ansible-pihole/tasks/main.yml

55 lines
1.6 KiB
YAML
Raw Normal View History

2020-07-04 14:17:17 +00:00
---
2020-07-04 18:29:43 +00:00
# tasks file for ansible-pihole
2020-07-05 10:12:10 +00:00
- name: Stop bind service
service:
name: named
state: stopped
enabled: no
failed_when: no
2020-07-05 13:13:22 +00:00
become: yes
2020-07-05 10:12:10 +00:00
2020-07-05 10:11:55 +00:00
- name: "Set the __docker_pihole_admin_password fact"
set_fact:
__docker_pihole_random_password: "{{ lookup('password', '/dev/null chars=ascii_letters,digits') }}"
__docker_pihole_admin_password: "{{ pihole_admin_password | default(__docker_pihole_random_password) }}"
2020-07-04 18:29:43 +00:00
2020-11-28 15:17:16 +00:00
- name: update image if needed
docker_image:
2021-01-05 19:36:01 +00:00
name: "{{ pihole_image_name }}"
2020-11-28 15:17:16 +00:00
force: yes
when: pihole_update_container == True
2020-07-05 10:11:55 +00:00
- name: "[docker] Setup the pi-hole docker container"
docker_container:
name: "{{ pihole_container_name }}"
image: "{{ pihole_image_name }}"
state: started
restart: yes
restart_policy: 'unless-stopped'
volumes: "{{ pihole_volumes }}"
published_ports: "{{ pihole_port }}"
env:
TZ: "{{pihole_timezone }}"
WEBPASSWORD: "{{ __docker_pihole_admin_password }}"
DNS1: "{{pihole_forwarder1}}"
DNS2: "{{pihole_forwarder2}}"
capabilities:
2020-07-04 18:29:43 +00:00
- NET_ADMIN
2020-07-05 10:11:55 +00:00
dns_servers: "{{ pihole_dns_servers }}"
2020-07-05 10:12:10 +00:00
become: yes
2020-07-05 10:11:55 +00:00
2020-11-28 15:17:16 +00:00
- name: cleanup old image
docker_prune:
images: yes
when: pihole_update_container == True
2020-07-05 10:11:55 +00:00
- name: "add custom dnsmask file"
template:
2020-07-05 10:12:10 +00:00
dest: "{{pihole_host_dir_dnsmasqd}}/02-localresolver.conf" # required. Location to render the template to on the remote machine.
2020-07-05 10:11:55 +00:00
src: 02-localresolver.conf.j2 # required. Path of a Jinja2 formatted template on the Ansible controller. This can be a relative or absolute path.
when: pihole_local_resolver is defined
notify: restart pihole container
2020-07-05 10:12:10 +00:00
become: yes