diff --git a/roles/instance/tasks/main.yml b/roles/instance/tasks/main.yml index 789254f..6ffd4c3 100644 --- a/roles/instance/tasks/main.yml +++ b/roles/instance/tasks/main.yml @@ -3,6 +3,19 @@ hostname: name: '{{ inventory_hostname | replace("_", "-") }}' +- name: check if rules file exists + stat: + path: /etc/cloud/cloud.cfg + register: cloud_cfg + +- name: Prevent cloud-init hostname setting + lineinfile: + dest: /etc/cloud/cloud.cfg + regexp: '^preserve_hostname:' + line: 'preserve_hostname: true' + state: present + when: cloud_cfg.stat.exists + - name: Add hostname to /etc/hosts lineinfile: dest: /etc/hosts diff --git a/site.yml b/site.yml index 0d3ebe2..a984fae 100644 --- a/site.yml +++ b/site.yml @@ -8,6 +8,7 @@ cache_valid_time: 3600 roles: - role: instance + tags: instance - role: apt - role: firewall - role: administrators