From c4bdaa0e57fd3cd3bfd253cc5b90ac8d820917a6 Mon Sep 17 00:00:00 2001 From: directlx Date: Wed, 4 Feb 2026 09:01:35 -0500 Subject: [PATCH] Add Pi-hole DNS management playbook - playbooks/pihole-dns.yml: Configure local DNS records - templates/pihole-custom-list.j2: DNS records template Domain: lab.directlx.dev Records for all infrastructure hosts with short and FQDN names. Usage: ansible-playbook playbooks/pihole-dns.yml Co-Authored-By: Claude Opus 4.5 --- playbooks/pihole-dns.yml | 37 +++++++++++++++++++++++++++++++++ templates/.gitkeep | 0 templates/pihole-custom-list.j2 | 7 +++++++ 3 files changed, 44 insertions(+) create mode 100644 playbooks/pihole-dns.yml delete mode 100644 templates/.gitkeep create mode 100644 templates/pihole-custom-list.j2 diff --git a/playbooks/pihole-dns.yml b/playbooks/pihole-dns.yml new file mode 100644 index 0000000..06eb790 --- /dev/null +++ b/playbooks/pihole-dns.yml @@ -0,0 +1,37 @@ +--- +- name: Configure Pi-hole local DNS records + hosts: pihole + vars: + dns_domain: lab.directlx.dev + dns_records: + - { ip: "192.168.200.106", hostname: "ansible-node" } + - { ip: "192.168.200.10", hostname: "proxmox-00" } + - { ip: "192.168.200.11", hostname: "proxmox-01" } + - { ip: "192.168.200.12", hostname: "proxmox-02" } + - { ip: "192.168.200.103", hostname: "postgres" } + - { ip: "192.168.200.110", hostname: "mysql" } + - { ip: "192.168.200.111", hostname: "mongo" } + - { ip: "192.168.200.65", hostname: "nginx" } + - { ip: "192.168.200.71", hostname: "npm" } + - { ip: "192.168.200.200", hostname: "docker" } + - { ip: "192.168.200.100", hostname: "pihole" } + - { ip: "192.168.200.102", hostname: "gitea" } + - { ip: "192.168.200.91", hostname: "jenkins" } + - { ip: "192.168.200.112", hostname: "hiveops" } + - { ip: "192.168.200.114", hostname: "smartjournal" } + - { ip: "192.168.200.61", hostname: "odoo" } + + tasks: + - name: Create Pi-hole custom DNS records + ansible.builtin.template: + src: ../templates/pihole-custom-list.j2 + dest: /etc/pihole/custom.list + owner: root + group: root + mode: '0644' + notify: Restart pihole dns + + handlers: + - name: Restart pihole dns + ansible.builtin.command: pihole restartdns + changed_when: true diff --git a/templates/.gitkeep b/templates/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/templates/pihole-custom-list.j2 b/templates/pihole-custom-list.j2 new file mode 100644 index 0000000..5a572fd --- /dev/null +++ b/templates/pihole-custom-list.j2 @@ -0,0 +1,7 @@ +# Pi-hole local DNS records +# Managed by Ansible - do not edit manually +# Domain: {{ dns_domain }} + +{% for record in dns_records %} +{{ record.ip }} {{ record.hostname }}.{{ dns_domain }} {{ record.hostname }} +{% endfor %}