diff --git a/defaults/main.yml b/defaults/main.yml index 6e6714d..eb318f3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -15,4 +15,8 @@ dnsmasq_host_aliases: [] dnsmasq_client_filename: "{{ inventory_hostname }}" dnsmasq_client_hostname: "{{ inventory_hostname }} {{ inventory_hostname_short }}" +# Groupe ansible pour l'enregistrement automatique +dnsmasq_ansible_group: zone_gaia + +# Enregistrement spécifiques dnsmasq_specifics: [] diff --git a/meta/main.yml b/meta/main.yml index b2f4afc..29fb6a3 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -12,5 +12,4 @@ galaxy_info: versions: - all -dependencies: - - role: nftables +dependencies: [] diff --git a/tasks/client.yml b/tasks/client.yml index b9d1620..8905487 100644 --- a/tasks/client.yml +++ b/tasks/client.yml @@ -1,13 +1,13 @@ --- # tasks file for security -- name: Déployer le fichier lié à l'hôte +- name: Déploiement des enregistrement via ansible ansible.builtin.template: owner: dnsmasq group: root mode: u=rw,g=r,o=r - src: "{{ role_path }}/templates/host.conf.j2" - dest: /srv/dnsmasq/{{ dnsmasq_client_filename }}.conf + src: "{{ role_path }}/templates/auto.conf.j2" + dest: /srv/dnsmasq/auto_{{ dnsmasq_ansible_group }}.conf when: dnsmasq_hosts | length > 0 become: true delegate_to: "{{ dnsserver }}" @@ -15,16 +15,3 @@ loop_control: loop_var: dnsserver notify: Recharger dnsmasq.service sur les serveurs - -- name: Supprimer le fichier lié à l'hôte - ansible.builtin.file: - path: /srv/dnsmasq/{{ dnsmasq_client_filename }}.conf - state: absent - when: dnsmasq_hosts | length > 0 - tags: [destruction, never] - become: true - delegate_to: "{{ dnsserver }}" - loop: "{{ dnsmasq_hosts }}" - loop_control: - loop_var: dnsserver - notify: Recharger dnsmasq.service sur les serveurs diff --git a/templates/auto.conf.j2 b/templates/auto.conf.j2 new file mode 100644 index 0000000..ec882c4 --- /dev/null +++ b/templates/auto.conf.j2 @@ -0,0 +1,17 @@ +# {{ ansible_managed }} + +{% for host in groups[dnsmasq_ansible_group] %} +{%- set ipv4 = hostvars[host]['ansible_host'] %} +{%- set ipv6_suffix = hostvars[host]['ansible_host'] | split('.') | last %} +{%- set aliases = [host] + hostvars[host].get('dnsmasq_host_aliases', []) %} + +# {{ host }} +{{ ipv4 }} {{ aliases | join(' ') }} +{% if (ipv6_suffix | int) < 10 %} +2a01:e0a:ee5:8b0::d00{{ ipv6_suffix }} {{ aliases | join(' ') }} +{% elif (ipv6_suffix | int) < 100 %} +2a01:e0a:ee5:8b0::d0{{ ipv6_suffix }} {{ aliases | join(' ') }} +{% else %} +2a01:e0a:ee5:8b0::d{{ ipv6_suffix }} {{ aliases | join(' ') }} +{% endif %} +{% endfor %} diff --git a/templates/specific.conf.j2 b/templates/specific.conf.j2 index d3157f9..f78dffa 100644 --- a/templates/specific.conf.j2 +++ b/templates/specific.conf.j2 @@ -1,6 +1,17 @@ # {{ ansible_managed }} -{% for ip in item.ips %} -{% set aliases = item.get('aliases', []) %} -{{ ip }} {{ ([item.hostname] + aliases) | join(' ') }} +{% for host in groups['zone_gaia'] %} +{%- set ipv4 = hostvars[host]['ansible_host'] %} +{%- set ipv6_suffix = hostvars[host]['ansible_host'] | split('.') | last %} +{%- set aliases = [host] + hostvars[host].get('dnsmasq_host_aliases', []) %} + +# {{ host }} +{{ ipv4 }} {{ aliases | join(' ') }} +{% if (ipv6_suffix | int) < 10 %} +2a01:e0a:ee5:8b0::d00{{ ipv6_suffix }} {{ aliases | join(' ') }} +{% elif (ipv6_suffix | int) < 100 %} +2a01:e0a:ee5:8b0::d0{{ ipv6_suffix }} {{ aliases | join(' ') }} +{% else %} +2a01:e0a:ee5:8b0::d{{ ipv6_suffix }} {{ aliases | join(' ') }} +{% endif %} {% endfor %} diff --git a/templates/specific.conf.j2.disabled b/templates/specific.conf.j2.disabled new file mode 100644 index 0000000..566828f --- /dev/null +++ b/templates/specific.conf.j2.disabled @@ -0,0 +1,7 @@ +# {{ ansible_managed }} + +{% for host in group['zone_gaia'] %} +# {{ inventory_hostname }} +192.168.84.{{ proxmox_host_id }} {{ inventory_hostname }} {{ inventory_hostname_short }} {{ dnsmasq_host_aliases | join(' ') }} +2a01:cb00:131:f100::d0{{ proxmox_host_id }} {{ inventory_hostname }} {{ inventory_hostname_short }} {{ dnsmasq_host_aliases | join(' ') }} +{% endfor %}