Files
Kamino/roles/pihole/tasks/install.yml
T
Defame1297 d84fb4a2f4 fix(pihole): address review findings
Remove the pihole_force_install input, which had no effect, and the dead
term of the install condition. Tag the merge and the configuration
directory check always, so --skip-tags config-only no longer skips facts
that later tasks read. Skip the installer log under --check, where the
installer did not run. Read the env and user_id facts through
ansible_facts, drop a redundant default, state the real reasons two
defaults stay out of the argument spec, and bring the README to the
fixed heading set.

Assisted-by: Claude Code:claude-opus-5-5
2026-11-25 18:53:21 +00:00

78 lines
3.5 KiB
YAML

---
# Here I use "dependencies" in a loosely defined fashion
# most of these packages would already be expected to be installed on any Ubuntu system
# but, does not hurt to be thorough
- name: Install dependencies (apt packages)
become: true
ansible.builtin.apt:
name: "{{ pihole_apt_dependencies }}"
state: present
# https://github.com/gsemet/ansible-rpi-pihole/blob/master/roles/pi/tasks/main.yml
# https://gist.github.com/bendews/e09edfc60e581ec4c686c4b70297f543
# https://github.com/Freekers/automated-pihole/blob/master/playbook.yml
# After reading up a little, it seems clear that the regular Pi-Hole
# install script will not work with Ansible by default.
# And in several places, I've seen the pihole devs state thay they don't intend
# to support Ansible playbooks. Fair enough. I've found suggested work-arounds:
# https://github.com/drew-kun/ansible-pihole/blob/master/tasks/install.yml
# https://discourse.pi-hole.net/t/automated-installation-enhancements-and-fixes/28746
# https://github.com/pi-hole/pi-hole/pull/3195
- name: "Clone the Pi-Hole repo"
ansible.builtin.git:
repo: "{{ __pihole_effective.repo.remote }}"
dest: "{{ __pihole_effective.repo.path }}"
version: "{{ __pihole_version }}"
become: true
become_user: "{{ ansible_facts['user_id'] }}"
# what happens if we run the install script with a pre-existing pihole on the system?
# is it overwritten without complaints from the installer?
# what if the repo has an older version than the installed pihole?
# would it perhaps by easiest to never allow install script to run if pihole is already installed?
# on my machine the install script produced a never-ending output of "y" lines immediately after
# successfully restarting the pihole-FTL service (if output was printed to file it quickly
# filled the available disk space). Did this happen because Pi-Hole was already installed?
# Only on a first install: on an installed Pi-hole the role leaves upgrades alone.
- name: Run Pi-Hole installation script in unattended mode
when: not (__pihole_installed | bool)
block:
# the unattended install only works if pihole.toml already exists (configure.yml)
# debug tip: keep track of the install progress by tailing the log-file on the host in question
- name: Run Pi-Hole installation script
become: true
ansible.builtin.shell: >
{{ pihole_install_script }} --unattended >>
{{ __pihole_effective.repo.path }}/pihole_install.log
changed_when: true
# can we create a task that tails -f the log file and then quits (continues to next task)
# once no new tail output for X seconds?
# https://stackoverflow.com/questions/33663357/how-to-continuously-tail-remote-files-using-ansible
# https://github.com/ansible/ansible/issues/4870
# https://github.com/ansible/ansible/issues/3887
# https://github.com/ansible/proposals/issues/92
# Perhaps in lieu of tailing we could simply print pihole_install.log in the next task?
- name: Ingest the Pi-Hole install log file
ansible.builtin.slurp:
src: "{{ __pihole_effective.repo.path }}/pihole_install.log"
register: __pihole_install_log
# under --check the installer was skipped, so there is no log to read
when:
- pihole_testing | bool
- not ansible_check_mode
# https://www.shellhacks.com/ansible-cat-file-print-read-file-content
- name: Display the install log
ansible.builtin.debug:
msg: "{{ __pihole_install_log.content | b64decode }}"
when:
- pihole_testing | bool
- not ansible_check_mode
# END OF BLOCK