publicarray.unbound
Ansible-Role-Unbound
高度可配置的 Ansible 角色,用于 Unbound DNS 解析器
- Ansible 2.2 及以上版本
- 兼容使用 systemd 作为初始化系统的操作系统。最新版本的 Ubuntu/Debian,RHEL/CentOS 6.x 和 FreeBSD
目录
安装
$ ansible-galaxy install publicarray.unbound
示例和常见用例
请查看维基: 示例
依赖项
Ansible 2.2 及以上版本
要求
无
角色变量
以下是此角色的默认变量列表。它们也可以在 defaults/main.yml
中找到。我建议您将以下变量复制并粘贴到您的 group_vars/all/configs
文件中,并查阅 Unbound 的文档: https://unbound.net/documentation/unbound.conf.html
---
# 是否从源代码编译 unbound,或使用包管理器。
unbound_compile: false
# 要从 <https://nlnetlabs.nl/projects/unbound/download/> 下载的 unbound 版本
unbound_compile_version: 1.8.0
# 用于比较下载文件的校验和 <https://nlnetlabs.nl/projects/unbound/download/>
unbound_compile_sha256: 78f79d6d3b643fdcd74a14fc76542250da886c82f82bc55b51e189663d61b83f
# 传递给 `./configure` 命令的参数。 <!--Solaris 用户应使用 --with-solaris-threads -->
unbound_compile_config: "--enable-dnscrypt --with-username={{unbound.server.username|default(unbound)}} --with-libevent --with-run-dir={{unbound.server.directory}} --with-conf-file={{unbound.server.directory}}/unbound.conf"
# 是否使用 <http://unbound.nlnetlabs.nl/documentation/howto_optimise.html> 的优化指南
unbound_optimise: false
# 为 unbound 使用的物理内存百分比。仅在 `unbound_optimise` 为 true 时使用
unbound_optimise_memory: 100
## DNS-over-TLS 设置
# 参考 <https://github.com/publicarray/ansible-role-unbound/wiki/Examples#dns-over-tls> 查找示例
# 证书签名请求的通用名称
unbound_tls_domain: example.com
# 证书生成方式。必须为 selfsigned 或 acme 之一。
# 'acme-cf' 选项(使用 dehydrated 实现)已被弃用,推荐使用新 'acme' 选项(使用 acme.sh 实现)
unbound_tls_cert_provider: selfsigned
## acme.sh 选项 https://github.com/Neilpang/acme.sh/wiki/Options-and-Params
# 自动更新 acme.sh 脚本的选项,0 = false,1 = true
unbound_tls_acme_auto_upgrade: 0
# 证书颁发机构。默认是 Let's Encrypt API v1,v2 将于 2018 年 2 月 27 日推出 (--server)
# https://community.letsencrypt.org/t/staging-endpoint-for-acme-v2/49605
# - https://acme-v02.api.letsencrypt.org/directory
unbound_tls_acme_ca: https://acme-v01.api.letsencrypt.org/directory
# 使用临时服务器进行测试 (--staging, --test)
# https://letsencrypt.org/docs/staging-environment/
# 注意:从临时环境切换到生产环境时,需要将 'unbound_tls_acme_force' 设置为 true。
unbound_tls_acme_staging: false
# 强制创建证书(忽略到期日期)
unbound_tls_acme_force: false
# 域名验证模式。可用模式有 standalone, stateless, tls, apache, dns [dns_cf|dns_dp|dns_cx|/path/to/api/file]
unbound_tls_acme_mode: dns dns_cf
# 设置使用 DNS 作为域名验证的环境变量
# 详细信息请参阅 https://github.com/Neilpang/acme.sh/tree/master/dnsapi#how-to-use-dns-api
unbound_tls_acme_dns_acc:
# CloudFlare 邮箱地址
CF_Email:
# CloudFlare 'Global' API 密钥 <https://www.cloudflare.com/a/profile>
# 请勿粘贴您的明文密钥! <https://docs.ansible.com/ansible/latest/playbooks_vault.html>
CF_Key:
# CloudFlare API URL
CF_Api: https://api.cloudflare.com/client/v4
# 密钥长度 [2048, 3072, 4096, 8192 或 ec-256, ec-384] (--keylength, -k)
unbound_tls_acme_keysize: 4096
# 创建 ECC(椭圆曲线加密)证书 (--ecc)
unbound_tls_acme_ecc: false
# 输出调试信息 (--debug)
unbound_tls_acme_debug: false
# 其他命令。https://github.com/Neilpang/acme.sh/wiki/Options-and-Params
# 例如 --dnssleep 300, --webroot /path/to/webroot/
unbound_tls_acme_custom:
### OpenNic <https://www.opennic.org/>
## 权威服务器的地址和端口,例如 nsd <https://nlnetlabs.nl/projects/nsd/>
# opennic_address: "127.0.0.1@5300"
## 权威服务器和 OpenNic 提供的 TLDs
# opennic_tlds: [ free, geek, oss, ... ]
#
## 获取 OpenNIC TLDs 的示例
##
## - name: 获取 OpenNIC TLDs
## shell: "dig @45.56.115.189 TXT tlds.opennic.glue +short | grep -v '^;' | sed s/\\\"//g | tr \" \" \"\\n\""
## register: opennic_tlds_temp
## check_mode: false
## - name: 设置 OpenNIC TLDs - https://wiki.opennic.org/opennic/dot
## set_fact:
## opennic_tlds: "{{opennic_tlds_temp.stdout_lines}}"
## 主 unbound 配置
# 有关更多选项和详细描述,请参见 <https://unbound.net/documentation/unbound.conf.html>
# 注意:在 Ansible 中,变量必须使用下划线 (_) 而不是破折号 (-) 作为分隔符
unbound:
server:
verbosity: 1
# interface: [127.0.0.1, "::1"]
# access_control: [0.0.0.0/0 allow, "::0 allow"]
# use_syslog: no
# log_time_ascii: yes
logfile: unbound.log
auto_trust_anchor_file: root.key
root_hints: root.hints
pidfile: "{{_unbound.pidfile|default('unbound.pid')}}"
username: "{{_unbound.user}}"
# 如果不编译则使用发行版默认目录,否则使用 unbound 默认目录
directory: "{{_unbound.conf_dir if unbound_compile == false else \"/usr/local/etc/unbound\"}}"
chroot: "{{_unbound.conf_dir if unbound_compile == false else \"/usr/local/etc/unbound\"}}"
## DNS-over-TLS
# interface: [0.0.0.0@853, '::0@853']
# ssl_service_key: "private.key"
# ssl_service_pem: "certificate.pem"
# ssl_port: 853
remote_control: # unbound-control
control_enable: false
依赖项
无
示例剧本
---
- hosts: all
roles:
- { role: publicarray.unbound }
vars:
- unbound_optimise: true
$ ansible-playbook -i dns.example.com, playbook.yml
测试
使用 molecule
需要 Python 2.7 和 Docker
virtualenv --no-setuptools venv
source venv/bin/activate 或 source venv/bin/activate.fish
pip install docker-py molecule
molecule test # --debug - 输出详细信息
deactivate
使用 geerlingguy 的脚本
- 安装并启动 Docker。
- 下载测试脚本到
tests/test.sh
:wget -O tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
- 使测试脚本可执行:
chmod +x tests/test.sh
。 - 运行(从角色根目录)
distro=[distro] playbook=[playbook] ./tests/test.sh
。 如果您不希望容器在测试剧本运行后自动删除,请添加以下环境变量:cleanup=false container_id=$(date +%s)
测试脚本的感谢致 @geerlingguy
支持的发行版:
- centos7
- ubuntu1604
- ubuntu1404
- debian9
- debian8
剧本位于 tests
目录
test.yml
测试默认配置compile-test.yml
测试编译 unboundpackage-test.yml
测试 dns-over-dns 和优化配置
Bash/sh 示例:
$ distro=debian9 playbook=package-test.yml cleanup=false container_id=$(date +%s) ./tests/test.sh
$ distro=debian9 playbook=compile-test.yml cleanup=false container_id=$(date +%s) ./tests/test.sh
Fish shell 示例:
$ set -x distro debian9; set -x playbook package-test.yml; set -x cleanup false; set -x container_id (date +%s); ./tests/test.sh
$ set -x distro debian9; set -x playbook compile-test.yml; set -x cleanup false; set -x container_id (date +%s); ./tests/test.sh
许可证
作者信息
@publicarray
关于项目
Unbound - Validating, recursive, and caching DNS resolver
安装
ansible-galaxy install publicarray.unbound
许可证
mit
下载
82