VMware仮想環境においてAnsible Playbookを利用してBIND(DNS)のインストールを実施したので構築方法をメモします。
前回、Dockerコンテナ間でAnsibleを動作した際の記事はこちらから

VMware仮想環境下で「Ansible」playbookを実行(BINDインストール)と動作確認まで
前回、Dockerコンテナ間でAnsible Playbookを実行し、BINDをインストールしたのですが、named、named-chrootがどれも起動しないという事象が発生しました。
今回、同じ設定でvShere環境のVMを利用して動作するか確認します。
OS環境は以下となります。
- OS:CentOS7
- Ansibleサーバー(192.168.140.100)
- dnsサーバー(192.168.140.101)
(latest)
AnsiblePlaybookのファイル構成
今回配置したファイル構成は以下となります。
配置、せって内容は前回Dockerコンテナで設定した内容とほぼ変わりません。
1 2 3 4 5 6 7 8 9 | [root@Ansible_test dns]# tree . |- config_files - 140.168.192.in-addr.arpa.rev - named.conf - test-network.local |- hosts |- playbook - dns_install.yml |
「named.conf」作成
リモート先のDNSサーバーへコピーする「named.conf」の設定内容を作成します。
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | [root@Ansible_test dns]# cat config_files/named.conf acl "test-network" { 192.168.140.0/24; }; options { listen-on port 53 { 127.0.0.1; 192.168.140.101; }; listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; secroots-file "/var/named/data/named.secroots"; recursing-file "/var/named/data/named.recursing"; allow-query { localhost; test-network; }; recursion yes; dnssec-enable no; dnssec-validation no; managed-keys-directory "/var/named/dynamic"; pid-file "/var/named/named.pid"; session-keyfile "/var/named/session.key"; }; logging { channel default_debug { file "data/named.run"; severity dynamic; }; }; view "internal" { match-clients { localhost; test-network; }; zone "." IN { type hint; file "named.ca"; }; zone "test-network.local" { type master; file "test-network.local"; }; zone "140.168.192.in-addr.arpa" { type master; file "140.168.192.in-addr.arpa.rev"; }; include "/etc/named.rfc1912.zones"; include "/etc/named.root.key"; }; |
「正引き」ゾーンファイルの作成
正引きゾーンファイルの設定内容は以下となります。
- ansible.test-network.local→192.168.140.100
- dns.test-network.local→192.168.140.101
01 02 03 04 05 06 07 08 09 10 11 12 13 | [root@Ansible_test dns]# cat config_files/test-network.local $TTL 3600 @ IN SOA dns.test-network.local. root.test-network.local. ( 2020011202 ; serial 3600 ; refresh 1hr 900 ; retry 15min 604800 ; expire 1w 86400 ; min 24hr ) IN NS dns.test-network.local. dns IN A 192.168.140.101 ansible IN A 192.168.140.100 |
「逆引き」ゾーンファイルの作成
逆引きゾーンファイルの内容は以下となります。
- 192.168.140.100→ansible.test-network.local
- 192.168.140.101→dns.test-network.local
01 02 03 04 05 06 07 08 09 10 11 12 13 | [root@Ansible_test dns]# cat config_files/140.168.192.in-addr.arpa.rev $TTL 3600 @ IN SOA dns.test-network.local. root.test-network.local. ( 2020011202 ; serial 3600 ; refresh 1hr 900 ; retry 15min 604800 ; expire 1w 86400 ; min 24hr ) IN NS dns.test-network.local. 100 IN PTR ansible.test-network.local. 101 IN PTR dns.test-network.local. |
「hosts」インベントリファイル作成
Playbook実行対象機器を設定します。
今回のリモート対象のサーバーは(192.168.140.101)となります。
1 2 3 4 5 6 7 8 9 | [root@Ansible_test dns]# cat hosts [dns] 192.168.140.101 [all:vars] ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=(password) ansible_sudo_pass=(password) |
「Playbook」作成
Playbookの内容は以下となります。
- 「hosts」から対象のリモートサーバーへアクセス
- bind,bind-chroot,bind-utilsをインストール
- named-chroot停止
- named.confをリモートサーバーへコピー
- 正引きゾーンファイルをリモートサーバーへコピー
- 逆引きゾーンファイルをリモートサーバーへコピー
- named-chroot起動
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | [root@Ansible_test dns]# cat playbook/dns_install.yml - hosts: dns become: yes tasks: - name: bind install yum: name: bind state: present - name: bind-chroot install yum: name: bind-chroot state: present - name: bind-utils install yum: name: bind-utils state: present - name: stop_named-chroot service: name: named-chroot state: stopped - name: copy named.conf copy: src: /etc/ansible/roles/dns/config_files/named.conf dest: /etc/named.conf owner: root group: named mode: 0640 - name: copy zone file copy: src: /etc/ansible/roles/dns/config_files/test-network.local dest: /var/named/test-network.local owner: root group: named mode: 0640 - name: copy reverse zone file copy: src: /etc/ansible/roles/dns/config_files/140.168.192.in-addr.arpa.rev dest: /var/named/140.168.192.in-addr.arpa.rev owner: root group: named mode: 0640 - name: start_and_enable_named-chroot service: name: named-chroot state: started enabled: yes |
「Ansible Playbook」 実行
以下コマンドでPlaybookを実行します。
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | [root@Ansible_test dns]# ansible-playbook -i hosts playbook/dns_install.yml PLAY [dns] ************************************************************************************************************************************************* TASK [Gathering Facts] ************************************************************************************************************************************* ok: [192.168.140.101] TASK [bind install] **************************************************************************************************************************************** ok: [192.168.140.101] TASK [bind-chroot install] ********************************************************************************************************************************* ok: [192.168.140.101] TASK [bind-utils install] ********************************************************************************************************************************** ok: [192.168.140.101] TASK [stop_named-chroot] *********************************************************************************************************************************** changed: [192.168.140.101] TASK [copy named.conf] ************************************************************************************************************************************* ok: [192.168.140.101] TASK [copy zone file] ************************************************************************************************************************************** ok: [192.168.140.101] TASK [copy reverse zone file] ****************************************************************************************************************************** ok: [192.168.140.101] TASK [start_and_enable_named-chroot] *********************************************************************************************************************** changed: [192.168.140.101] PLAY RECAP ************************************************************************************************************************************************* 192.168.140.101 : ok=9 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 |
問題なく実行されると上記の様にエラーがカウントされず、「ok」、及び「changed」がカウントされます。
動作確認
実際にリモートサーバーでBINDがインストールされ、正常動作をしているか確認します。
以下ではnslookupを実行し、DNSをリモートサーバー(192.168.140.101)を指名します。
正引き:ansible.test-network.local
1 2 3 4 5 6 | [root@Ansible_test dns]# nslookup ansible.test-network.local 192.168.140.101 Server: 192.168.140.101 Address: 192.168.140.101#53 Name: ansible.test-network.local Address: 192.168.140.100 |
逆引き:ansible.test-network.local
1 2 | [root@Ansible_test dns]# nslookup 192.168.140.100 192.168.140.101 100.140.168.192.in-addr.arpa name = ansible.test-network.local. |
正引き:dns.test-network.local
1 2 3 4 5 6 | [root@Ansible_test dns]# nslookup dns.test-network.local 192.168.140.101 Server: 192.168.140.101 Address: 192.168.140.101#53 Name: dns.test-network.local Address: 192.168.140.101 |
逆引き:dns.test-network.local
1 2 | [root@Ansible_test dns]# nslookup 192.168.140.101 192.168.140.101 101.140.168.192.in-addr.arpa name = dns.test-network.local. |
上記の様にDNSサーバーから応答があれば成功です。
応答がない場合は対象のサーバーで「53」番ポートの開放をしましょう。
permitしていない場合は名前解決の確認ができません。
設定は以上となります。
ITエンジニアの開発・検証・学習としてインターネット上で専用のサーバ(VPS)を利用しましょう!
実務経験はVPSで学べます。
コメント