]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
client: fix pool creation
authorGuillaume Abrioux <gabrioux@redhat.com>
Mon, 30 Apr 2018 18:53:42 +0000 (20:53 +0200)
committerSébastien Han <seb@redhat.com>
Thu, 3 May 2018 06:22:40 +0000 (08:22 +0200)
the value in `docker_exec_client_cmd` doesn't allow to check for
existing pools because it's set with a wrong value for the entrypoint
that is going to be used.
It means the check were going to fail anyway even if pools actually exist.

Using jinja syntax to set `docker_exec_cmd` allows to handle the case
where you don't have monitors in your inventory.

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

index 20ee096e2669e5ab8a5a0e8345154f9a4b94d035..d8ab3fd875bc11576f3c74b895ccb666a58613c2 100644 (file)
   run_once: true
   when: containerized_deployment
 
+- name: set_fact delegated_node
+  set_fact:
+    delegated_node: "{{ groups[mon_group_name][0] if groups.get(mon_group_name, []) | length > 0 else inventory_hostname }}"
+
+- name: set_fact condition_copy_admin_key
+  set_fact:
+    condition_copy_admin_key: "{{ True if groups.get(mon_group_name, []) | length > 0 else copy_admin_key }}"
+
+- name: set_fact docker_exec_cmd
+  set_fact:
+    docker_exec_cmd: "docker exec {% if groups.get(mon_group_name, []) | length > 0 -%} ceph-mon-{{ hostvars[delegated_node]['ansible_hostname'] }} {% else %} ceph-client-{{ hostvars[delegated_node]['ansible_hostname'] }} {% endif %}"
+  when:
+    - containerized_deployment
+
 - name: create cephx key(s)
   ceph_key:
     state: present
 
 - name: list existing pool(s)
   command: >
-    {{ docker_exec_client_cmd | default('') }} ceph --cluster {{ cluster }}
+    {{ docker_exec_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] }}"
+  delegate_to: "{{ delegated_node }}"
   when:
-    - copy_admin_key
+    - condition_copy_admin_key
 
 - name: create ceph pool(s)
   command: >
-    {{ docker_exec_client_cmd | default('') }} ceph --cluster {{ cluster }}
+    {{ docker_exec_cmd | default('') }} ceph --cluster {{ cluster }}
     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) }}
     - "{{ created_pools.results }}"
   changed_when: false
   run_once: true
-  delegate_to: "{{ groups.get(client_group_name)[0] }}"
+  delegate_to: "{{ delegated_node }}"
   when:
     - pools | length > 0
-    - copy_admin_key
+    - condition_copy_admin_key
     - inventory_hostname in groups.get(client_group_name) | first
     - item.1.rc != 0