lucab85.ansible_role_bind

Ansible Role: BIND

CI

This role installs and sets up a BIND9 DNS service on systems like Fedora, CentOS, RHEL 7/8, and Debian/Ubuntu. It configures the DNS service as the main server (master) or a backup server (slave) for one or more domains, with customized settings for zones and reverse lookups.

Requirements

No special needs; however, this role requires root access. You can run it in a playbook by adding become: yes globally, or specify it for the role like this:

- hosts: dns
  roles:
    - role: lucab85.ansible_role_bind
      become: yes

Role Variables

You can find the available variables and their default values in the defaults/main.yml file.

Main Configuration

Settings in bind_main_config_settings will be applied to the main configuration file—/etc/named.conf for Fedora/CentOS/RHEL or /etc/bind/named.conf for Debian/Ubuntu. The settings in bind_main_options_settings go into the options { } tag of this configuration file.

Example settings:

bind_main_options_settings:
  - option: listen-on port
    value: '53 { 127.0.0.1; 10.0.1.1; };'
  - option: allow-query
    value: '{ trusted; };'
  - option: forwarders
    value: '{ 8.8.8.8; 8.8.4.4; };'
  - option: listen-on-v6
    value: '{ any; };'
  - option: dnssec-validation
    value: 'auto;'

In this example, 10.0.1.1 is the IPv4 address of the target machine; adjust it as needed.

bind_main_config_settings:
  - option: acl "trusted"
    value: '{ 10.0.1.1; 10.0.1.2; };'

This example defines an access control list (acl) called trusted with two IPv4 addresses that could be useful for your policy. Adjust as necessary.

Example output:

#
# Ansible managed: Do NOT edit this file manually!
#
options {
    directory "/var/named";
    listen-on port 53 { 127.0.0.1; 10.0.1.1; };
    allow-query { trusted; };
    forwarders { 8.8.8.8; 8.8.4.4; };
    listen-on-v6 { any; };
    dnssec-validation auto;
};
acl "trusted" { 10.0.1.1; 10.0.1.2; };
include "/etc/named/named.conf.local";

Zone Configuration

Zone settings are defined in bind_zones_entries and applied using the template zone.j2. These settings go into the auxiliary configuration file located at /etc/named/named.conf.local for both Fedora/CentOS/RHEL and Debian/Ubuntu. The actual zone records will be stored in /var/named/[[ example.com.zone ]] for Fedora/CentOS/RHEL or /var/lib/bind/[[ example.com.zone ]] for Debian/Ubuntu.

Example:

bind_zones_entries:
  - name: "example.com"
    file: "example.com.zone"
    type: "master"
    options: "allow-update { none; };"
    ttl: 86400
    records:
      - name: "@"
        type: "SOA"
        value: "dns1.example.com. hostmaster.example.com. (2001062501 21600 3600 604800 86400)"
      - name: "@"
        type: "NS"
        value: "dns1.example.com."
      - name: "@"
        type: "NS"
        value: "dns2.example.com."
      - name: "dns1"
        type: "A"
        value: "10.0.1.1"
      - name: "dns2"

Example local output: /etc/named/named.conf.local

#
# Ansible managed: Do NOT edit this file manually!
#
zone "example.com" IN {
    type master;
    file "example.com.zone";
    allow-update { none; };
};
zone "1.0.10.in-addr.arpa" IN {
    type master;
    file "example.com.rr.zone";
    allow-update { none; };
};

Example output: /var/named/example.com.zone

$ORIGIN example.com.
$TTL 86400;
@  IN  SOA dns1.example.com. hostmaster.example.com. (2001062501 21600 3600 604800 86400)
@  IN  NS dns1.example.com.
@  IN  NS dns2.example.com.
dns1  IN  A 10.0.1.1
dns2  IN  A 10.0.1.2
@  IN  MX 10 mail1.example.com.
@  IN  MX 20 mail2.example.com.
mail1  IN  A 10.0.1.5
mail2  IN  A 10.0.1.6
services  IN  A 10.0.1.10
services  IN  A 10.0.1.11
ftp  IN  CNAME services.example.com.
www  IN  CNAME services.example.com.

Reverse Zone Configuration

You can also configure a reverse zone similarly to how you configure a standard zone.

Example:

- name: "1.0.10.in-addr.arpa"
  file: "example.com.rr.zone"
  type: "master"
  options: "allow-update { none; };"
  ttl: 86400
  records:
    - name: "@"
      type: "SOA"
      value: "dns1.example.com. hostmaster.example.com. (2001062501 21600 3600 604800 86400)"
    - name: "@"
      type: "NS"
      value: "dns1.example.com."
    - name: "@"
      type: "NS"
      value: "dns2.example.com."
    - name: "1"
      type: "PTR"
      value: "dns1.example.com."

Example output: /var/named/example.com.rr.zone

$ORIGIN 1.0.10.in-addr.arpa.
$TTL 86400;
@  IN  SOA dns1.example.com. hostmaster.example.com. (2001062501 21600 3600 604800 86400)
@  IN  NS dns1.example.com.
@  IN  NS dns2.example.com.
1  IN  PTR dns1.example.com.
2  IN  PTR dns2.example.com.
5  IN  PTR mail1.example.com.
6  IN  PTR mail2.example.com.
10 IN  PTR services.example.com.
11 IN  PTR services.example.com.

For specific record definitions, refer to BIND documentation.

Dependencies

None.

Example Playbook

- hosts: dns
  become: yes
  vars_files:
    - vars/main.yml
  roles:
    - lucab85.ansible_role_bind

Make changes to variables in vars/main.yml:

bind_zones_entries:
  - name: "example.com"
    file: "example.com.zone"
    type: "master"
    options: "allow-update { none; };"
    ttl: 86400
    records:
      - name: "@"
        type: "SOA"
        value: "dns1.example.com. hostmaster.example.com. (2001062501 21600 3600 604800 86400)"
      - name: "@"
        type: "NS"
        value: "dns1.example.com."
      - name: "@"
        type: "NS"
        value: "dns2.example.com."
      - name: "dns1"
        type: "A"
        value: "10.0.1.1"
      - name: "dns2"

License

MIT / BSD

Author Information

This role was created in 2021 by Luca Berton, the author of Ansible Pilot.

Ansible Pilot

For more information, visit:

Thank you for your support:

Informazioni sul progetto

Setup a BIND9 DNS service on Fedora/Centos/RHEL7/8 and Debian/Ubuntu target as authoritative for one or more domains (master and/or slave) with customized zone and reverse.

Installa
ansible-galaxy install lucab85.ansible_role_bind
Licenza
mit
Download
311
Proprietario
Ansible Automation Engineer with Open Source passion: (Ansible, Progressive Web Applications, Cloud Computing, IoT, GNU/Linux)