common: introduce ceph_pool module calls

This commits calls the `ceph_pool` module for creating ceph pools
everywhere it's needed in the playbook.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
pull/5387/head
Guillaume Abrioux 2020-04-28 18:08:59 +02:00
parent bddcb439ce
commit af9f6684f2
4 changed files with 64 additions and 232 deletions

View File

@ -73,83 +73,27 @@
name: ceph-facts name: ceph-facts
tasks_from: get_def_crush_rule_name.yml tasks_from: get_def_crush_rule_name.yml
- name: list existing pool(s)
command: >
{{ ceph_admin_command }} --cluster {{ cluster }}
osd pool get {{ item.name }} size
with_items: "{{ pools }}"
register: created_pools
failed_when: false
delegate_to: "{{ delegated_node }}"
- name: create ceph pool(s) - name: create ceph pool(s)
command: > ceph_pool:
{{ ceph_admin_command | default('') }} --cluster {{ cluster }} name: "{{ item.name }}"
osd pool create {{ item.0.name }} state: present
{{ item.0.pg_num | default(osd_pool_default_pg_num) if not item.0.pg_autoscale_mode | default(False) | bool else 16 }} cluster: "{{ cluster }}"
{{ item.0.pgp_num | default(item.0.pg_num) | default(osd_pool_default_pg_num) if not item.0.pg_autoscale_mode | default(False) | bool else '' }} pg_num: "{{ item.pg_num | default(osd_pool_default_pg_num) if not item.0.pg_autoscale_mode | default(False) | bool else 16 }}"
{%- if item.0.type | default(1) | int == 1 or item.0.type | default('replicated') == 'replicated' %} pgp_num: "{{ item.pgp_num | default(item.pg_num) | default(osd_pool_default_pg_num) if not item.pg_autoscale_mode | default(False) | bool else omit }}"
replicated size: "{{ item.size | default(omit) }}"
{{ item.0.rule_name | default(ceph_osd_pool_default_crush_rule_name) }} min_size: "{{ item.min_size | default(omit) }}"
{{ item.0.expected_num_objects | default(0) }} pool_type: "{{ item.type | default('replicated') }}"
{%- else %} rule_name: "{{ item.rule_name | default(omit) }}"
erasure erasure_profile: "{{ item.erasure_profile | default(omit) }}"
{{ item.0.erasure_profile }} pg_autoscale_mode: "{{ item.pg_autoscale_mode | default(omit) }}"
{%- endif %} target_size_ratio: "{{ item.target_size_ratio | default(omit) }}"
with_together: application: "{{ item.application | default(omit) }}"
- "{{ pools }}" environment:
- "{{ created_pools.results }}" CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
with_items: "{{ pools }}"
changed_when: false changed_when: false
delegate_to: "{{ delegated_node }}" delegate_to: "{{ delegated_node }}"
when:
- pools | length > 0
- item.1.rc != 0
- name: set the target ratio on pool(s)
command: "{{ ceph_admin_command | default('') }} --cluster {{ cluster }} osd pool set {{ item.name }} target_size_ratio {{ item.target_size_ratio }}"
with_items: "{{ pools | unique }}"
delegate_to: "{{ delegated_node }}"
when:
- item.pg_autoscale_mode | default(False) | bool
- item.target_size_ratio is defined
- name: set pg_autoscale_mode value on pool(s)
command: "{{ ceph_admin_command | default('') }} --cluster {{ cluster }} osd pool set {{ item.name }} pg_autoscale_mode {{ item.pg_autoscale_mode | default(False) | ternary('on', 'warn') }}"
delegate_to: "{{ delegated_node }}"
with_items: "{{ pools | unique }}"
- name: customize pool size
command: >
{{ ceph_admin_command | default('') }} --cluster {{ cluster }}
osd pool set {{ item.name }} size {{ item.size | default(osd_pool_default_size) }} {{ '--yes-i-really-mean-it' if item.size | default(osd_pool_default_size) | int == 1 else '' }}
with_items: "{{ pools | unique }}"
delegate_to: "{{ delegated_node }}"
changed_when: false
when:
- pools | length > 0
- item.type | default(1) | int != 3
- item.type | default('replicated') != 'erasure'
- item.size | default(osd_pool_default_size) != ceph_osd_pool_default_size
- name: customize pool min_size
command: >
{{ ceph_admin_command | default('') }} --cluster {{ cluster }}
osd pool set {{ item.name }} min_size {{ item.min_size | default(osd_pool_default_min_size) }}
with_items: "{{ pools | unique }}"
delegate_to: "{{ delegated_node }}"
changed_when: false
when:
- pools | length > 0
- (item.min_size | default(osd_pool_default_min_size))|int > ceph_osd_pool_default_min_size
- item.type | default(1) | int != 3
- item.type | default('replicated') != 'erasure'
- name: assign application to pool(s)
command: "{{ ceph_admin_command | default('') }} --cluster {{ cluster }} osd pool application enable {{ item.name }} {{ item.application }}"
with_items: "{{ pools | unique }}"
changed_when: false
delegate_to: "{{ delegated_node }}"
when: item.application is defined
- name: get client cephx keys - name: get client cephx keys
copy: copy:

View File

@ -52,27 +52,14 @@
delegate_to: "{{ groups[mon_group_name][0] }}" delegate_to: "{{ groups[mon_group_name][0] }}"
when: containerized_deployment | bool when: containerized_deployment | bool
- name: check if a rbd pool exists - name: create iscsi pool
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} osd pool ls --format json" ceph_pool:
changed_when: false name: "{{ iscsi_pool_name }}"
register: iscsi_pool_exists state: present
delegate_to: "{{ groups[mon_group_name][0] }}" cluster: "{{ cluster }}"
pg_num: "{{ osd_pool_default_pg_num }}"
- name: iscsi pool related tasks size: "{{ iscsi_pool_size | default(osd_pool_default_size) }}"
when: "iscsi_pool_name not in (iscsi_pool_exists.stdout | from_json)" application: "rbd"
block: environment:
- name: create a iscsi pool if it doesn't exist CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment else None }}"
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} osd pool create {{ iscsi_pool_name }} {{ osd_pool_default_pg_num }}" CEPH_CONTAINER_BINARY: "{{ container_binary }}"
changed_when: false
delegate_to: "{{ groups[mon_group_name][0] }}"
- name: assign application rbd to iscsi pool
command: "{{ container_exec_cmd }} ceph --connect-timeout 5 --cluster {{ cluster }} osd pool application enable {{ iscsi_pool_name }} rbd"
delegate_to: "{{ groups[mon_group_name][0] }}"
run_once: True
- name: customize pool size
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} osd pool set {{ iscsi_pool_name }} size {{ iscsi_pool_size | default(osd_pool_default_size) }} {{ '--yes-i-really-mean-it' if iscsi_pool_size | default(osd_pool_default_size) | int == 1 else '' }}"
delegate_to: "{{ groups[mon_group_name][0] }}"
changed_when: false
when: iscsi_pool_size | default(osd_pool_default_size) != ceph_osd_pool_default_size

View File

@ -2,22 +2,6 @@
- name: check and deploy filesystem pools - name: check and deploy filesystem pools
delegate_to: "{{ groups[mon_group_name][0] }}" delegate_to: "{{ groups[mon_group_name][0] }}"
block: block:
- name: check if filesystem pool already exists
block:
- name: compile a list of pool names
set_fact:
cephfs_pool_names: "{{ cephfs_pools | map(attribute='name') | list }}"
- name: get and store list of filesystem pools
command: "{{ ceph_run_cmd }} --cluster {{ cluster }} osd pool ls"
changed_when: false
register: osd_pool_ls
- name: look whether pools to be created are present in the output
set_fact:
fs_pools_created: True
when: osd_pool_ls.stdout_lines | intersect(cephfs_pool_names) | length > 0
- name: deploy filesystem pools - name: deploy filesystem pools
when: fs_pools_created is not defined when: fs_pools_created is not defined
block: block:
@ -26,52 +10,23 @@
tasks_from: get_def_crush_rule_name.yml tasks_from: get_def_crush_rule_name.yml
- name: create filesystem pools - name: create filesystem pools
command: > ceph_pool:
{{ ceph_run_cmd }} --cluster {{ cluster }} name: "{{ item.name }}"
osd pool create {{ item.name }} state: present
{{ item.pg_num | default(osd_pool_default_pg_num) if not item.pg_autoscale_mode | default(False) | bool else 16 }} cluster: "{{ cluster }}"
{{ item.pgp_num | default(item.pg_num) | default(osd_pool_default_pg_num) if not item.pg_autoscale_mode | default(False) | bool else '' }} pg_num: "{{ item.pg_num | default(osd_pool_default_pg_num) if not item.0.pg_autoscale_mode | default(False) | bool else 16 }}"
{%- if item.type | default(1) | int == 1 or item.type | default('replicated') == 'replicated' %} pgp_num: "{{ item.pgp_num | default(item.pg_num) | default(osd_pool_default_pg_num) if not item.pg_autoscale_mode | default(False) | bool else omit }}"
replicated size: "{{ item.size | default(omit) }}"
{{ item.rule_name | default(ceph_osd_pool_default_crush_rule_name) }} min_size: "{{ item.min_size | default(omit) }}"
{{ item.expected_num_objects | default(0) }} pool_type: "{{ item.type | default('replicated') }}"
{%- else %} rule_name: "{{ item.rule_name | default(omit) }}"
erasure erasure_profile: "{{ item.erasure_profile | default(omit) }}"
{{ item.erasure_profile }} pg_autoscale_mode: "{{ item.pg_autoscale_mode | default(omit) }}"
{%- endif %} target_size_ratio: "{{ item.target_size_ratio | default(omit) }}"
changed_when: false with_items: "{{ cephfs_pools }}"
with_items: environment:
- "{{ cephfs_pools }}" CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
- name: set the target ratio on pool(s)
command: "{{ ceph_run_cmd }} --cluster {{ cluster }} osd pool set {{ item.name }} target_size_ratio {{ item.target_size_ratio }}"
with_items: "{{ cephfs_pools | unique }}"
when:
- item.pg_autoscale_mode | default(False) | bool
- item.target_size_ratio is defined
- name: set pg_autoscale_mode value on pool(s)
command: "{{ ceph_run_cmd }} --cluster {{ cluster }} osd pool set {{ item.name }} pg_autoscale_mode {{ item.pg_autoscale_mode | default(False) | ternary('on', 'warn') }}"
with_items: "{{ cephfs_pools | unique }}"
- name: customize pool size
command: "{{ ceph_run_cmd }} --cluster {{ cluster }} osd pool set {{ item.name }} size {{ item.size | default(osd_pool_default_size) }} {{ '--yes-i-really-mean-it' if item.size | default(osd_pool_default_size) | int == 1 else '' }}"
with_items: "{{ cephfs_pools | unique }}"
changed_when: false
when:
- item.size | default(osd_pool_default_size) != ceph_osd_pool_default_size
- item.type | default(1) | int != 3
- item.type | default('replicated') != 'erasure'
- name: customize pool min_size
command: "{{ ceph_run_cmd }} --cluster {{ cluster }} osd pool set {{ item.name }} min_size {{ item.min_size | default(osd_pool_default_min_size) }}"
with_items: "{{ cephfs_pools | unique }}"
changed_when: false
when:
- (item.min_size | default(osd_pool_default_min_size))|int > ceph_osd_pool_default_min_size
- item.type | default(1) | int != 3
- item.type | default('replicated') != 'erasure'
- name: check and create ceph filesystem - name: check and create ceph filesystem
delegate_to: "{{ groups[mon_group_name][0] }}" delegate_to: "{{ groups[mon_group_name][0] }}"

View File

@ -1,80 +1,26 @@
--- ---
- name: pool related tasks - name: pool related tasks
block: block:
- name: list existing pool(s)
command: >
{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }}
osd pool get {{ item.name }} size
with_items: "{{ openstack_pools | unique }}"
register: created_pools
delegate_to: "{{ groups[mon_group_name][0] }}"
failed_when: created_pools.rc in [1, 125]
changed_when: false
- name: create openstack pool(s) - name: create openstack pool(s)
command: > ceph_pool:
{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }} name: "{{ item.name }}"
osd pool create {{ item.0.name }} state: present
{{ item.0.pg_num | default(osd_pool_default_pg_num) if not item.0.pg_autoscale_mode | default(False) | bool else 16 }} cluster: "{{ cluster }}"
{{ item.0.pgp_num | default(item.0.pg_num) | default(osd_pool_default_pg_num) if not item.0.pg_autoscale_mode | default(False) | bool else '' }} pg_num: "{{ item.pg_num | default(osd_pool_default_pg_num) if not item.0.pg_autoscale_mode | default(False) | bool else 16 }}"
{%- if item.0.type | default(1) | int == 1 or item.0.type | default('replicated') == 'replicated' %} pgp_num: "{{ item.pgp_num | default(item.pg_num) | default(osd_pool_default_pg_num) if not item.pg_autoscale_mode | default(False) | bool else omit }}"
replicated size: "{{ item.size | default(omit) }}"
{{ item.0.rule_name | default(ceph_osd_pool_default_crush_rule_name) }} min_size: "{{ item.min_size | default(omit) }}"
{{ item.0.expected_num_objects | default(0) }} pool_type: "{{ item.type | default('replicated') }}"
{%- else %} rule_name: "{{ item.rule_name | default(omit) }}"
erasure erasure_profile: "{{ item.erasure_profile | default(omit) }}"
{{ item.0.erasure_profile }} pg_autoscale_mode: "{{ item.pg_autoscale_mode | default(omit) }}"
{%- endif %} target_size_ratio: "{{ item.target_size_ratio | default(omit) }}"
with_together: application: "{{ item.application | default(omit) }}"
- "{{ openstack_pools | unique }}" with_items: "{{ openstack_pools }}"
- "{{ created_pools.results }}"
changed_when: false
delegate_to: "{{ groups[mon_group_name][0] }}" delegate_to: "{{ groups[mon_group_name][0] }}"
when: item.1.get('rc', 0) != 0 environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment else None }}"
- name: set the target ratio on pool(s) CEPH_CONTAINER_BINARY: "{{ container_binary }}"
command: "{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }} osd pool set {{ item.name }} target_size_ratio {{ item.target_size_ratio }}"
with_items: "{{ openstack_pools | unique }}"
delegate_to: "{{ groups[mon_group_name][0] }}"
when:
- item.pg_autoscale_mode | default(False) | bool
- item.target_size_ratio is defined
- name: set pg_autoscale_mode value on pool(s)
command: "{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }} osd pool set {{ item.name }} pg_autoscale_mode {{ item.pg_autoscale_mode | default(False) | ternary('on', 'warn') }}"
delegate_to: "{{ groups[mon_group_name][0] }}"
with_items: "{{ openstack_pools | unique }}"
- name: customize pool size
command: >
{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }}
osd pool set {{ item.name }} size {{ item.size | default(osd_pool_default_size) }} {{ '--yes-i-really-mean-it' if item.size | default(osd_pool_default_size) | int == 1 else '' }}
with_items: "{{ openstack_pools | unique }}"
delegate_to: "{{ groups[mon_group_name][0] }}"
changed_when: false
when:
- item.size | default(osd_pool_default_size)
- item.type | default(1) | int != 3
- item.type | default('replicated') != 'erasure'
- name: customize pool min_size
command: >
{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }}
osd pool set {{ item.name }} min_size {{ item.min_size | default(osd_pool_default_min_size) }}
with_items: "{{ openstack_pools | unique }}"
delegate_to: "{{ groups[mon_group_name][0] }}"
changed_when: false
when:
- (item.min_size | default(osd_pool_default_min_size))|int > ceph_osd_pool_default_min_size
- item.type | default(1) | int != 3
- item.type | default('replicated') != 'erasure'
- name: assign application to pool(s)
command: "{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }} osd pool application enable {{ item.name }} {{ item.application }}"
with_items: "{{ openstack_pools | unique }}"
changed_when: false
delegate_to: "{{ groups[mon_group_name][0] }}"
when: item.application is defined
- name: create openstack cephx key(s) - name: create openstack cephx key(s)
block: block: