Authored by chunhua.zhang

将dns 服务器的配置更新到inventory文件中

---
nameservers:
- 10.66.4.18
- 10.66.4.17
dc: qcloud-az1
... ...
# inventory file for az1
[nameservers]
10.66.4.18
10.66.4.17
[java-nginx]
10.66.0.2
10.66.0.3
... ...
---
nameservers:
- 10.66.105.5
- 10.66.105.9
dc: qcloud-az2
\ No newline at end of file
... ...
# inventory file for az2
[nameservers]
10.66.105.5
10.66.105.9
[java-nginx]
10.66.104.15
10.66.104.13
... ...
---
nameservers:
- 10.66.200.10
- 10.66.200.12
dc: qcloud-az3
\ No newline at end of file
... ...
# inventory file for az2
[nameservers]
10.66.200.10
10.66.200.12
[java-nginx]
10.66.202.5
10.66.202.12
... ...
---
nameservers: ''
nameserver_timeout: 1
\ No newline at end of file
... ...
---
# Configure resolv.conf
# make sure group exists
- name: make sure nameserver groups exist in inventory file
fail:
msg: "group {{ item }} not exist!"
when: item not in groups
with_items:
- nameservers
- name: Configure resolv.conf
template:
src: resolv.conf.j2
... ...
# {{ ansible_managed }}
{% for i in nameservers %}
{% for i in groups['nameservers'] %}
nameserver {{ i }}
{% endfor %}
... ...
# inventory file for az1
[nameservers]
10.66.4.18
10.66.4.17
[java-nginx]
10.66.0.2
10.66.0.3
... ...
# inventory file for az2
[nameservers]
10.66.105.5
10.66.105.9
[java-nginx]
10.66.104.15
10.66.104.13
... ...
# inventory file for az2
[nameservers]
10.66.200.10
10.66.200.12
[java-nginx]
10.66.202.5
10.66.202.12
... ...