common: ssh tasks use the ssh unit that Ubuntu also has, cloud-init no longer rewrites /etc/hosts at boot

This commit is contained in:
2026-11-07 18:51:22 +00:00
parent 4abfea352c
commit 3290d843cc
3 changed files with 19 additions and 2 deletions
+15
View File
@@ -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 }}
+2
View File
@@ -8,6 +8,8 @@
- import_tasks: ./timesync.yml - import_tasks: ./timesync.yml
- import_tasks: ./cloud_init.yml
- import_tasks: ./aliases.yml - import_tasks: ./aliases.yml
- import_tasks: ./networking.yml - import_tasks: ./networking.yml
+2 -2
View File
@@ -1,6 +1,6 @@
- name: Check if SSH daemon is active - name: Check if SSH daemon is active
systemd: systemd:
name: sshd name: ssh
state: started state: started
register: sshd_status register: sshd_status
@@ -14,7 +14,7 @@
- name: Restart SSH daemon - name: Restart SSH daemon
service: service:
name: sshd name: ssh
state: restarted state: restarted
when: sshd_config.changed when: sshd_config.changed
when: sshd_status.status.ActiveState == 'active' when: sshd_status.status.ActiveState == 'active'