Skip to content

Commit 65a0222

Browse files
committed
Revision 1 - get Pi-hole working correctly too.
1 parent 0ec162b commit 65a0222

11 files changed

+90
-18
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
inventory.ini
2+
config.yml

Diff for: README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ TODO: Description here.
77
## Features
88

99
- **Internet Monitoring**: TODO.
10-
- **Pi Hole**: TODO.
10+
- **Pi-hole**: TODO.
1111

1212
## Setup
1313

14-
TODO.
14+
1. Install Ansible (either full version or ansible-base).
15+
2. Install requirements: `ansible-galaxy collection install -r requirements.yml`
16+
3. Make copies of the following files and customize them to your liking:
17+
- `example.inventory.ini` to `inventory.ini` (replace IP address with your Pi's IP).
18+
- `example.config.yml` to `config.yml`
19+
4. Run the playbook: `ansible-playbook main.yml`
1520

1621
## License
1722

Diff for: ansible.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[defaults]
22
nocows = True
3-
inventory = ./inventory
3+
inventory = ./inventory.ini
44
interpreter_python = auto_silent

Diff for: example.config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
pihole_hostname: pihole
3+
pihole_password: change-this-password

Diff for: inventory renamed to example.inventory.ini

File renamed without changes.

Diff for: main.yml

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
- hosts: internet_pi
33
become: true
44

5+
pre_tasks:
6+
- name: Load configuration.
7+
ansible.builtin.include_vars: config.yml
8+
9+
- name: Ensure apt cache is up to date.
10+
ansible.builtin.apt:
11+
update_cache: true
12+
cache_valid_time: 3600
13+
514
tasks:
6-
- include_tasks: tasks/docker.yml
7-
- include_tasks: tasks/internet-monitoring.yml
15+
- ansible.builtin.include_tasks: tasks/docker.yml
16+
- ansible.builtin.include_tasks: tasks/internet-monitoring.yml
17+
- ansible.builtin.include_tasks: tasks/pi-hole.yml

Diff for: requirements.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
collections:
3+
- community.docker

Diff for: tasks/docker.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
---
22
- name: Check if Docker is already present.
3-
command: which docker
3+
ansible.builtin.command: which docker
44
failed_when: false
55
changed_when: false
66
register: docker_command_result
77

88
- name: Download Docker install convenience script.
9-
get_url:
9+
ansible.builtin.get_url:
1010
url: https://get.docker.com/
1111
dest: /tmp/get-docker.sh
1212
mode: 0775
1313
when: docker_command_result.rc == 1
1414

1515
- name: Run Docker install convenience script.
16-
command: /tmp/get-docker.sh
16+
ansible.builtin.command: /tmp/get-docker.sh
1717
environment:
1818
CHANNEL: stable
1919
when: docker_command_result.rc == 1
2020

2121
- name: Ensure Docker is started.
22-
service:
22+
ansible.builtin.service:
2323
name: docker
2424
state: started
2525
enabled: true
2626

2727
- name: Ensure dependencies are installed.
28-
apt:
28+
ansible.builtin.apt:
2929
name:
3030
- libffi-dev
3131
- libssl-dev
@@ -35,13 +35,13 @@
3535
state: present
3636

3737
- name: Install Docker Compose using Pip.
38-
pip:
38+
ansible.builtin.pip:
3939
name: docker-compose
4040
state: present
4141
executable: pip3
4242

4343
- name: Ensure pi user is added to the docker group.
44-
user:
44+
ansible.builtin.user:
4545
name: pi
4646
groups: docker
4747
append: true

Diff for: tasks/internet-monitoring.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
---
22
- name: Clone internet-monitoring repo to Pi.
3-
git:
3+
ansible.builtin.git:
44
repo: https://github.com/geerlingguy/internet-monitoring
55
dest: ~/internet-monitoring/
66
version: master
77
accept_hostkey: true
88
become: false
99

10+
# TODO: The first time this playbook is run, the `pi` user may not be added
11+
# to the `docker` group, so this task may fail.
1012
- name: Ensure internet-monitoring environment is running.
11-
meta: noop
12-
13-
# git clone https://github.com/geerlingguy/internet-monitoring
14-
# cd internet-monitoring
15-
# docker-compose up -d
13+
community.docker.docker_compose:
14+
project_src: ~/internet-monitoring/
15+
build: false
16+
become: false

Diff for: tasks/pi-hole.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
- name: Create Pi-hole folder on Pi.
3+
ansible.builtin.file:
4+
path: ~/pi-hole
5+
state: directory
6+
mode: 0755
7+
become: false
8+
9+
- name: Copy Pi-hole docker-compose template to Pi.
10+
ansible.builtin.template:
11+
src: templates/pi-hole-docker-compose.yml.j2
12+
dest: ~/pi-hole/docker-compose.yml
13+
mode: '0640'
14+
become: false
15+
16+
# TODO: The first time this playbook is run, the `pi` user may not be added
17+
# to the `docker` group, so this task may fail.
18+
- name: Ensure Pi-hole is running.
19+
community.docker.docker_compose:
20+
project_src: ~/pi-hole/
21+
build: false
22+
become: false

Diff for: templates/pi-hole-docker-compose.yml.j2

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# {{ ansible_managed }}
2+
---
3+
version: "3"
4+
5+
# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
6+
services:
7+
pihole:
8+
container_name: pihole
9+
image: pihole/pihole:latest
10+
hostname: '{{ pihole_hostname }}'
11+
ports:
12+
- "53:53/tcp"
13+
- "53:53/udp"
14+
- "67:67/udp"
15+
- "80:80/tcp"
16+
- "443:443/tcp"
17+
environment:
18+
TZ: 'America/Chicago'
19+
WEBPASSWORD: '{{ pihole_password }}'
20+
ServerIP: '{{ ansible_facts['default_ipv4']['address'] }}'
21+
volumes:
22+
- './etc-pihole/:/etc/pihole/'
23+
- './etc-dnsmasq.d/:/etc/dnsmasq.d/'
24+
cap_add:
25+
- NET_ADMIN
26+
restart: unless-stopped

0 commit comments

Comments
 (0)