diff --git a/example.config.yml b/example.config.yml index f9907efb..5f18e09f 100644 --- a/example.config.yml +++ b/example.config.yml @@ -2,6 +2,8 @@ pihole_hostname: pihole pihole_password: change-this-password +pihole_ipaddr: 192.168.1.245 # Ip you want pi-hole container (not the pi itself) to have on your LAN + shelly_plug_enable: false shelly_plug_hostname: my-shelly-plug-host-or-ip shelly_plug_http_username: username diff --git a/tasks/pi-hole.yml b/tasks/pi-hole.yml index c709a14f..1a3f7e38 100644 --- a/tasks/pi-hole.yml +++ b/tasks/pi-hole.yml @@ -6,6 +6,12 @@ mode: 0755 become: false +- name: Get CIDR notation of subnet + set_fact: + mask_cidr: "{{ ip | ipaddr('prefix') }}" + vars: + ip: "{{ ansible_facts['default_ipv4']['address'] }}/{{ ansible_facts['default_ipv4']['netmask'] }}" + - name: Copy Pi-hole docker-compose template to Pi. ansible.builtin.template: src: templates/pi-hole-docker-compose.yml.j2 diff --git a/templates/pi-hole-docker-compose.yml.j2 b/templates/pi-hole-docker-compose.yml.j2 index ae4f42e2..8613f41a 100644 --- a/templates/pi-hole-docker-compose.yml.j2 +++ b/templates/pi-hole-docker-compose.yml.j2 @@ -2,12 +2,29 @@ --- version: "3" +# For DHCP to function pi-hole needs to be able to see/send broadcasts +# More info at https://docs.pi-hole.net/docker/DHCP/ and +# http://tonylawrence.com/posts/unix/synology/free-your-synology-ports/ +networks: + pihole_network: + driver: macvlan + driver_opts: + parent: eth0 + ipam: + config: + - subnet: '{{ ansible_facts['default_ipv4']['address'] }}/{{ mask_cidr }}' + gateway: '{{ ansible_facts['default_ipv4']['gateway'] }}' + # More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/ services: pihole: container_name: pihole image: pihole/pihole:latest hostname: '{{ pihole_hostname }}' + networks: + pihole_network: + ipv4_address: '{{ pihole_ipaddr }}' + ports: - "53:53/tcp" - "53:53/udp" @@ -17,7 +34,7 @@ services: environment: TZ: 'America/Chicago' WEBPASSWORD: '{{ pihole_password }}' - ServerIP: '{{ ansible_facts['default_ipv4']['address'] }}' + ServerIP: '{{ pihole_ipaddr }}' dns: - 127.0.0.1 - 8.8.8.8