Skip to content

Added macvlan network to allow for pi-hole DHCP #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tasks/pi-hole.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion templates/pi-hole-docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is pihole_ipaddr being defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's defined in the config.yml I'll add it to the example file but I feel like it might need more explanation, maybe in the readme?


ports:
- "53:53/tcp"
- "53:53/udp"
Expand All @@ -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
Expand Down