From 3290d843ccc8df9c463d1fc5412396916dd2875f Mon Sep 17 00:00:00 2001 From: Ruakij Date: Sat, 7 Nov 2026 18:51:22 +0000 Subject: [PATCH] common: ssh tasks use the ssh unit that Ubuntu also has, cloud-init no longer rewrites /etc/hosts at boot --- common/tasks/cloud_init.yml | 15 +++++++++++++++ common/tasks/main.yml | 2 ++ common/tasks/ssh.yml | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 common/tasks/cloud_init.yml diff --git a/common/tasks/cloud_init.yml b/common/tasks/cloud_init.yml new file mode 100644 index 0000000..b385a4c --- /dev/null +++ b/common/tasks/cloud_init.yml @@ -0,0 +1,15 @@ +# With manage_etc_hosts in the user-data (Proxmox sets it) cloud-init rewrites /etc/hosts from its +# template on every boot and drops the blocks other roles add; user-data outranks cloud.cfg.d, so +# the module is taken out of the boot stage instead. +- name: Read the cloud-init configuration + slurp: + path: /etc/cloud/cloud.cfg + register: cloud_cfg + failed_when: false + +- name: Keep cloud-init from rewriting /etc/hosts + when: cloud_cfg.content is defined + copy: + dest: /etc/cloud/cloud.cfg.d/99-ansible-etc-hosts.cfg + content: | + cloud_init_modules: {{ (cloud_cfg.content | b64decode | from_yaml).cloud_init_modules | reject('equalto', 'update_etc_hosts') | list | to_json }} diff --git a/common/tasks/main.yml b/common/tasks/main.yml index 6a40538..69fd5f3 100755 --- a/common/tasks/main.yml +++ b/common/tasks/main.yml @@ -8,6 +8,8 @@ - import_tasks: ./timesync.yml +- import_tasks: ./cloud_init.yml + - import_tasks: ./aliases.yml - import_tasks: ./networking.yml diff --git a/common/tasks/ssh.yml b/common/tasks/ssh.yml index 17a61a8..75c567b 100644 --- a/common/tasks/ssh.yml +++ b/common/tasks/ssh.yml @@ -1,6 +1,6 @@ - name: Check if SSH daemon is active systemd: - name: sshd + name: ssh state: started register: sshd_status @@ -14,7 +14,7 @@ - name: Restart SSH daemon service: - name: sshd + name: ssh state: restarted when: sshd_config.changed when: sshd_status.status.ActiveState == 'active'