diff --git a/tasks/configuration.yml b/tasks/configuration.yml index 52d616d..60a754f 100644 --- a/tasks/configuration.yml +++ b/tasks/configuration.yml @@ -26,12 +26,13 @@ become: true notify: Reload dnsmasq.service -- name: Deploy local host configuration +- name: Deploy specific records ansible.builtin.template: - src: host.conf.j2 - dest: /srv/dnsmasq/{{ inventory_hostname }}.conf + src: "{{ role_path }}/templates/records_specific.conf.j2" + dest: /srv/dnsmasq/specific.conf owner: dnsmasq group: root mode: u=rw,g=r,o=r + when: dnsmasq_specifics | length > 0 become: true notify: Reload dnsmasq.service diff --git a/tasks/records.yml b/tasks/records.yml index 2bdee35..4c9b3a3 100644 --- a/tasks/records.yml +++ b/tasks/records.yml @@ -1,9 +1,9 @@ --- # tasks file for security -- name: Deploy records +- name: Deploy records from ansible inventory ansible.builtin.template: - src: "{{ role_path }}/templates/auto.conf.j2" + src: "{{ role_path }}/templates/records_auto.conf.j2" dest: /srv/dnsmasq/auto-{{ dnsmasq_ansible_group }}.conf owner: dnsmasq group: root diff --git a/templates/host.conf.j2 b/templates/host.conf.j2 deleted file mode 100644 index fd2579d..0000000 --- a/templates/host.conf.j2 +++ /dev/null @@ -1,5 +0,0 @@ -# {{ ansible_managed }} - -{% for ip in dnsmasq_host_ips %} -{{ ip }} {{ dnsmasq_client_hostname }} {{ dnsmasq_host_aliases | join(' ') }} -{% endfor %} diff --git a/templates/auto.conf.j2 b/templates/records_auto.conf.j2 similarity index 56% rename from templates/auto.conf.j2 rename to templates/records_auto.conf.j2 index c8a0b03..1e3a302 100644 --- a/templates/auto.conf.j2 +++ b/templates/records_auto.conf.j2 @@ -1,8 +1,6 @@ # {{ ansible_managed }} -# ansible inventory -{%- set hosts = groups[dnsmasq_ansible_group] | reject('equalto', inventory_hostname) | sort %} -{%- for host in hosts %} +{%- 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 %} @@ -12,12 +10,3 @@ {{ ipv4 }} {{ 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/records_specific.conf.j2 b/templates/records_specific.conf.j2 new file mode 100644 index 0000000..377737f --- /dev/null +++ b/templates/records_specific.conf.j2 @@ -0,0 +1,9 @@ +# {{ ansible_managed }} + +{%- for specific in dnsmasq_specifics %} + +## {{ specific.hostname }} +{% for ip in specific.ips %} +{{ ip }} {{ specific.hostname }} +{% endfor %} +{% endfor %}