From c3cbf1ecb437a95611451cc296017dd06a82f4cc Mon Sep 17 00:00:00 2001 From: Piotr Parczewski Date: Tue, 2 Sep 2025 09:25:47 +0200 Subject: [PATCH 1/2] Apply various fixes (cherry picked from commit 79368655db2c9db33be6c0b70fed0768827bfad6) Co-authored-by: Michal Nasiadka --- .gitignore | 1 + roles/cephadm/tasks/bootstrap.yml | 6 ++++-- roles/cephadm/tasks/prechecks.yml | 15 +++++++++++++++ roles/cephadm/templates/cluster.yml.j2 | 2 +- test-requirements.txt | 2 +- 5 files changed, 22 insertions(+), 4 deletions(-) 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..90266b4 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 From 38b9e0252237a11fb36663f567d10b6118d83ca2 Mon Sep 17 00:00:00 2001 From: Piotr Parczewski Date: Tue, 2 Sep 2025 12:02:58 +0200 Subject: [PATCH 2/2] Improve default interface handling --- roles/cephadm/templates/cluster.yml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/cephadm/templates/cluster.yml.j2 b/roles/cephadm/templates/cluster.yml.j2 index 90266b4..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'] | default(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'] %}