--- - name: Check if it is atomic host ansible.builtin.stat: path: /run/ostree-booted register: stat_ostree - name: Set_fact is_atomic ansible.builtin.set_fact: is_atomic: "{{ stat_ostree.stat.exists }}" - name: Import_tasks container_binary.yml ansible.builtin.import_tasks: container_binary.yml - name: Set_fact ceph_cmd ansible.builtin.set_fact: 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' }}" # In case ansible_python_interpreter is set by the user, # ansible will not discover python and discovered_interpreter_python # will not be set - name: Set_fact discovered_interpreter_python ansible.builtin.set_fact: discovered_interpreter_python: "{{ ansible_python_interpreter }}" when: ansible_python_interpreter is defined # If ansible_python_interpreter is not defined, this can result in the # discovered_interpreter_python fact from being set. This fails later in this # playbook and is used elsewhere. - name: Set_fact discovered_interpreter_python if not previously set ansible.builtin.set_fact: discovered_interpreter_python: "{{ ansible_facts['discovered_interpreter_python'] }}" when: - discovered_interpreter_python is not defined - ansible_facts['discovered_interpreter_python'] is defined # Set ceph_release to ceph_stable by default - name: Set_fact ceph_release ceph_stable_release ansible.builtin.set_fact: ceph_release: "{{ ceph_stable_release }}" - name: Set_fact monitor_name ansible_facts['hostname'] ansible.builtin.set_fact: monitor_name: "{{ hostvars[item]['ansible_facts']['hostname'] }}" delegate_to: "{{ item }}" delegate_facts: true with_items: "{{ groups.get(mon_group_name, []) }}" run_once: true when: groups.get(mon_group_name, []) | length > 0 - name: Find a running monitor when: groups.get(mon_group_name, []) | length > 0 block: - name: Set_fact container_exec_cmd ansible.builtin.set_fact: container_exec_cmd: "{{ container_binary }} exec ceph-mon-{{ hostvars[groups[mon_group_name][0]]['ansible_facts']['hostname'] if not rolling_update | bool else hostvars[mon_host | default(groups[mon_group_name][0])]['ansible_facts']['hostname'] }}" when: - containerized_deployment | bool - name: Find a running mon container ansible.builtin.command: "{{ container_binary }} ps -q --filter name=ceph-mon-{{ hostvars[item]['ansible_facts']['hostname'] }}" register: find_running_mon_container failed_when: false run_once: true delegate_to: "{{ item }}" with_items: "{{ groups.get(mon_group_name, []) }}" changed_when: false when: - containerized_deployment | bool - name: Check for a ceph mon socket ansible.builtin.shell: stat --printf=%n {{ rbd_client_admin_socket_path }}/{{ cluster }}-mon*.asok changed_when: false failed_when: false check_mode: false register: mon_socket_stat run_once: true delegate_to: "{{ item }}" with_items: "{{ groups.get(mon_group_name, []) }}" when: - not containerized_deployment | bool - name: Check if the ceph mon socket is in-use ansible.builtin.command: grep -q {{ item.stdout }} /proc/net/unix changed_when: false failed_when: false check_mode: false register: mon_socket run_once: true delegate_to: "{{ hostvars[item.item]['inventory_hostname'] }}" with_items: "{{ mon_socket_stat.results }}" when: - not containerized_deployment | bool - item.rc == 0 - name: Set_fact running_mon - non_container ansible.builtin.set_fact: running_mon: "{{ hostvars[item.item.item]['inventory_hostname'] }}" with_items: "{{ mon_socket.results }}" run_once: true when: - not containerized_deployment | bool - item.rc is defined - item.rc == 0 - name: Set_fact running_mon - container ansible.builtin.set_fact: running_mon: "{{ item.item }}" run_once: true with_items: "{{ find_running_mon_container.results }}" when: - containerized_deployment | bool - item.stdout_lines | default([]) | length > 0 - name: Set_fact _container_exec_cmd ansible.builtin.set_fact: _container_exec_cmd: "{{ container_binary }} exec ceph-mon-{{ hostvars[groups[mon_group_name][0] if running_mon is undefined else running_mon]['ansible_facts']['hostname'] }}" when: - containerized_deployment | bool # this task shouldn't run in a rolling_update situation # because it blindly picks a mon, which may be down because # of the rolling update - name: Get current fsid if cluster is already running ansible.builtin.command: "{{ timeout_command }} {{ _container_exec_cmd | default('') }} ceph --cluster {{ cluster }} fsid" changed_when: false failed_when: false check_mode: false register: current_fsid run_once: true delegate_to: "{{ groups[mon_group_name][0] if running_mon is undefined else running_mon }}" when: - not rolling_update | bool # set this as a default when performing a rolling_update # so the rest of the tasks here will succeed - name: Set_fact current_fsid rc 1 ansible.builtin.set_fact: current_fsid: rc: 1 when: rolling_update | bool or groups.get(mon_group_name, []) | length == 0 - name: Get current fsid ansible.builtin.command: "{{ timeout_command }} {{ container_exec_cmd }} ceph --admin-daemon /var/run/ceph/{{ cluster }}-mon.{{ hostvars[mon_host | default(groups[mon_group_name][0])]['ansible_facts']['hostname'] }}.asok config get fsid" register: rolling_update_fsid delegate_to: "{{ mon_host | default(groups[mon_group_name][0]) }}" until: rolling_update_fsid is succeeded changed_when: false when: - rolling_update | bool - groups.get(mon_group_name, []) | length > 0 - name: Set_fact fsid ansible.builtin.set_fact: fsid: "{{ (rolling_update_fsid.stdout | from_json).fsid }}" when: - rolling_update | bool - groups.get(mon_group_name, []) | length > 0 - name: Set_fact fsid from current_fsid ansible.builtin.set_fact: fsid: "{{ current_fsid.stdout }}" run_once: true when: current_fsid.rc == 0 - name: Fsid related tasks when: - generate_fsid | bool - current_fsid.rc != 0 - not rolling_update | bool block: - name: Generate cluster fsid ansible.builtin.command: "{{ hostvars[groups[mon_group_name][0]]['discovered_interpreter_python'] }} -c 'import uuid; print(str(uuid.uuid4()))'" register: cluster_uuid delegate_to: "{{ groups[mon_group_name][0] }}" changed_when: false run_once: true - name: Set_fact fsid ansible.builtin.set_fact: fsid: "{{ cluster_uuid.stdout }}" - name: Import_tasks devices.yml ansible.builtin.import_tasks: devices.yml when: inventory_hostname in groups.get(osd_group_name, []) - name: Check if the ceph conf exists ansible.builtin.stat: path: '/etc/ceph/{{ cluster }}.conf' register: ceph_conf - name: Set default osd_pool_default_crush_rule fact ansible.builtin.set_fact: osd_pool_default_crush_rule: "{{ ceph_osd_pool_default_crush_rule }}" - name: Get default crush rule value from ceph configuration when: ceph_conf.stat.exists | bool block: - &read-osd-pool-default-crush-rule name: Read osd pool default crush rule ansible.builtin.command: grep 'osd_pool_default_crush_rule' /etc/ceph/{{ cluster }}.conf register: crush_rule_variable changed_when: false check_mode: false failed_when: crush_rule_variable.rc not in (0, 1) - &set-osd-pool-default-crush-rule-fact name: Set osd_pool_default_crush_rule fact ansible.builtin.set_fact: osd_pool_default_crush_rule: "{{ crush_rule_variable.stdout.split(' = ')[1] }}" when: crush_rule_variable.rc == 0 - name: Get default crush rule value from running monitor ceph configuration when: - running_mon is defined - not ceph_conf.stat.exists | bool block: - <<: *read-osd-pool-default-crush-rule # noqa: name[casing] delegate_to: "{{ running_mon }}" - *set-osd-pool-default-crush-rule-fact - name: Import_tasks set_monitor_address.yml ansible.builtin.import_tasks: set_monitor_address.yml when: groups.get(mon_group_name, []) | length > 0 - name: Import_tasks set_radosgw_address.yml ansible.builtin.include_tasks: set_radosgw_address.yml when: - set_radosgw_address | default(true) - inventory_hostname in groups.get(rgw_group_name, []) - name: Set_fact ceph_run_cmd ansible.builtin.set_fact: ceph_run_cmd: "{{ container_binary + ' run --rm --net=host -v /etc/ceph:/etc/ceph:z -v /var/lib/ceph/:/var/lib/ceph/:z -v /var/log/ceph/:/var/log/ceph/:z --entrypoint=ceph ' + ceph_docker_registry + '/' + ceph_docker_image + ':' + ceph_docker_image_tag if containerized_deployment | bool else 'ceph' }}" delegate_to: "{{ item }}" delegate_facts: true run_once: true with_items: - "{{ groups[mon_group_name] if groups[mon_group_name] | default([]) | length > 0 else [] }}" - "{{ groups[mds_group_name] if groups[mds_group_name] | default([]) | length > 0 else [] }}" - "{{ groups[client_group_name] if groups[client_group_name] | default([]) | length > 0 else [] }}" - name: Set_fact ceph_admin_command ansible.builtin.set_fact: ceph_admin_command: "{{ hostvars[item]['ceph_run_cmd'] }} -n client.admin -k /etc/ceph/{{ cluster }}.client.admin.keyring" delegate_to: "{{ item }}" delegate_facts: true run_once: true with_items: - "{{ groups[mon_group_name] if groups[mon_group_name] | default([]) | length > 0 else [] }}" - "{{ groups[mds_group_name] if groups[mds_group_name] | default([]) | length > 0 else [] }}" - "{{ groups[client_group_name] if groups[client_group_name] | default([]) | length > 0 else [] }}"