forked from ISTI-ansible-roles/ansible-roles
Set the hostname identical to the inventory hostname if no 'hostname' variable has been defined.
This commit is contained in:
parent
76aa23c024
commit
d53f160afb
|
@ -1,9 +1,14 @@
|
||||||
---
|
---
|
||||||
- name: Set the hostname
|
- name: Set the hostname when different from the inventory one.
|
||||||
hostname: name={{ hostname }}
|
hostname: name={{ hostname }}
|
||||||
when: hostname is defined
|
when: hostname is defined
|
||||||
tags: [ 'bootstrap', 'set_hostname' ]
|
tags: [ 'bootstrap', 'set_hostname' ]
|
||||||
|
|
||||||
|
- name: Set the hostname as defined in the inventory
|
||||||
|
hostname: name={{ inventory_hostname }}
|
||||||
|
when: hostname is not defined
|
||||||
|
tags: [ 'bootstrap', 'set_hostname' ]
|
||||||
|
|
||||||
- name: Add the hostname to /etc/hosts
|
- name: Add the hostname to /etc/hosts
|
||||||
shell: grep -v {{ ansible_default_ipv4.address }} /etc/hosts > /etc/hosts.tmp ; echo "{{ ansible_default_ipv4.address }} {{ hostname }} {{ ansible_hostname }}" >> /etc/hosts.tmp ; /bin/mv /etc/hosts.tmp /etc/hosts
|
shell: grep -v {{ ansible_default_ipv4.address }} /etc/hosts > /etc/hosts.tmp ; echo "{{ ansible_default_ipv4.address }} {{ hostname }} {{ ansible_hostname }}" >> /etc/hosts.tmp ; /bin/mv /etc/hosts.tmp /etc/hosts
|
||||||
when:
|
when:
|
||||||
|
|
Loading…
Reference in New Issue