Purge conditions of /etc/hosts are the same as permanent ip address (ipv4).
This commit is contained in:
parent
d8a3e11a9b
commit
3ff80a95e7
|
@ -1,9 +1,10 @@
|
||||||
## v1.0.X
|
## v1.0.1
|
||||||
|
|
||||||
## Enhancements
|
## Enhancements
|
||||||
* Add example playbook.
|
* 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).
|
* 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 /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
|
## v1.0
|
||||||
|
|
||||||
|
|
19
README.md
19
README.md
|
@ -18,12 +18,12 @@ Manage some basics configuration for IPR's servers.
|
||||||
* **basics__domain** : Domain to use [default : `{{ ansible_domain }}`].
|
* **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_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_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_manage** : If the ipv4 address 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_content** : Content of the ipv4 address line [default : `{{ ansible_hostname }}.{{ basics__domain }} {{ ansible_hostname }}`].
|
||||||
|
|
||||||
## Example Playbook
|
## 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
|
``` yml
|
||||||
- hosts: serverXYZ
|
- hosts: serverXYZ
|
||||||
|
@ -39,18 +39,19 @@ Manage some basics configuration for IPR's servers.
|
||||||
- hosts: serverXYZ
|
- hosts: serverXYZ
|
||||||
roles:
|
roles:
|
||||||
- role: ipr-cnrs.basics
|
- role: ipr-cnrs.basics
|
||||||
basics__hosts_localhost_manage: true
|
|
||||||
basics__domain: 'mydomain.org'
|
basics__domain: 'mydomain.org'
|
||||||
|
basics__hosts_ipv4_manage: true
|
||||||
````
|
````
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
### Hosts
|
### 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.
|
Ensure to have the correct fqdn and hostname in /etc/hosts :
|
||||||
- You can choose to define the localhost (127.0.0.1) line content.
|
- You can define the domain if it's not correct on the remote host.
|
||||||
- You can choose to define the permanent ip (127.0.0.1) line content.
|
- You can choose to define the localhost (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
|
## Development
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
## Modify /etc/hosts
|
## 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:
|
lineinfile:
|
||||||
dest: /etc/hosts
|
dest: /etc/hosts
|
||||||
state: present
|
state: present
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
when: (basics__hosts_localhost_manage and
|
when: (basics__hosts_localhost_manage and
|
||||||
ansible_lo.ipv4.address is defined)
|
ansible_lo.ipv4.address is defined)
|
||||||
|
|
||||||
- name: Set ipv4 line in hosts file
|
- name: Config host - Set ipv4 line in hosts file
|
||||||
lineinfile:
|
lineinfile:
|
||||||
dest: /etc/hosts
|
dest: /etc/hosts
|
||||||
state: present
|
state: present
|
||||||
|
@ -22,14 +22,14 @@
|
||||||
backup: yes
|
backup: yes
|
||||||
when: (basics__hosts_ipv4_manage and
|
when: (basics__hosts_ipv4_manage and
|
||||||
ansible_default_ipv4.address is defined)
|
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:
|
lineinfile:
|
||||||
dest: /etc/hosts
|
dest: /etc/hosts
|
||||||
state: absent
|
state: absent
|
||||||
regexp: '^(?!({{ ansible_default_ipv4.address }})).*{{ ansible_hostname }}'
|
regexp: '^(?!({{ ansible_default_ipv4.address }})).*{{ ansible_hostname }}'
|
||||||
backup: yes
|
backup: yes
|
||||||
when: basics__register_ipv4_line.changed
|
when: (basics__hosts_ipv4_manage and
|
||||||
|
ansible_default_ipv4.address is defined)
|
||||||
|
|
||||||
## }}}
|
## }}}
|
||||||
|
|
Reference in New Issue