inventoryFromAnsible #4

Merged
pulsar merged 10 commits from inventoryFromAnsible into master 2024-05-06 18:48:20 +00:00
4 changed files with 32 additions and 2 deletions
Showing only changes of commit 6258dd6d57 - Show all commits

View File

@ -46,6 +46,12 @@ Nom d'hôte du client.
*<span style="text-decoration: underline">Valeur par défaut:</span> `{{ inventory_hostname }} {{ inventory_hostname_short }}`* *<span style="text-decoration: underline">Valeur par défaut:</span> `{{ inventory_hostname }} {{ inventory_hostname_short }}`*
### dnsmasq_specifics
Liste de dictionnaires contenant le nom d'hôte, les alias et la liste d'IP associées.
*<span style="text-decoration: underline">Valeur par défaut:</span> aucune*
## Exemple d'utilisation ## Exemple d'utilisation
### inventory.yml ### inventory.yml

View File

@ -11,3 +11,5 @@ dnsmasq_host_aliases: []
dnsmasq_client_filename: "{{ inventory_hostname }}" dnsmasq_client_filename: "{{ inventory_hostname }}"
dnsmasq_client_hostname: "{{ inventory_hostname }} {{ inventory_hostname_short }}" dnsmasq_client_hostname: "{{ inventory_hostname }} {{ inventory_hostname_short }}"
dnsmasq_specifics: []

View File

@ -13,10 +13,26 @@
- name: Déployer la configuration de l'instance - name: Déployer la configuration de l'instance
ansible.builtin.template: ansible.builtin.template:
src: host.conf.j2
dest: /srv/dnsmasq/{{ inventory_hostname }}.conf
owner: dnsmasq owner: dnsmasq
group: root group: root
mode: u=rw,g=r,o=r mode: u=rw,g=r,o=r
src: host.conf.j2
dest: /srv/dnsmasq/{{ inventory_hostname }}.conf
become: true become: true
notify: Recharger dnsmasq.service notify: Recharger dnsmasq.service
- name: Déployer les configurations specifiques
ansible.builtin.template:
src: specific.conf.j2
dest: "{{ filename }}"
owner: dnsmasq
group: root
mode: u=rw,g=r,o=r
when: dnsmasq_specifics | length > 0
become: true
notify: Recharger dnsmasq.service
loop: "{{ dnsmasq_specifics }}"
loop_control:
label: "{{ filename }}"
vars:
filename: /srv/dnsmasq/{{ item.hostname }}.conf

View File

@ -0,0 +1,6 @@
# {{ ansible_managed }}
{% for ip in item.ips %}
{% set aliases = item.get('aliases', []) %}
{{ ip }} {{ ([item.hostname] + aliases) | join(' ') }}
{% endfor %}