ansible-roles/library/roles/deb-set-hostname/tasks/main.yml

18 lines
710 B
YAML
Raw Normal View History

---
- name: Set the hostname when different from the inventory one.
hostname: name={{ hostname }}
when: hostname is defined
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
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
2018-09-05 17:02:03 +02:00
when:
- hostname is defined
- ansible_virtualization_type == 'xen'
tags: [ 'bootstrap', 'set_hostname' ]