PowerDNSには構築用のAnsibleロールが公式に用意されているようです。
PowerDNS/pdns-ansible: PowerDNS Authoritative Ansible role
Debian系とRedHat系のLinuxに対応しているようです。
(SQLiteバックエンドは現在Debian系のみのようです)
今回はCentOS6(RedHat系)で、バックエンドにはMySQL5.1を使います。
前提バージョン
$ cat /etc/redhat-release
CentOS release 6.8 (Final)
$ ansible --version
ansible 2.1.2.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
$ mysql --version
mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
Playbook作成
$ git clone https://github.com/PowerDNS/pdns-ansible.git
$ mkdir roles
$ mv pdns-ansible roles/
$ vim master.yml
master.yml
- hosts: localhost
sudo: yes
roles:
- role: pdns-ansible
vars:
pdns_config:
master: true
slave: false
pdns_backends:
gmysql:
host: localhost
port: 3306
user: powerdns
password: P0w3rDn5
dbname: pdns
pdns_backends_mysql_credential:
gmysql:
priv_user: root
priv_password: "MySQLルートパスワード"
priv_host:
- "localhost"
pdns_repo_provider: 'powerdns'
pdns_repo_branch: 'master'
pdns_mysql_schema_file:
powerdns: /usr/share/doc/pdns-backend-mysql-3.3.3/no-dnssec.schema.mysql.sql #ベタで書きたくないがこうしないとうまくいかなかった
実行
$ ansible-playbook master.yml
PowerDNSのインストールとデータベースの作成が行われます。
起動
$ service pdns start
サンプルレコードの登録
MySQLに入って、下記クエリを実行してみます。
USE pdns
INSERT INTO domains (name, type) VALUES ('example.com', 'NATIVE');
INSERT INTO records (domain_id, name, content, type, ttl, prio) VALUES
(1, 'example.com', 'ns.example.com postmaster@example.com 1','SOA', 60, NULL),
(1, 'example.com', 'ns.example.com', 'NS', 60, NULL),
(1, 'example.com', 'mail.example.com', 'MX', 60, 0),
(1, 'mail.example.com', '10.6.0.10', 'A', 60, NULL),
(1, 'www.example.com', '10.6.0.11', 'A', 60, NULL);
SQL実行前
$ dig example.com any @127.0.0.1
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> example.com any @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 25977
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;example.com. IN ANY
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Oct 31 03:28:36 2016
;; MSG SIZE rcvd: 29
SQL実行後
$ dig example.com any @127.0.0.1
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> example.com any @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24510
;; flags: qr aa rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;example.com. IN ANY
;; ANSWER SECTION:
example.com. 60 IN SOA ns.example.com. postmaster.example.com. 1 10800 3600 604800 3600
example.com. 60 IN NS ns.example.com.
example.com. 60 IN MX 0 mail.example.com.
;; ADDITIONAL SECTION:
mail.example.com. 60 IN A 10.6.0.10
;; Query time: 3 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Oct 31 03:31:30 2016
;; MSG SIZE rcvd: 130
反映されました。