clients: refact `ceph-clients` role

This commit refacts this role so we don't have to pull container image
on client nodes just to create pools and keys.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1550977

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
pull/2494/head
Guillaume Abrioux 2018-03-30 13:48:17 +02:00 committed by Sébastien Han
parent cefd471967
commit 9c979c6390
1 changed files with 30 additions and 0 deletions

View File

@ -20,9 +20,11 @@
creates: /etc/ceph/{{ cluster }}.{{ item.name }}.keyring creates: /etc/ceph/{{ cluster }}.{{ item.name }}.keyring
with_items: "{{ keys }}" with_items: "{{ keys }}"
changed_when: false changed_when: false
run_once: true
when: when:
- cephx - cephx
- keys | length > 0 - keys | length > 0
- inventory_hostname in groups.get(client_group_name) | first
- name: set docker_exec_client_cmd_binary to ceph - name: set docker_exec_client_cmd_binary to ceph
set_fact: set_fact:
@ -36,14 +38,28 @@
- not containerized_deployment - not containerized_deployment
- docker_exec_client_cmd == 'ceph-authtool' - docker_exec_client_cmd == 'ceph-authtool'
- name: slurp client key(s)
slurp:
src: "{{ ceph_conf_key_directory }}/{{ cluster }}.{{ item.name }}.keyring"
with_items:
- "{{ keys }}"
register: slurp_client_keys
run_once: true
when:
- cephx
- keys | length > 0
- inventory_hostname in groups.get(client_group_name) | first
- name: check if key(s) already exist(s) - name: check if key(s) already exist(s)
command: "{{ docker_exec_client_cmd }} --cluster {{ cluster }} auth get {{ item.name }}" command: "{{ docker_exec_client_cmd }} --cluster {{ cluster }} auth get {{ item.name }}"
changed_when: false changed_when: false
failed_when: false failed_when: false
with_items: "{{ keys }}" with_items: "{{ keys }}"
register: keys_exist register: keys_exist
run_once: true
when: when:
- copy_admin_key - copy_admin_key
- inventory_hostname in groups.get(client_group_name) | first
- name: create pool(s) - name: create pool(s)
command: > command: >
@ -59,13 +75,16 @@
{{ item.expected_num_objects | default('') }} {{ item.expected_num_objects | default('') }}
with_items: "{{ pools }}" with_items: "{{ pools }}"
changed_when: false changed_when: false
run_once: true
when: when:
- pools | length > 0 - pools | length > 0
- copy_admin_key - copy_admin_key
- inventory_hostname in groups.get(client_group_name) | first
- name: add key(s) to ceph - name: add key(s) to ceph
command: "{{ docker_exec_client_cmd }} --cluster {{ cluster }} auth import -i /etc/ceph/{{ cluster }}.{{ item.0.name }}.keyring" command: "{{ docker_exec_client_cmd }} --cluster {{ cluster }} auth import -i /etc/ceph/{{ cluster }}.{{ item.0.name }}.keyring"
changed_when: false changed_when: false
run_once: true
with_together: with_together:
- "{{ keys }}" - "{{ keys }}"
- "{{ keys_exist.results | default([]) }}" - "{{ keys_exist.results | default([]) }}"
@ -73,12 +92,23 @@
- not item.1.get("skipped") - not item.1.get("skipped")
- copy_admin_key - copy_admin_key
- item.1.rc != 0 - item.1.rc != 0
- inventory_hostname in groups.get(client_group_name) | first
- name: put docker_exec_client_cmd back to normal with a none value - name: put docker_exec_client_cmd back to normal with a none value
set_fact: set_fact:
docker_exec_client_cmd: docker_exec_client_cmd:
when: docker_exec_client_cmd == 'ceph' when: docker_exec_client_cmd == 'ceph'
- name: get client keys
copy:
dest: "{{ item.source }}"
content: "{{ item.content | b64decode }}"
with_items:
- "{{ slurp_client_keys.results }}"
when:
- not item.get('skipped', False)
- not inventory_hostname == groups.get(client_group_name, []) | first
- name: chmod key(s) - name: chmod key(s)
file: file:
path: "/etc/ceph/{{ cluster }}.{{ item.name }}.keyring" path: "/etc/ceph/{{ cluster }}.{{ item.name }}.keyring"