add hosts file management

This commit is contained in:
vincent 2021-07-18 11:39:52 +02:00
parent 4481b8277d
commit f8cffd3b03
5 changed files with 35 additions and 0 deletions

View File

@ -111,3 +111,8 @@ privatekeytodeploy: []
# keyfile: /root/.ssh/id_rsa
# privatekey: {{ vault_privatekey }}
# Custom hosts entries to be added
hosts_entries: []
# Custom host file snippets to be added
hosts_file_snippets: []

8
tasks/hosts.yml Normal file
View File

@ -0,0 +1,8 @@
- name: Install custom hosts file
become: true
template:
src: etc_hosts.j2
dest: "{{ hosts_file }}"
owner: root
group: root
mode: 0644

View File

@ -1,4 +1,5 @@
#- include_tasks: hostname.yml
- include_tasks: hosts.yml
- include_tasks: hostname.yml
- include_tasks: locales.yml
- include_tasks: time.yml

19
templates/etc_hosts.j2 Normal file
View File

@ -0,0 +1,19 @@
# Hosts file -- Don't edit manually!
#
# {{ ansible_managed }}
{% if hosts_entries|length != 0 %}
# Custom entries
{% for host in hosts_entries %}
{{ host.ip }} {{ host.name }} {{ host.aliases | default('') | join(' ') }}
{% endfor %}
{% endif %}
{% if hosts_file_snippets %}
#
# Hosts file snippets
#
{{ hosts_file_snippets }}
{% endif %}

View File

@ -0,0 +1,2 @@
---
hosts_file: "/etc/hosts"