2018-11-27 13:32:06 +00:00
|
|
|
---
|
2019-11-26 14:03:57 +00:00
|
|
|
- name: Detect domain name
|
|
|
|
set_fact:
|
|
|
|
domainname: "{{ ansible_dns.domain|default(False) or ansible_dns.search.0|default(False) or ansible_domain|default(False) or 'invalid'}}"
|
|
|
|
|
2018-11-27 13:32:06 +00:00
|
|
|
- name: Add name/IP to hosts file
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/hosts
|
2019-11-26 14:03:57 +00:00
|
|
|
regexp: '^{{ ansible_default_ipv4.address }}'
|
|
|
|
line: '{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.{{ domainname }} {{ ansible_hostname }}'
|
2018-11-27 13:32:06 +00:00
|
|
|
backup: yes
|
|
|
|
|
|
|
|
- name: Clean/remove 127.0.1.1
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/hosts
|
2019-11-26 14:03:57 +00:00
|
|
|
regexp: '^127.0.1.1'
|
2018-11-27 13:32:06 +00:00
|
|
|
state: absent
|
|
|
|
backup: yes
|
|
|
|
|
|
|
|
- name: Ensure 127.0.0.1 localhost
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/hosts
|
2019-11-26 14:03:57 +00:00
|
|
|
regexp: '127.0.0.1'
|
|
|
|
line: '127.0.0.1 localhost localhost.localdomain'
|
2018-11-27 13:32:06 +00:00
|
|
|
insertbefore: BOF
|
|
|
|
backup: yes
|
|
|
|
|