From 73d87064618ac39b744342ebe2e6a0d808c68487 Mon Sep 17 00:00:00 2001 From: Sam Al-Sapti Date: Sun, 5 Nov 2023 19:27:30 +0100 Subject: [PATCH] Add hosts file --- roles/common/tasks/base.yml | 7 +++++++ roles/common/templates/etc/hosts.j2 | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 roles/common/templates/etc/hosts.j2 diff --git a/roles/common/tasks/base.yml b/roles/common/tasks/base.yml index d68a727..1111905 100644 --- a/roles/common/tasks/base.yml +++ b/roles/common/tasks/base.yml @@ -9,6 +9,13 @@ community.general.timezone: name: "{{ timezone }}" +- name: Copy hosts file + ansible.builtin.template: + src: etc/hosts.j2 + dest: /etc/hosts + owner: root + mode: u=rw,g=r,o=r + - name: Set /etc/resolv.conf symlink ansible.builtin.file: path: /etc/resolv.conf diff --git a/roles/common/templates/etc/hosts.j2 b/roles/common/templates/etc/hosts.j2 new file mode 100644 index 0000000..96c08f5 --- /dev/null +++ b/roles/common/templates/etc/hosts.j2 @@ -0,0 +1,16 @@ +# code: language=ansible-jinja +127.0.1.1 {{ hostname }} {{ hostname }} +127.0.0.1 localhost + +# The following lines are desirable for IPv6 capable hosts +::1 ip6-localhost ip6-loopback +fe00::0 ip6-localnet +ff00::0 ip6-mcastprefix +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters +ff02::3 ip6-allhosts + +# Static hostnames for VMs +{% for host in groups[all] %} +{{ hostvars[host].ansible_eth1.ipv4.address }} {{ hostvars[host].ansible_host }} +{% endfor %}