]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
check if pools already exist before creating them
authorGuillaume Abrioux <gabrioux@redhat.com>
Fri, 27 Apr 2018 12:48:33 +0000 (14:48 +0200)
committerGuillaume Abrioux <gabrioux@redhat.com>
Mon, 30 Apr 2018 06:15:18 +0000 (08:15 +0200)
Add a task to check if pools already exist before we create them.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
roles/ceph-client/tasks/create_users_keys.yml
roles/ceph-mon/tasks/openstack_config.yml

index 93f1e20069fbe4e08aacb75ebd825a846406394f..20ee096e2669e5ab8a5a0e8345154f9a4b94d035 100644 (file)
     - 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
index 93ad82fce509ea79380870938b0859c7af931bad..6bc3b189c827603e6a9ef110b41b3741ebd14ede 100644 (file)
@@ -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"