From: Guillaume Abrioux Date: Fri, 27 Apr 2018 12:48:33 +0000 (+0200) Subject: check if pools already exist before creating them X-Git-Tag: v3.1.0beta9~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=75ed437d4e0a3b4a0a8705bc7b010212f189c162;p=ceph-ansible.git check if pools already exist before creating them Add a task to check if pools already exist before we create them. Signed-off-by: Guillaume Abrioux --- diff --git a/roles/ceph-client/tasks/create_users_keys.yml b/roles/ceph-client/tasks/create_users_keys.yml index 93f1e2006..20ee096e2 100644 --- a/roles/ceph-client/tasks/create_users_keys.yml +++ b/roles/ceph-client/tasks/create_users_keys.yml @@ -62,25 +62,41 @@ - keys | length > 0 - inventory_hostname in groups.get(client_group_name) | first +- name: list existing pool(s) + command: > + {{ docker_exec_client_cmd | default('') }} ceph --cluster {{ cluster }} + osd pool get {{ item.name }} size + with_items: "{{ pools }}" + register: created_pools + run_once: true + failed_when: false + delegate_to: "{{ groups.get(client_group_name)[0] }}" + when: + - copy_admin_key + - name: create ceph pool(s) command: > {{ docker_exec_client_cmd | default('') }} ceph --cluster {{ cluster }} - osd pool create {{ item.name }} - {{ item.get('pg_num', hostvars[groups[mon_group_name][0]]['osd_pool_default_pg_num']) }} - {{ item.pgp_num | default(item.pg_num) }} - {{ item.rule_name | default("replicated_rule") }} - {{ 1 if item.type|default(1) == 'replicated' else 3 if item.type|default(1) == 'erasure' else item.type|default(1) }} - {%- if (item.type | default("1") == '3' or item.type | default("1") == 'erasure') and item.erasure_profile != '' %} - {{ item.erasure_profile }} + osd pool create {{ item.0.name }} + {{ item.0.get('pg_num', hostvars[groups[mon_group_name][0]]['osd_pool_default_pg_num']) }} + {{ item.0.pgp_num | default(item.0.pg_num) }} + {{ 'replicated_rule' if item.0.rule_name | default('replicated_rule') == '' else item.0.rule_name | default('replicated_rule') }} + {{ 1 if item.0.type|default(1) == 'replicated' else 3 if item.0.type|default(1) == 'erasure' else item.0.type|default(1) }} + {%- if (item.0.type | default("1") == '3' or item.0.type | default("1") == 'erasure') and item.0.erasure_profile != '' %} + {{ item.0.erasure_profile }} {%- endif %} - {{ item.expected_num_objects | default('') }} - with_items: "{{ pools }}" + {{ item.0.expected_num_objects | default('') }} + with_together: + - "{{ pools }}" + - "{{ created_pools.results }}" changed_when: false run_once: true + delegate_to: "{{ groups.get(client_group_name)[0] }}" when: - pools | length > 0 - copy_admin_key - inventory_hostname in groups.get(client_group_name) | first + - item.1.rc != 0 - name: kill a dummy container that created pool(s)/key(s) command: docker rm -f ceph-create-keys diff --git a/roles/ceph-mon/tasks/openstack_config.yml b/roles/ceph-mon/tasks/openstack_config.yml index 93ad82fce..6bc3b189c 100644 --- a/roles/ceph-mon/tasks/openstack_config.yml +++ b/roles/ceph-mon/tasks/openstack_config.yml @@ -1,18 +1,30 @@ --- +- name: list existing pool(s) + command: > + {{ docker_exec_cmd | default('') }} ceph --cluster {{ cluster }} + osd pool get {{ item.name }} size + with_items: "{{ openstack_pools | unique }}" + register: created_pools + failed_when: false + - name: create openstack pool(s) command: > {{ docker_exec_cmd }} ceph --cluster {{ cluster }} - osd pool create {{ item.name }} - {{ item.pg_num }} - {{ item.pgp_num | default(item.pg_num) }} - {{ item.rule_name | default("replicated_rule") }} - {{ 1 if item.type|default(1) == 'replicated' else 3 if item.type|default(1) == 'erasure' else item.type|default(1) }} - {%- if (item.type | default("1") == '3' or item.type | default("1") == 'erasure') and item.erasure_profile != '' %} - {{ item.erasure_profile }} + osd pool create {{ item.0.name }} + {{ item.0.pg_num }} + {{ item.0.pgp_num | default(item.0.pg_num) }} + {{ 'replicated_rule' if item.0.rule_name | default('replicated_rule') == '' else item.0.rule_name | default('replicated_rule') }} + {{ 1 if item.0.type|default(1) == 'replicated' else 3 if item.0.type|default(1) == 'erasure' else item.0.type|default(1) }} + {%- if (item.0.type | default("1") == '3' or item.0.type | default("1") == 'erasure') and item.0.erasure_profile != '' %} + {{ item.0.erasure_profile }} {%- endif %} - {{ item.expected_num_objects | default('') }} - with_items: "{{ openstack_pools | unique }}" + {{ item.0.expected_num_objects | default('') }} + with_together: + - "{{ openstack_pools | unique }}" + - "{{ created_pools.results }}" changed_when: false + when: + - item.1.get('rc', 0) != 0 - name: assign rbd application to pool(s) command: "{{ docker_exec_cmd }} ceph --cluster {{ cluster }} osd pool application enable {{ item.name }} rbd"