2022-12-21 22:56:39 -05:00
|
|
|
---
|
|
|
|
- name: Set hostname
|
|
|
|
hostname:
|
|
|
|
name: '{{ inventory_hostname | replace("_", "-") }}'
|
|
|
|
|
2022-12-22 19:31:20 -05:00
|
|
|
- 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
|
|
|
|
|
2022-12-21 22:56:39 -05:00
|
|
|
- name: Add hostname to /etc/hosts
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/hosts
|
|
|
|
regexp: '^127\.0\.0\.1[ \t]+localhost'
|
|
|
|
line: '127.0.0.1 localhost {{ inventory_hostname | replace("_", "-") }}'
|
|
|
|
state: present
|
|
|
|
|
|
|
|
- name: Install ansible pre-requisites
|
|
|
|
apt:
|
|
|
|
name:
|
|
|
|
- acl
|
|
|
|
state: present
|