diff --git a/defaults/main.yml b/defaults/main.yml index 4bb3e7e..5e53ecb 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -16,7 +16,7 @@ dnsmasq_client_filename: "{{ inventory_hostname }}" dnsmasq_client_hostname: "{{ inventory_hostname }} {{ inventory_hostname_short }}" # Groupe ansible pour l'enregistrement automatique -dnsmasq_ansible_group: zone_gaia +dnsmasq_ansible_group: "" # CIDR du sous-réseau IPv6 dnsmasq_ipv6_subnet: "" diff --git a/tasks/configuration.yml b/tasks/configuration.yml index 1d2f9f6..52d616d 100644 --- a/tasks/configuration.yml +++ b/tasks/configuration.yml @@ -35,19 +35,3 @@ mode: u=rw,g=r,o=r become: true notify: Reload dnsmasq.service - -- name: Deploy specific configuration - 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: Reload dnsmasq.service - loop: "{{ dnsmasq_specifics }}" - loop_control: - label: "{{ filename }}" - vars: - filename: /srv/dnsmasq/{{ item.hostname }}.conf diff --git a/tasks/main.yml b/tasks/main.yml index 689304c..fcac242 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -8,3 +8,7 @@ - name: Import configuration tasks ansible.builtin.import_tasks: file: configuration.yml + +- name: Import records deployment tasks + ansible.builtin.import_tasks: + file: records.yml diff --git a/tasks/client.yml b/tasks/records.yml similarity index 86% rename from tasks/client.yml rename to tasks/records.yml index 264d9e0..0597026 100644 --- a/tasks/client.yml +++ b/tasks/records.yml @@ -3,11 +3,11 @@ - name: Deploy records ansible.builtin.template: + src: "{{ role_path }}/templates/auto.conf.j2" + dest: /srv/dnsmasq/auto-{{ dnsmasq_ansible_group }}.conf owner: dnsmasq group: root mode: u=rw,g=r,o=r - 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 }}" diff --git a/templates/auto.conf.j2 b/templates/auto.conf.j2 index a770162..2f1ca91 100644 --- a/templates/auto.conf.j2 +++ b/templates/auto.conf.j2 @@ -1,12 +1,22 @@ # {{ ansible_managed }} -{% for host in groups[dnsmasq_ansible_group] %} +# ansible inventory +{%- for host in (groups[dnsmasq_ansible_group] | sort) %} {%- set ipv4 = hostvars[host]['ansible_host'] %} +{%- set ipv6_prefix = dnsmasq_ipv6_subnet | split('/') | first %} {%- set ipv6_suffix = hostvars[host]['ansible_host'] | split('.') | last %} -{%- set ipv6 = (dnsmasq_ipv6_subnet | split('/') | first) + ipv6_suffix %} {%- set aliases = [host] + hostvars[host].get('dnsmasq_host_aliases', []) %} -# {{ host }} +## {{ host }} {{ ipv4 }} {{ aliases | join(' ') }} -{{ ipv6 }} {{ aliases | join(' ') }} +{{ ipv6_prefix }}{{ ipv6_suffix }} {{ aliases | join(' ') }} +{% endfor %} + +# role specifics +{%- for specific in dnsmasq_specifics %} + +## {{ specific.hostname }} +{% for ip in specific.ips %} +{{ ip }} {{ specific.hostname }} +{% endfor %} {% endfor %} diff --git a/templates/specific.conf.j2 b/templates/specific.conf.j2 index f78dffa..d1022d3 100644 --- a/templates/specific.conf.j2 +++ b/templates/specific.conf.j2 @@ -1,17 +1,8 @@ # {{ ansible_managed }} +{% for specific in dnsmasq_specifics %} -{% 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 %} +# {{ specific.hostname }} +{% for ip in specific.ips %} +{{ ip }} {{ specific.hostname }} +{% endfor %} {% endfor %} diff --git a/templates/specific.conf.j2.disabled b/templates/specific.conf.j2.disabled deleted file mode 100644 index 566828f..0000000 --- a/templates/specific.conf.j2.disabled +++ /dev/null @@ -1,7 +0,0 @@ -# {{ 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 %}