ceph-ansible/roles/ceph-mon/tasks/ceph_keys.yml

137 lines
4.0 KiB
YAML

---
- name: collect admin and bootstrap keys
command: ceph-create-keys --cluster {{ cluster }} -i {{ monitor_name }} -t 30
changed_when: false
check_mode: no
when:
- cephx
- ceph_release_num[ceph_release] >= ceph_release_num.luminous
- name: collect admin and bootstrap keys
command: ceph-create-keys --cluster {{ cluster }} -i {{ monitor_name }}
changed_when: false
check_mode: no
when:
- cephx
- ceph_release_num[ceph_release] < ceph_release_num.luminous
# NOTE (leseb): wait for mon discovery and quorum resolution
# the admin key is not instantaneously created so we have to wait a bit
# msg: is only supported as of Ansible 2.4.
- name: "wait for {{ cluster }}.client.admin.keyring exists"
wait_for:
path: /etc/ceph/{{ cluster }}.client.admin.keyring
timeout: 30
msg: "Timed out while waiting for keyring creation. Check network settings on mon nodes."
when:
- cephx
- (ansible_version.major == 2 and ansible_version.minor >= 4) or
ansible_version.major > 2
- name: "wait for {{ cluster }}.client.admin.keyring exists"
wait_for:
path: /etc/ceph/{{ cluster }}.client.admin.keyring
timeout: 30
when:
- cephx
- ansible_version.major == 2 and ansible_version.minor < 4
- name: test if initial mon keyring is in mon kv store
command: ceph --cluster {{ cluster }} config-key get initial_mon_keyring
changed_when: false
ignore_errors: true
check_mode: no
run_once: true
failed_when: false
register: is_initial_mon_keyring_in_kv
- name: put initial mon keyring in mon kv store
command: ceph --cluster {{ cluster }} config-key put initial_mon_keyring {{ monitor_keyring.stdout }}
changed_when: false
check_mode: no
run_once: true
when:
- is_initial_mon_keyring_in_kv.rc != 0
- cephx
- name: create ceph rest api keyring when mon is not containerized
ceph_key:
name: client.restapi
state: present
caps:
mon: allow *
osd: allow *
cluster: "{{ cluster }}"
when:
- cephx
- groups.get(restapi_group_name, []) | length > 0
- inventory_hostname == groups[mon_group_name]|last
- name: create ceph mgr keyring(s) when mon is not containerized
ceph_key:
name: "mgr.{{ hostvars[item]['ansible_hostname'] }}"
state: present
caps:
mon: allow profile mgr
osd: allow *
mds: allow *
cluster: "{{ cluster }}"
when:
- cephx
- groups.get(mgr_group_name, []) | length > 0
- inventory_hostname == groups[mon_group_name]|last
- ceph_release_num[ceph_release] > ceph_release_num.jewel
with_items: "{{ groups.get(mgr_group_name, []) }}"
# once this gets backported github.com/ceph/ceph/pull/20983
# we will be able to remove these 2 tasks below
- name: find ceph keys
shell: ls -1 /etc/ceph/*.keyring
changed_when: false
register: ceph_keys
check_mode: no
when:
- cephx
- name: set keys permissions
file:
path: "{{ item }}"
owner: "ceph"
group: "ceph"
mode: "{{ ceph_keyring_permissions }}"
with_items:
- "{{ ceph_keys.get('stdout_lines') | default([]) }}"
when:
- cephx
- name: set_fact bootstrap_rbd_keyring
set_fact:
bootstrap_rbd_keyring: "/var/lib/ceph/bootstrap-rbd/{{ cluster }}.keyring"
when:
- ceph_release_num[ceph_release] >= ceph_release_num.luminous
- name: copy keys to the ansible server
fetch:
src: "{{ item }}"
dest: "{{ fetch_directory }}/{{ fsid }}/{{ item }}"
flat: yes
with_items:
- "{{ ceph_keys.get('stdout_lines') | default([]) }}"
- /var/lib/ceph/bootstrap-osd/{{ cluster }}.keyring
- /var/lib/ceph/bootstrap-rgw/{{ cluster }}.keyring
- /var/lib/ceph/bootstrap-mds/{{ cluster }}.keyring
- "{{ bootstrap_rbd_keyring | default([]) }}"
when:
- cephx
- inventory_hostname == groups[mon_group_name] | last
- name: drop in a motd script to report status when logging in
copy:
src: precise/92-ceph
dest: /etc/update-motd.d/92-ceph
owner: root
group: root
mode: 0755
when:
- ansible_distribution_release == 'precise'