pihole/tasks/main.yml
2022-08-07 13:31:59 +02:00

69 lines
No EOL
2 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: "{{ pihole_config_dir }}"
register: pihole_dir
- name: Clone the pi-hole repo
ansible.builtin.git:
repo: https://github.com/pi-hole/pi-hole.git
depth: 1
dest: "{{ pihole_download_dir }}"
version: master
when: not pihole_dir.stat.exists
- name: Set setupVars.conf
template:
src: setupVars.conf.j2
dest: "{{ pihole_config_dir }}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: "'{{ pihole_download_dir }}automated install/basic-install.sh' --unattended >> {{ ansible_env.HOME }}/pihole_install.log"
args:
warn: false
when: not pihole_dir.stat.exists
- name: Set custom dnsmasq options
template:
src: dnsmasq.conf.j2
dest: /etc/dnsmasq.d/10-custom.conf
- name: Set admin password
shell: "pihole -a -p {{ pihole_admin_password }}"
- name: Set local DNS entries
template:
src: custom.list.j2
dest: "{{ pihole_config_dir }}custom.list"
owner: root
mode: 0664
- name: Restart pihole
become: yes
shell: "pihole restartdns"