From b656ce9f665ac0c0b57b1737ff4278f9682b185b Mon Sep 17 00:00:00 2001 From: Alexandre Le Gall Date: Fri, 22 Sep 2023 17:25:03 +0200 Subject: [PATCH] [EVO] Utiliser l'inventaire d'ansible --- tasks/configuration.yml | 15 +++++++++++++++ templates/hosts.conf.j2 | 6 ++++++ 2 files changed, 21 insertions(+) create mode 100644 templates/hosts.conf.j2 diff --git a/tasks/configuration.yml b/tasks/configuration.yml index 9147453..cfda839 100644 --- a/tasks/configuration.yml +++ b/tasks/configuration.yml @@ -20,3 +20,18 @@ dest: /srv/dnsmasq/{{ inventory_hostname }}.conf become: true notify: Recharger dnsmasq.service + +- name: Déployer le fichier d'hôte en partant de l'inventaire +# ansible.builtin.template: + ansible.builtin.blockinfile: + path: /srv/dnsmasq/ansible_inventory.conf.disabled + marker: "# {mark} ANSIBLE MANAGED BLOCK for {{ inventory_hostname }} " + create: true + owner: dnsmasq + group: root + mode: u=rw,g=r,o=r +# src: hosts.conf.j2 +# dest: /srv/dnsmasq/ansible_inventory.conf.disabled + become: true + notify: Recharger dnsmasq.service + loop: "{{ groups['all'] }}" diff --git a/templates/hosts.conf.j2 b/templates/hosts.conf.j2 new file mode 100644 index 0000000..fb25490 --- /dev/null +++ b/templates/hosts.conf.j2 @@ -0,0 +1,6 @@ +# {{ ansible_managed }} + +{% for ip in dnsmasq_host_ips %} +{% set hostnames = [hostvars[host]['inventory_hostname']] + [hostvars[host]['inventory_hostname_short']] + dnsmasq_host_aliases %} +{{ ip }} {{ hostnames | select() | join(' ') }} +{% endfor %}