robertdebock.dns

Ansible 角色 dns

在您的系统上安装和配置 DNS。

GitHub GitLab 下载 版本
github gitlab downloads 版本

示例剧本

这个示例来自 molecule/default/converge.yml,并在每次推送、拉取请求和发布时进行了测试。

---
- 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"

机器需要做好准备。在 CI 中,通过 molecule/default/prepare.yml 来完成这个准备工作:

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

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

有关如何使用这些角色的 完整说明和示例

角色变量

变量的默认值设置在 defaults/main.yml 中:

---
# dns 的默认文件

# 监听的端口。
dns_port: 53

# DNS 服务器是否应该是缓存 DNS 服务器?
dns_caching_dns: true

# 每个区域的区域和属性列表。
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.

# 一个可选的用于允许递归的 acl 列表。("any" 和 "none" 始终可用。)
dns_allow_recursion:
  - none

# 一个可选的用于指定 DNS 服务器监听的 IPv4 列表。("any" 和 "none" 始终可用。)
dns_listen_on:
  - any

# 一个可选的用于指定 DNS 服务器监听的 IPv6 列表。("any" 和 "none" 始终可用。)
dns_listen_on_v6:
  - any

# 一个可选的允许查询该服务器的 IP 列表。("any" 和 "none" 始终可用。)
# 默认值: "any"
# dns_allow_query:
#  - any
#  - "127.0.0.1"

# 一个可选的允许运行 AXFR 查询的 IP 列表。("any" 和 "none" 始终可用。)
# 默认值: "none"
# dns_allow_transfer:
#   - none
#   - "172.16.0.1"

# 一个可选的设置,用于配置将创建 pid 文件的路径。
dns_pid_file: /run/named/named.pid

# 一个可选的设置,用于将流量转发到其他 DNS 服务器。
# dns_forwarders:
#   - "1.1.1.1"
#   - "8.8.8.8"

要求

已使用角色的状态

以下角色用于准备系统。您可以通过其他方式准备您的系统。

要求 GitHub GitLab
robertdebock.bootstrap Build Status GitHub Build Status GitLab
robertdebock.core_dependencies Build Status GitHub Build Status GitLab

上下文

此角色是许多兼容角色的一部分。有关更多信息,请查看 这些角色的文档

这是相关角色的概述: 依赖关系

兼容性

此角色已在这些 容器镜像 上进行测试:

容器 标签
Alpine 所有
Amazon 候选版
EL 9
Debian 所有
Fedora 所有
Ubuntu 所有

所需的 Ansible 最低版本为 2.12,已对以下版本进行了测试:

  • 先前版本。
  • 当前版本。
  • 开发版本。

如果您发现问题,请在 GitHub 注册。

许可证

Apache-2.0

作者信息

robertdebock

请考虑 赞助我

关于项目

Install and configure dns on your system.

安装
ansible-galaxy install robertdebock.dns
许可证
apache-2.0
下载
1.2k
拥有者
I know my way around (Linux) infrastructure, have a passion for automation, Docker, Ansible, Molecule and ci/cd.