hostname: Also write /etc/hosts

This commit introduces a new role, *hostname*, that is used by the
`hostname.yml` playbook to set the hostname. It also writes
`/etc/hosts` using a template.
jenkins-master
Dustin 2018-04-08 10:11:43 -05:00
parent 66339a827d
commit 712d298b38
4 changed files with 13 additions and 4 deletions

View File

@ -1,5 +1,3 @@
- hosts: all
tasks:
- name: ensure hostname is set
hostname:
name={{ preferred_hostname|d(inventory_hostname) }}
roles:
- hostname

View File

@ -0,0 +1 @@
preferred_hostname: '{{ inventory_hostname }}'

View File

@ -0,0 +1,8 @@
- name: ensure hostname is set
hostname:
name={{ preferred_hostname }}
- name: ensure hosts file is populated
template:
src=hosts.j2
dest=/etc/hosts
mode=0644

View File

@ -0,0 +1,2 @@
127.0.0.1 {{ preferred_hostname }} {{ preferred_hostname.split('.')[0] }} localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 {{ preferred_hostname }} {{ preferred_hostname.split('.')[0] }} localhost localhost.localdomain localhost6 localhost6.localdomain6