diff --git a/.gitignore b/.gitignore index 5088f03..07c396e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # ansible-test output /tests/output +/.ansible # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/roles/cephadm/tasks/bootstrap.yml b/roles/cephadm/tasks/bootstrap.yml index 2f2bec0..3a2cb5b 100644 --- a/roles/cephadm/tasks/bootstrap.yml +++ b/roles/cephadm/tasks/bootstrap.yml @@ -43,6 +43,7 @@ cmd: "cephadm shell -- ceph config set mon public_network {{ cephadm_public_network }}" become: true changed_when: true + when: cephadm_public_network | length > 0 - name: Set cluster network command: @@ -67,7 +68,7 @@ - name: Get cluster fsid command: - cmd: "cephadm shell -- ceph fsid" + cmd: "cephadm ls --no-detail" when: cephadm_fsid | length == 0 become: true changed_when: false @@ -75,7 +76,8 @@ - name: Template out cluster.yml vars: - fsid: "{{ cephadm_fsid if cephadm_fsid | length > 0 else cephadm_fsid_current.stdout }}" + current_fsid: "{{ cephadm_fsid_current.stdout | from_json | selectattr('name', 'search', 'mon') | map(attribute='fsid') | first }}" + fsid: "{{ cephadm_fsid if cephadm_fsid | length > 0 else current_fsid }}" template: src: "templates/cluster.yml.j2" dest: "/var/run/ceph/{{ fsid }}/cephadm_cluster.yml" diff --git a/roles/cephadm/tasks/prechecks.yml b/roles/cephadm/tasks/prechecks.yml index 3433a0c..421a3f6 100644 --- a/roles/cephadm/tasks/prechecks.yml +++ b/roles/cephadm/tasks/prechecks.yml @@ -1,4 +1,19 @@ --- +- name: Assert that required Ansible groups exist + ansible.builtin.assert: + that: "'{{ item }}' in group_names" + msg: "Ansible '{{ item }}' group does not exist - please create one" + loop: + - ceph + - mons + - mgrs + - osds + +- name: Assert that cephadm_public_interface is set + ansible.builtin.assert: + that: cephadm_public_interface | length > 0 + msg: "Ansible Cephadm interface variable 'cephadm_public_interface' is not set" + - name: Populate service facts service_facts: diff --git a/roles/cephadm/templates/cluster.yml.j2 b/roles/cephadm/templates/cluster.yml.j2 index 31a3500..606bb66 100644 --- a/roles/cephadm/templates/cluster.yml.j2 +++ b/roles/cephadm/templates/cluster.yml.j2 @@ -2,7 +2,7 @@ --- service_type: host hostname: {{ hostvars[host].ansible_facts.nodename }} -{% set cephadm_admin_interface = hostvars[host]['cephadm_admin_interface'] %} +{% set cephadm_admin_interface = hostvars[host].cephadm_admin_interface | default(cephadm_admin_interface) %} addr: {{ hostvars[host]['ansible_facts'][cephadm_admin_interface | replace('-', '_')]['ipv4']['address'] }} labels: {% if host in groups['mons'] %} diff --git a/test-requirements.txt b/test-requirements.txt index 0688036..61fbe66 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,5 +1,5 @@ ansible>=2.9 -ansible-lint<7 +ansible-lint<26 antsibull-changelog mock pytest