Skip to content

robertdebock/ansible-role-dns

Install and configure dns on your system.

GitHub GitLab Downloads Version
github gitlab downloads Version

This example is taken from molecule/default/converge.yml and is tested on each push, pull request and release.

---
- name: Converge
  hosts: all
  become: true
  gather_facts: true

  roles:
    - role: robertdebock.dns
      dns_allow_transfer:
        - none
        - "127.0.0.1"
      dns_zones:
        - name: localhost
          type: primary
          soa: localhost
          serial: 1
          refresh: 604800
          retry: 86400
          expire: 2419200
          ttl: 604800
          records:
            - name: "@"
              type: NS
              value: localhost.
            - name: "@"
              value: "127.0.0.1"
            - name: "@"
              type: AAAA
              value: "::1"
        - name: "127.in-addr.arpa"
          ttl: 604800
          type: primary
          records:
            - name: "@"
              type: NS
              value: localhost.
            - name: "1.0.0"
              type: PTR
              value: localhost.
        - name: "0.in-addr.arpa"
          type: primary
          records:
            - name: "@"
              type: NS
              value: localhost.

        - name: "255.in-addr.arpa"
          type: primary
          records:
            - name: "@"
              type: NS
              value: localhost.
        - name: example.com
          type: primary
          ttl: 604800
          ns:
            - name: dns1.example.com.
            - name: dns2.example.com.
          mx:
            - name: mail1.example.com.
              priority: 10
            - name: mail2.example.com.
              priority: 20
          records:
            - name: dns1
              value: "127.0.0.1"
            - name: dns2
              value: "127.0.0.1"
            - name: www
              value: "127.0.0.1"
            - name: dns1
              value: "127.0.0.1"
            - name: dns2
              value: "127.0.0.1"
            - name: mail1
              value: "127.0.0.1"
            - name: mail2
              value: "127.0.0.1"
        - name: forwarded.example.com
          type: forward
          forwarders:
            - "1.1.1.1"
            - "8.8.8.8"
        - name: secondary.example.com
          type: secondary
          primaries:
            - "127.0.0.1"
            - "127.0.0.2"
        - name: lab.controlplane.info
          type: primary
          ttl: 600
          ns:
            - name: ns.lab.controlplane.info.
          mx:
            - name: mail1.lab.controlplane.info.
              priority: 10
            - name: mail2.lab.controlplane.info.
              priority: 20
          records:
            - name: ns
              value: "192.168.254.27"
            - name: git
              value: "192.168.254.19"
            - name: dl380
              value: "192.168.254.27"
            - name: mail1
              value: "192.168.123.123"
            - name: mail2
              value: "192.168.123.123"
        - name: forwarded.lab.controlplane.info
          type: forward
          ns:
            - name: forwarded.lab.controlplane.info.
          records:
            - name: ns
              value: "192.168.254.27"
            - name: "@"
              value: "192.168.123.123"
          forwarders:
            - "9.9.9.9"
            - "8.8.8.8"

The machine needs to be prepared. In CI this is done using molecule/default/prepare.yml:

---
- name: Prepare
  hosts: all
  become: true
  gather_facts: false

  roles:
    - role: robertdebock.bootstrap
    - role: robertdebock.core_dependencies

Also see a full explanation and example on how to use these roles.

The default values for the variables are set in defaults/main.yml:

---
# defaults file for dns

# The port to listen on.
dns_port: 53

# Should the DNS server be a caching DNS server?
dns_caching_dns: true

# A list of zones and properties per zone.
dns_zones:
  - name: localhost
    type: primary
    soa: localhost
    serial: 1
    refresh: 604800
    retry: 86400
    expire: 2419200
    ttl: 604800
    records:
      - name: "@"
        type: NS
        value: localhost.
      - name: "@"
        value: "127.0.0.1"
      - name: "@"
        type: AAAA
        value: "::1"
  - name: "127.in-addr.arpa"
    ttl: 604800
    type: primary
    records:
      - name: "@"
        type: NS
        value: localhost.
      - name: "1.0.0"
        type: PTR
        value: localhost.
  - name: "0.in-addr.arpa"
    type: primary
    records:
      - name: "@"
        type: NS
        value: localhost.
  - name: "255.in-addr.arpa"
    type: primary
    records:
      - name: "@"
        type: NS
        value: localhost.

# An optional list of acls to allow recursion. ("any" and "none" are always available.)
dns_allow_recursion:
  - none

# An optional list of IPv4 on which the DNS server will listen. ("any" and "none" are always available.)
dns_listen_on:
  - any

# A optional list of IPv6 on which the DNS server will listen. ("any" and "none" are always available.)
dns_listen_on_v6:
  - any

# An optional list of IP which are allowed to query the server. ("any" and "none" are always available.)
# Default: "any"
# dns_allow_query:
#  - any
#  - "127.0.0.1"

# An optional list of IP which are allowed to run a AXFR query. ("any" and "none" are always available.)
# Default: "none"
# dns_allow_transfer:
#   - none
#   - "172.16.0.1"

# An optional setting to configure the path where the pid file will be created.
dns_pid_file: /run/named/named.pid

# An optional setting to forward traffic to other DNS servers.
# dns_forwarders:
#   - "1.1.1.1"
#   - "8.8.8.8"

The following roles are used to prepare a system. You can prepare your system in another way.

Requirement GitHub GitLab
robertdebock.bootstrap Build Status GitHub Build Status GitLab
robertdebock.core_dependencies Build Status GitHub Build Status GitLab

This role is part of many compatible roles. Have a look at the documentation of these roles for further information.

Here is an overview of related roles: dependencies

This role has been tested on these container images:

container tags
Alpine all
EL 9
Debian all
Fedora all
Ubuntu all

The minimum version of Ansible required is 2.12, tests have been done on:

  • The previous version.
  • The current version.
  • The development version.

If you find issues, please register them on GitHub.

Apache-2.0.

robertdebock

Please consider sponsoring me.

About

Install and configure dns on your system.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages