add management of /etc/hosts and hostname
This commit is contained in:
@@ -6,6 +6,9 @@ common_apt_repositories:
|
|||||||
- "deb http://security.debian.org/ {{ ansible_distribution_release }}/updates main contrib non-free"
|
- "deb http://security.debian.org/ {{ ansible_distribution_release }}/updates main contrib non-free"
|
||||||
common_apt_upgrade_policy: ""
|
common_apt_upgrade_policy: ""
|
||||||
|
|
||||||
|
common_hostname: True
|
||||||
|
common_hostname_hosts_additional: []
|
||||||
|
|
||||||
common_locales: []
|
common_locales: []
|
||||||
common_locales_default:
|
common_locales_default:
|
||||||
|
|
||||||
|
|||||||
22
tasks/hostname.yml
Normal file
22
tasks/hostname.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
- name: set hostname
|
||||||
|
hostname:
|
||||||
|
name: "{{ inventory_hostname_short }}"
|
||||||
|
|
||||||
|
- name: /etc/hostname
|
||||||
|
copy:
|
||||||
|
dest: /etc/hostname
|
||||||
|
content: "{{ inventory_hostname_short }}\n"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0644
|
||||||
|
backup: yes
|
||||||
|
state: file
|
||||||
|
|
||||||
|
- name: /etc/hosts
|
||||||
|
template:
|
||||||
|
dest: /etc/hosts
|
||||||
|
src: hosts.j2
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0644
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- include: resolvconf.yml
|
- include: resolvconf.yml
|
||||||
|
|
||||||
|
- include: hostname.yml
|
||||||
|
when: common_hostname
|
||||||
|
tags: ['common', 'hostname']
|
||||||
|
|
||||||
- include: apt.yml
|
- include: apt.yml
|
||||||
|
|
||||||
- include: locales.yml
|
- include: locales.yml
|
||||||
|
|||||||
16
templates/hosts.j2
Normal file
16
templates/hosts.j2
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# {{ ansible_managed }}
|
||||||
|
|
||||||
|
127.0.0.1 localhost.localdomain localhost
|
||||||
|
127.0.1.1 {{ inventory_hostname }} {{ inventory_hostname_short }}
|
||||||
|
|
||||||
|
::1 localhost ip6-localhost ip6-loopback
|
||||||
|
ff02::1 ip6-allnodes
|
||||||
|
ff02::2 ip6-allrouters
|
||||||
|
|
||||||
|
{% for host in common_hostname_hosts_additional %}
|
||||||
|
{% if host['short'] is defined %}
|
||||||
|
{{ host['ip'] }} {{ host['fqdn'] }} {{ host['short'] }}
|
||||||
|
{% else %}
|
||||||
|
{{ host['ip'] }} {{ host['fqdn'] }}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
Reference in New Issue
Block a user