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'