Skip to content

Commit

Permalink
keyring: use ceph_key module for auth get command
Browse files Browse the repository at this point in the history
Instead of using ceph auth get command via the ansible command module
then we can use the ceph_key module and the info state.

Signed-off-by: Dimitri Savineau <dsavinea@redhat.com>
  • Loading branch information
dsavineau authored and guits committed Nov 2, 2020
1 parent 7d3d51d commit 59ecddc
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 41 deletions.
10 changes: 8 additions & 2 deletions infrastructure-playbooks/cephadm-adopt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,14 @@
ceph_cmd: "{{ container_binary + ' run --rm --net=host -v /etc/ceph:/etc/ceph:z -v /var/lib/ceph:/var/lib/ceph:z -v /var/run/ceph:/var/run/ceph:z --entrypoint=ceph ' + ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else 'ceph' }}"

- name: get the client.admin keyring
command: "{{ ceph_cmd }} --cluster {{ cluster }} auth get client.admin"
changed_when: false
ceph_key:
name: client.admin
cluster: "{{ cluster }}"
output_format: plain
state: info
environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
run_once: true
delegate_to: '{{ groups[mon_group_name][0] }}'
register: client_admin_keyring
Expand Down
27 changes: 14 additions & 13 deletions roles/ceph-client/tasks/pre_requisite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
- name: copy ceph admin keyring
block:
- name: get keys from monitors
command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} auth get {{ item.name }}"
register: _client_keys
with_items:
- { name: "client.admin", path: "/etc/ceph/{{ cluster }}.client.admin.keyring", copy_key: "{{ copy_admin_key }}" }
ceph_key:
name: client.admin
cluster: "{{ cluster }}"
output_format: plain
state: info
environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
register: _admin_key
delegate_to: "{{ groups.get(mon_group_name)[0] }}"
run_once: true
when:
- cephx | bool
- item.copy_key | bool

- name: copy ceph key(s) if needed
copy:
dest: "{{ item.item.path }}"
content: "{{ item.stdout + '\n' }}"
dest: "/etc/ceph/{{ cluster }}.client.admin.keyring"
content: "{{ _admin_key.stdout + '\n' }}"
owner: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
group: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
mode: "{{ ceph_keyring_permissions }}"
with_items: "{{ _client_keys.results }}"
when:
- item.item.copy_key | bool
when: cephx | bool
when:
- cephx | bool
- copy_admin_key | bool
11 changes: 8 additions & 3 deletions roles/ceph-crash/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
run_once: True

- name: get keys from monitors
command: "{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }} auth get client.crash"
ceph_key:
name: client.crash
cluster: "{{ cluster }}"
output_format: plain
state: info
environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
register: _crash_keys
delegate_to: "{{ groups.get(mon_group_name)[0] }}"
check_mode: False
changed_when: False
run_once: true

- name: copy ceph key(s) if needed
Expand Down
22 changes: 13 additions & 9 deletions roles/ceph-iscsi-gw/tasks/common.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
---
- name: get keys from monitors
command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} auth get {{ item.name }}"
register: _iscsi_keys
with_items:
- { name: "client.admin", path: "/etc/ceph/{{ cluster }}.client.admin.keyring", copy_key: "{{ copy_admin_key }}" }
ceph_key:
name: client.admin
cluster: "{{ cluster }}"
output_format: plain
state: info
environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
register: _admin_key
delegate_to: "{{ groups.get(mon_group_name)[0] }}"
run_once: true
when:
- cephx | bool
- item.copy_key | bool
- copy_admin_key | bool

- name: copy ceph key(s) if needed
copy:
dest: "{{ item.item.path }}"
content: "{{ item.stdout + '\n' }}"
dest: "/etc/ceph/{{ cluster }}.client.admin.keyring"
content: "{{ _admin_key.stdout + '\n' }}"
owner: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
group: "{{ ceph_uid if containerized_deployment | bool else 'ceph' }}"
mode: "{{ ceph_keyring_permissions }}"
with_items: "{{ _iscsi_keys.results }}"
when:
- cephx | bool
- item.item.copy_key | bool
- copy_admin_key | bool

- name: add mgr ip address to trusted list with dashboard - ipv4
set_fact:
Expand Down
9 changes: 8 additions & 1 deletion roles/ceph-mds/tasks/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
- /var/lib/ceph/mds/{{ cluster }}-{{ ansible_hostname }}

- name: get keys from monitors
command: "{{ container_exec_cmd | default('') }} ceph --cluster {{ cluster }} auth get {{ item.name }}"
ceph_key:
name: "{{ item.name }}"
cluster: "{{ cluster }}"
output_format: plain
state: info
environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
register: _mds_keys
with_items:
- { name: "client.bootstrap-mds", path: "/var/lib/ceph/bootstrap-mds/{{ cluster }}.keyring", copy_key: true }
Expand Down
9 changes: 8 additions & 1 deletion roles/ceph-mgr/tasks/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@
- { 'name': "mgr.{{ ansible_hostname }}", 'path': "/var/lib/ceph/mgr/{{ cluster }}-{{ ansible_hostname }}/keyring", 'copy_key': true }

- name: get keys from monitors
command: "{{ _container_exec_cmd | default('') }} ceph --cluster {{ cluster }} auth get {{ item.name }}"
ceph_key:
name: "{{ item.name }}"
cluster: "{{ cluster }}"
output_format: plain
state: info
environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
register: _mgr_keys
with_items: "{{ _mgr_keys }}"
delegate_to: "{{ groups[mon_group_name][0] if running_mon is undefined else running_mon }}"
Expand Down
16 changes: 11 additions & 5 deletions roles/ceph-mon/tasks/deploy_monitors.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
---
- name: check if monitor initial keyring already exists
command: >
{{ _container_exec_cmd | default('') }} ceph --cluster {{ cluster }} --name mon. -k
/var/lib/ceph/mon/{{ cluster }}-{{ hostvars[groups[mon_group_name][0] if running_mon is undefined else running_mon]['ansible_hostname'] }}/keyring
auth get-key mon.
ceph_key:
name: mon.
cluster: "{{ cluster }}"
user: mon.
user_key: "/var/lib/ceph/mon/{{ cluster }}-{{ hostvars[groups[mon_group_name][0] if running_mon is undefined else running_mon]['ansible_hostname'] }}/keyring"
output_format: json
state: info
environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
register: initial_mon_key
run_once: True
delegate_to: "{{ groups[mon_group_name][0] if running_mon is undefined else running_mon }}"
Expand All @@ -24,7 +30,7 @@

- name: get initial keyring when it already exists
set_fact:
monitor_keyring: "{{ initial_mon_key.stdout if monitor_keyring.skipped is defined else monitor_keyring.stdout if initial_mon_key.skipped is defined }}"
monitor_keyring: "{{ (initial_mon_key.stdout | from_json)[0].key if monitor_keyring.skipped is defined else monitor_keyring.stdout if initial_mon_key.skipped is defined }}"
when: initial_mon_key is not skipped or monitor_keyring is not skipped

- name: create monitor initial keyring
Expand Down
9 changes: 8 additions & 1 deletion roles/ceph-nfs/tasks/pre_requisite_container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
run_once: true

- name: get keys from monitors
command: "{{ hostvars[groups.get(mon_group_name)[0]]['container_exec_cmd'] }} ceph --cluster {{ cluster }} auth get {{ item.name }}"
ceph_key:
name: "{{ item.name }}"
cluster: "{{ cluster }}"
output_format: plain
state: info
environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
register: _rgw_keys
with_items:
- { name: "client.bootstrap-rgw", path: "/var/lib/ceph/bootstrap-rgw/{{ cluster }}.keyring", copy_key: true }
Expand Down
6 changes: 5 additions & 1 deletion roles/ceph-nfs/tasks/pre_requisite_non_container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
- groups.get(mon_group_name, []) | length > 0
block:
- name: get keys from monitors
command: "ceph --cluster {{ cluster }} auth get {{ item.name }}"
ceph_key:
name: "{{ item.name }}"
cluster: "{{ cluster }}"
output_format: plain
state: info
register: _rgw_keys
with_items:
- { name: "client.bootstrap-rgw", path: "/var/lib/ceph/bootstrap-rgw/{{ cluster }}.keyring", copy_key: "{{ nfs_obj_gw }}" }
Expand Down
9 changes: 8 additions & 1 deletion roles/ceph-osd/tasks/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
- /var/lib/ceph/osd/

- name: get keys from monitors
command: "{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }} auth get {{ item.name }}"
ceph_key:
name: "{{ item.name }}"
cluster: "{{ cluster }}"
output_format: plain
state: info
environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
register: _osd_keys
with_items:
- { name: "client.bootstrap-osd", path: "/var/lib/ceph/bootstrap-osd/{{ cluster }}.keyring", copy_key: true }
Expand Down
10 changes: 8 additions & 2 deletions roles/ceph-osd/tasks/openstack_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@
delegate_to: "{{ groups[mon_group_name][0] }}"

- name: get keys from monitors
command: "{{ hostvars[groups[mon_group_name][0]]['container_exec_cmd'] | default('') }} ceph --cluster {{ cluster }} auth get {{ item.name }}"
ceph_key:
name: "{{ item.name }}"
cluster: "{{ cluster }}"
output_format: plain
state: info
environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
register: _osp_keys
with_items: "{{ openstack_keys }}"
run_once: true
delegate_to: "{{ groups.get(mon_group_name)[0] }}"

- name: copy ceph key(s) if needed
Expand Down
9 changes: 8 additions & 1 deletion roles/ceph-rbd-mirror/tasks/common.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
---
- name: get keys from monitors
command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} auth get {{ item.name }}"
ceph_key:
name: "{{ item.name }}"
cluster: "{{ cluster }}"
output_format: plain
state: info
environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
register: _rbd_mirror_keys
with_items:
- { name: "client.bootstrap-rbd-mirror", path: "/var/lib/ceph/bootstrap-rbd-mirror/{{ cluster }}.keyring", copy_key: true }
Expand Down
9 changes: 8 additions & 1 deletion roles/ceph-rgw/tasks/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
with_items: "{{ rbd_client_admin_socket_path }}"

- name: get keys from monitors
command: "{{ container_exec_cmd }} ceph --cluster {{ cluster }} auth get {{ item.name }}"
ceph_key:
name: "{{ item.name }}"
cluster: "{{ cluster }}"
output_format: plain
state: info
environment:
CEPH_CONTAINER_IMAGE: "{{ ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else None }}"
CEPH_CONTAINER_BINARY: "{{ container_binary }}"
register: _rgw_keys
with_items:
- { name: "client.bootstrap-rgw", path: "/var/lib/ceph/bootstrap-rgw/{{ cluster }}.keyring", copy_key: true }
Expand Down

0 comments on commit 59ecddc

Please sign in to comment.