cleanup-hosts/tasks/main_linebreak.yml

28 lines
738 B
YAML
Raw Normal View History

---
- 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'}}"
- name: Add name/IP to hosts file
lineinfile: >
dest=/etc/hosts
regexp='^{{ ansible_default_ipv4.address }}'
line='{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.{{ domainname }} {{ ansible_hostname }}'
backup=yes
- name: Clean/remove 127.0.1.1
lineinfile: >
dest=/etc/hosts
regexp='^127.0.1.1'
state=absent
backup=yes
- name: Ensure 127.0.0.1 localhost
lineinfile: >
dest=/etc/hosts
regexp='127.0.0.1'
line='127.0.0.1 localhost localhost.localdomain'
insertbefore=BOF
backup=yes