commit cb3ed889db40e9850056e0344f4b38c3ab226e4b Author: Kyattsukuro Date: Wed Oct 14 23:04:31 2026 +0200 init diff --git a/README.md b/README.md new file mode 100644 index 0000000..07d23aa --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# dns diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..3378b6b --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,9 @@ +path: /srv/{{ role_name }} + +dns_override: {} +dns_defaults: + api_key: "" + domain: "" + local_domains: [] + domain_host: "" + domain_host_v6: "" diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..5b51544 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,9 @@ +- name: restart container + community.docker.docker_compose_v2: + project_src: "{{ path }}" + project_name: "{{ role_name }}" + recreate: "always" + services: ["pihole"] + state: "restarted" + + when: _dns_already_restarted is deffined and not _dns_already_restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..7480d5e --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,17 @@ +--- +galaxy_info: + author: "Niklas Freese " + description: dns + company: "Urmel Services" + license: AGPL-3.0-or-later + min_ansible_version: 2.1 + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..a52c818 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,33 @@ +--- +- name: "set local variables from overrides and defaults" + set_fact: + dns: "{{ (dns_defaults | combine(dns_override, recursive=True)) if dns_override else dns_defaults }}" + +- name: ensure that path exists + file: + path: "{{ path }}/config/dns" + state: directory + +- name: template docker-compose + template: + src: compose.yml.j2 + dest: "{{ path }}/compose.yml" + +- name: populate dmasq + ansible.builtin.template: + src: "dmasq.conf/{{ item.path }}" + dest: "{{ path }}/config/etc-dnsmasq.d/{{ item.path | regex_replace('\\.j2$', '') }}" + with_filetree: "{{ role_path }}/templates/dmasq.conf" + when: + - item.state == "file" + notify: restart container + +- name: ensure container is running + community.docker.docker_compose_v2: + project_src: "{{ path }}" + project_name: "{{ role_name }}" + state: "present" + pull: "always" + wait: true + services: ["pihole"] + register: _compose_result diff --git a/templates/compose.yml.j2 b/templates/compose.yml.j2 new file mode 100644 index 0000000..83dca49 --- /dev/null +++ b/templates/compose.yml.j2 @@ -0,0 +1,34 @@ +--- +services: + pihole: + image: pihole/pihole:latest + ports: + - "53:53/tcp" + - "53:53/udp" + - "67:67/udp" + environment: + TZ: 'Europe/Berlin' + FTLCONF_webserver_api_password: '{{ dns.api_key }}' + FTLCONF_dns_listeningMode: 'ALL' # recomendet for docker bridge + volumes: + - './data/pihole:/etc/pihole' + - './config/etc-dnsmasq.d:/etc/dnsmasq.d' + networks: + - exposed + cap_add: + - NET_ADMIN # For DHCP + restart: unless-stopped + labels: + traefik.enable: true + + traefik.http.routers.pihole.entrypoints: https + traefik.http.routers.pihole.rule: Host(`{{ dns.domain }}`) + traefik.http.services.pihole.loadbalancer.server.port: 80 + traefik.http.routers.pihole.tls: "true" + traefik.http.routers.pihole.tls.certresolver: hetzner + traefik.http.routers.pihole.middlewares: local-only@file + +networks: + exposed: + name: traefik_exposed + external: true diff --git a/templates/dmasq.conf/02-pihole-dhcp.conf.j2 b/templates/dmasq.conf/02-pihole-dhcp.conf.j2 new file mode 100644 index 0000000..44d8961 --- /dev/null +++ b/templates/dmasq.conf/02-pihole-dhcp.conf.j2 @@ -0,0 +1 @@ +dhcp-option=6,{{ ansible_facts.default_ipv4.address }} diff --git a/templates/dmasq.conf/99-local-wildcard.conf.j2 b/templates/dmasq.conf/99-local-wildcard.conf.j2 new file mode 100644 index 0000000..b5fdfdb --- /dev/null +++ b/templates/dmasq.conf/99-local-wildcard.conf.j2 @@ -0,0 +1,5 @@ +{% for local_domain in dns.local_domains %} +address=/.{{ local_domain }}/{{ dns.domain_host | default(ansible_facts.default_ipv4.address, true) }} +address=/.{{ local_domain }}/{{ dns.domain_host_v6 | default(ansible_facts.default_ipv6.address, true) }} + +{% endfor %}