From 6fe8df627b8e4b89227e90937c847b49587d6ab6 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Mon, 30 Apr 2018 20:53:42 +0200 Subject: [PATCH] client: fix pool creation 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 --- roles/ceph-client/tasks/create_users_keys.yml | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/roles/ceph-client/tasks/create_users_keys.yml b/roles/ceph-client/tasks/create_users_keys.yml index 20ee096e2..d8ab3fd87 100644 --- a/roles/ceph-client/tasks/create_users_keys.yml +++ b/roles/ceph-client/tasks/create_users_keys.yml @@ -32,6 +32,20 @@ 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 @@ -64,19 +78,19 @@ - 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) }} @@ -91,10 +105,10 @@ - "{{ 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 -- 2.39.5