[EVO] Utiliser l'inventaire d'ansible
This commit is contained in:
parent
b9baf12530
commit
6e48e05990
20
tasks/clients.yml
Normal file
20
tasks/clients.yml
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
# tasks file for security
|
||||
|
||||
- name: Générer le fichier d'hôtes en partant de l'inventaire ansible
|
||||
ansible.builtin.template:
|
||||
src: ansible_inventory.conf.j2
|
||||
dest: /srv/dnsmasq/ansible_inventory.conf.disabled
|
||||
owner: dnsmasq
|
||||
group: root
|
||||
mode: u=rw,g=r,o=r
|
||||
when:
|
||||
- dnsmasq_servers | length > 0
|
||||
- dnsmasq_host_ipv4 not in dnsmasq_servers
|
||||
tags: creation
|
||||
loop: "{{ dnsmasq_servers }}"
|
||||
loop_control:
|
||||
loop_var: dnsserver
|
||||
delegate_to: "{{ dnsserver }}"
|
||||
become: true
|
||||
notify: Recharger dnsmasq.service sur les serveurs
|
13
templates/ansible_inventory.conf.j2
Normal file
13
templates/ansible_inventory.conf.j2
Normal file
@ -0,0 +1,13 @@
|
||||
# {{ ansible_managed }}
|
||||
|
||||
{% for ip in dnsmasq_host_ips %}
|
||||
{% endfor %}
|
||||
|
||||
{% set last_host = groups['all'] | last %}
|
||||
{% for host in groups['all'] %}
|
||||
{% set hostnames = [hostvars[host]['inventory_hostname']] + [hostvars[host]['inventory_hostname_short']] + dnsmasq_host_aliases %}
|
||||
{{ ip }} {{ hostnames | select() | join(' ') }}
|
||||
{% if host != last_host %}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
Loading…
Reference in New Issue
Block a user