pihole/tasks/main.yml
2022-07-13 12:52:43 +02:00

65 lines
No EOL
1.8 KiB
YAML

---
- name: Set OS dependent variables
ansible.builtin.include_vars: "{{ lookup('first_found', params) }}"
vars:
params:
files:
- "{{ ansible_distribution | lower }}_{{ ansible_distribution_version | lower }}.yml"
- "{{ ansible_distribution | lower }}_{{ ansible_distribution_major_version | lower }}.yml"
- "{{ ansible_distribution | lower }}.yml"
- "{{ ansible_os_family | lower }}.yml"
- "{{ ansible_system | lower }}.yml"
paths:
- '{{ role_path }}/vars'
ignore_errors: True
- name: OS is supported
ansible.builtin.assert:
that: __os_supported
quiet: True
vars:
__os_supported: "{{ lookup('vars', '{}_os_supported'.format(role_name)) | bool }}"
- name: Check whether pi-hole is installed
stat:
path: /etc/pihole
register: pihole_dir
- name: Clone the pi-hole repo
ansible.builtin.git:
repo: https://github.com/pi-hole/pi-hole.git
depth: 1
dest: "/var/pi-hole"
version: master
when: not pihole_dir.stat.exists
- name: Set /etc/pihole/setupVars.conf
template:
src: setupVars.conf.j2
dest: /etc/pihole/setupVars.conf
owner: root
mode: 0400
when: not pihole_dir.stat.exists
# pihole unattented install only works if /etc/pihole/setupVars.conf already exists
# debug tip: keep track of the install progress by tailing the log-file
- name: Run pi-hole install script
ansible.builtin.shell: "'/var/pi-hole/automated install/basic-install.sh' --unattended >> {{ ansible_env.HOME }}/pihole_install.log"
args:
warn: false
when: not pihole_dir.stat.exists
- name: Set admin password
shell: "pihole -a -p {{ pihole_admin_password }}"
- name: Set local DNS entries
template:
src: custom.list.j2
dest: /etc/pihole/custom.list
owner: root
mode: 0664
- name: Restart pihole
become: yes
shell: "pihole restartdns"