pihole/tasks/main.yml

84 lines
2.3 KiB
YAML
Raw Permalink Normal View History

2022-07-13 12:52:43 +02:00
---
- 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 }}"
2023-09-13 10:45:36 +02:00
- name: Install unbound DNS resolver
apt:
name: unbound
state: latest
- name: Set unbound config file
template:
src: unbound.conf.j2
dest: /etc/unbound/unbound.conf.d/default.conf
- name: Restart unbound
service:
name: unbound
state: restarted
2022-07-13 12:52:43 +02:00
- name: Check whether pi-hole is installed
stat:
2022-07-13 20:14:18 +02:00
path: "{{ pihole_config_dir }}"
2022-07-13 12:52:43 +02:00
register: pihole_dir
- name: Clone the pi-hole repo
ansible.builtin.git:
repo: https://github.com/pi-hole/pi-hole.git
depth: 1
2022-07-13 20:14:18 +02:00
dest: "{{ pihole_download_dir }}"
2022-07-13 12:52:43 +02:00
version: master
when: not pihole_dir.stat.exists
2022-07-13 20:14:18 +02:00
- name: Set setupVars.conf
2022-07-13 12:52:43 +02:00
template:
src: setupVars.conf.j2
2022-07-13 20:14:18 +02:00
dest: "{{ pihole_config_dir }}setupVars.conf"
2022-07-13 12:52:43 +02:00
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
2022-07-13 20:14:18 +02:00
ansible.builtin.shell: "'{{ pihole_download_dir }}automated install/basic-install.sh' --unattended >> {{ ansible_env.HOME }}/pihole_install.log"
2022-07-13 12:52:43 +02:00
args:
warn: false
when: not pihole_dir.stat.exists
2022-08-07 13:31:59 +02:00
- name: Set custom dnsmasq options
template:
src: dnsmasq.conf.j2
dest: /etc/dnsmasq.d/10-custom.conf
2022-07-13 12:52:43 +02:00
- name: Set admin password
shell: "pihole -a -p {{ pihole_admin_password }}"
- name: Set local DNS entries
template:
src: custom.list.j2
2022-07-13 20:14:18 +02:00
dest: "{{ pihole_config_dir }}custom.list"
2022-07-13 12:52:43 +02:00
owner: root
mode: 0664
- name: Restart pihole
become: yes
shell: "pihole restartdns"