Purge conditions of /etc/hosts are the same as permanent ip address (ipv4).

This commit is contained in:
Jeremy Gardais 2018-01-12 17:12:11 +01:00
parent d8a3e11a9b
commit 3ff80a95e7
3 changed files with 17 additions and 15 deletions

View File

@ -1,9 +1,10 @@
## v1.0.X
## v1.0.1
## 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.
* Purge conditions of /etc/hosts are the same as permanent ip address (ipv4).
## v1.0

View File

@ -18,12 +18,12 @@ Manage some basics configuration for IPR's servers.
* **basics__domain**: Domain to use [default: `{{ ansible_domain }}`].
* **basics__hosts_localhost_manage**: If the localhost (127.0.0.1) line should be managed [default: `false`].
* **basics__hosts_localhost_content**: Content of the localhost (127.0.0.1) line [default: `localhost.localdomain localhost`].
* **basics__hosts_ipv4_manage**: If the ipv4 (lan) line should be managed [default: `false`].
* **basics__hosts_ipv4_content**: Content of the ipv4 (lan) line [default: `{{ ansible_hostname }}.{{ basics__domain }} {{ ansible_hostname }}`].
* **basics__hosts_ipv4_manage**: If the ipv4 address line should be managed [default: `false`].
* **basics__hosts_ipv4_content**: Content of the ipv4 address line [default: `{{ ansible_hostname }}.{{ basics__domain }} {{ ansible_hostname }}`].
## Example Playbook
* If you want to manage both localhost (127.0.0.1) and permanent IP (lan/ipv4) lines:
* If you want to manage both localhost (127.0.0.1) and permanent IP (ipv4) lines:
``` yml
- hosts: serverXYZ
@ -39,18 +39,19 @@ Manage some basics configuration for IPR's servers.
- hosts: serverXYZ
roles:
- role: ipr-cnrs.basics
basics__hosts_localhost_manage: true
basics__domain: 'mydomain.org'
basics__hosts_ipv4_manage: true
````
## Configuration
### Hosts
- Ensure to have the correct fqdn and hostname in /etc/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 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.
- You can choose to define the permanent ip (ipv4) line content.
- All other lines that contains hostname without this permanent ip address will be removed.
## Development

View File

@ -3,7 +3,7 @@
## Modify /etc/hosts
- name: Set 127.0.0.1 line in hosts file
- name: Config host - Set 127.0.0.1 line in hosts file
lineinfile:
dest: /etc/hosts
state: present
@ -13,7 +13,7 @@
when: (basics__hosts_localhost_manage and
ansible_lo.ipv4.address is defined)
- name: Set ipv4 line in hosts file
- name: Config host - Set ipv4 line in hosts file
lineinfile:
dest: /etc/hosts
state: present
@ -22,14 +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
- name: Config host - 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
when: (basics__hosts_ipv4_manage and
ansible_default_ipv4.address is defined)
## }}}