Create set_hostname role and playbook
Turns out we have had many issues with random servers having wrong hostname and /etc/hosts info. This playbook/role allows to configure that by passing -e "target=<hostname>" as ansible-playbook parameter. Change-Id: I73939ebc65211a840bb41370c22b111112389716
This commit is contained in:
parent
22fb2fe130
commit
be31fead2f
13
playbooks/roles/set_hostname/tasks/main.yml
Normal file
13
playbooks/roles/set_hostname/tasks/main.yml
Normal file
@ -0,0 +1,13 @@
|
||||
---
|
||||
# Set hostname and /etc/hosts
|
||||
# Inspired by:
|
||||
# https://github.com/ansible/ansible/pull/8482)
|
||||
# https://gist.github.com/rothgar/8793800
|
||||
- name: Set /etc/hostname
|
||||
hostname: name="{{ inventory_hostname.split('.', 1)[0] }}"
|
||||
|
||||
- name: Set /etc/hosts
|
||||
template: src=hosts.j2 dest=/etc/hosts mode=0644
|
||||
|
||||
- name: Set /etc/mailname
|
||||
template: src=mailname.j2 dest=/etc/mailname mode=0644
|
2
playbooks/roles/set_hostname/templates/hosts.j2
Normal file
2
playbooks/roles/set_hostname/templates/hosts.j2
Normal file
@ -0,0 +1,2 @@
|
||||
127.0.0.1 localhost
|
||||
127.0.1.1 {{ inventory_hostname }} {{ inventory_hostname.split('.', 1)[0] }}
|
1
playbooks/roles/set_hostname/templates/mailname.j2
Normal file
1
playbooks/roles/set_hostname/templates/mailname.j2
Normal file
@ -0,0 +1 @@
|
||||
{{ inventory_hostname.split('.', 1)[0] }}
|
7
playbooks/set_hostnames.yml
Normal file
7
playbooks/set_hostnames.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
# file: set_hostnames.yml
|
||||
- hosts: "{{ target }}"
|
||||
gather_facts: no
|
||||
user: root
|
||||
roles:
|
||||
- { role: set_hostname }
|
Loading…
Reference in New Issue
Block a user