From 889bc61b6ca572e1f3718d8b1723248c73e747e4 Mon Sep 17 00:00:00 2001 From: Ahmed Abdelhalim Date: Tue, 23 Sep 2025 12:41:14 +0200 Subject: Use static values for defaults instead of ansible vars The ansible vars fail on CI because the validate arguments task runs way before the setting of the variables, which causes the ansible undefined vars on CI to cause errors. This is a way better approach of having the static values as defaults and allowing setting the variables to ansible vars in the host/group vars --- roles/pihole/defaults/main.yml | 5 +---- roles/pihole/meta/argument_specs.yml | 5 +---- roles/pihole/tasks/main.yml | 11 +++++++++++ 3 files changed, 13 insertions(+), 8 deletions(-) (limited to 'roles/pihole') diff --git a/roles/pihole/defaults/main.yml b/roles/pihole/defaults/main.yml index f5a5047c..4e1d0bf7 100644 --- a/roles/pihole/defaults/main.yml +++ b/roles/pihole/defaults/main.yml @@ -8,12 +8,9 @@ pihole_dns: # Google - "8.8.8.8" - "2001:4860:4860:0:0:0:0:8888" -pihole_interface: "{{ ansible_default_ipv4.interface }}" +pihole_interface: "eth0" pihole_dns_blocking_enabled: true pihole_dhcp_enabled: false -pihole_dhcp_start: "{{ ansible_default_ipv4.network | regex_replace('\\.0$', '.100') }}" -pihole_dhcp_end: "{{ ansible_default_ipv4.network | regex_replace('\\.0$', '.199') }}" -pihole_dhcp_router: "{{ ansible_default_ipv4.address }}" pihole_dhcp_lease_time: "" pihole_dhcp_domain: "local" pihole_dhcp_hosts: [] diff --git a/roles/pihole/meta/argument_specs.yml b/roles/pihole/meta/argument_specs.yml index e6ba264e..9b71f48b 100644 --- a/roles/pihole/meta/argument_specs.yml +++ b/roles/pihole/meta/argument_specs.yml @@ -26,7 +26,7 @@ argument_specs: pihole_interface: type: "str" description: "The interface to bind the pi-hole on" - default: "{{ ansible_default_ipv4.interface }}" + default: "eth0" pihole_dns_blocking_enabled: type: "bool" description: "The boolean flag to toggle DNS blocking" @@ -38,15 +38,12 @@ argument_specs: pihole_dhcp_start: type: "str" description: "The dhcp start address" - default: "{{ ansible_default_ipv4.network }}.100" pihole_dhcp_end: type: "str" description: "The dhcp end address" - default: "{{ ansible_default_ipv4.network }}.199" pihole_dhcp_router: type: "str" description: "The dhcp server router (gateway) address" - default: "{{ ansible_default_ipv4.address }}" pihole_dhcp_lease_time: type: "str" description: "The dhcp lease time string ex. ('45m', '1h', '2d', '1w') empty defaults to dnsmasq default" diff --git a/roles/pihole/tasks/main.yml b/roles/pihole/tasks/main.yml index 7e0e7697..6556a7ce 100644 --- a/roles/pihole/tasks/main.yml +++ b/roles/pihole/tasks/main.yml @@ -4,6 +4,17 @@ msg: "Pihole role cannot work when network_ipv4_dns or network_ipv6_dns are defined" when: network_ipv4_dns is defined or network_ipv6_dns is defined +- name: "Validate pihole_dhcp_* params" + ansible.builtin.assert: + that: + - pihole_dhcp_start is defined + - pihole_dhcp_end is defined + - pihole_dhcp_router is defined + - pihole_dhcp_lease_time is defined + - pihole_dhcp_domain is defined + - pihole_dhcp_hosts is defined + when: pihole_dhcp_enabled + - name: "Crete Pi-hole user" ansible.builtin.user: name: "pihole" -- cgit v1.2.3