Purge /etc/hosts of multiple lines that contains $HOSTNAME without the default ipv4 ip address.
See : https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=316099
This commit is contained in:
parent
da459374b2
commit
d8a3e11a9b
|
@ -3,6 +3,7 @@
|
|||
## Enhancements
|
||||
* Add example playbook.
|
||||
* localhost line sould not contain hostname information (see https://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_hostname_resolution).
|
||||
* Purge /etc/hosts of multiple lines that contains $HOSTNAME without the default ipv4 ip address.
|
||||
|
||||
## v1.0
|
||||
|
||||
|
|
|
@ -48,7 +48,9 @@ Manage some basics configuration for IPR's servers.
|
|||
### Hosts
|
||||
- Ensure to have the correct fqdn and hostname in /etc/hosts.
|
||||
- You can define the domain if it's not correct on the remote host.
|
||||
- You can choose to define the localhost (127.0.0.1) line or/and the ipv4 (lan) line.
|
||||
- You can choose to define the localhost (127.0.0.1) line content.
|
||||
- You can choose to define the permanent ip (127.0.0.1) line content.
|
||||
- All other lines that contains hostname without this permanent ip will be removed.
|
||||
|
||||
## Development
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
---
|
||||
# tasks file for basics
|
||||
|
||||
## Modify /etc/hosts
|
||||
|
||||
- name: Set 127.0.0.1 line in hosts file
|
||||
lineinfile:
|
||||
dest: /etc/hosts
|
||||
|
@ -20,3 +22,14 @@
|
|||
backup: yes
|
||||
when: (basics__hosts_ipv4_manage and
|
||||
ansible_default_ipv4.address is defined)
|
||||
register: basics__register_ipv4_line
|
||||
|
||||
- name: Purge other lines with hostname
|
||||
lineinfile:
|
||||
dest: /etc/hosts
|
||||
state: absent
|
||||
regexp: '^(?!({{ ansible_default_ipv4.address }})).*{{ ansible_hostname }}'
|
||||
backup: yes
|
||||
when: basics__register_ipv4_line.changed
|
||||
|
||||
## }}}
|
||||
|
|
Reference in New Issue