我在本地主机上收集事实。
localhost | SUCCESS => {
"ansible_facts": {
"ansible_dns": {
"nameservers": [
"192.168.1.2",
"192.168.1.3"
],
"search": [
"example.com",
]
}
},
"changed": false
}
我需要能够访问域名服务器: 192.168.1.2 和 192.168.1.3
我尝试了以下操作,但仍然在语法中出错。我没有看到任何在线文档向我展示如何访问嵌套值。
# Method 1
- name: Allow httpd access to files on CIFS volumes that are labeled with the cifs_t type
seboolean: name=httpd_use_cifs state=true persistent=yes
when: ansible_dns == nameservers == '192.168.1.2' and ansible_dns == nameservers == '192.168.1.3'
# Method 2
- name: Allow httpd access to files on CIFS volumes that are labeled with the cifs_t type
seboolean: name=httpd_use_cifs state=true persistent=yes
when: nameservers == '192.168.1.2' and nameservers == '192.168.1.3'
答案 0 :(得分:0)
您可以使用 dot 访问嵌套元素:ansible_dns.nameservers
。
不确定要构建的条件,但可能的方法之一:
when: "'192.168.1.2' in ansible_dns.nameservers and '192.168.1.3' in ansible_dns.nameservers"