2016-11-21 70 views
0

我收集我的本地主机上的事实。Ansible Playbook语法问题 - 当:列表

localhost | SUCCESS => { 
    "ansible_facts": { 
     "ansible_dns": { 
      "nameservers": [ 
       "192.168.1.2", 
       "192.168.1.3" 
      ], 
      "search": [ 
       "example.com", 
      ] 
     } 
    }, 
    "changed": false 
} 

我需要能够访问域名服务器:192.168.1.2192.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

您可以访问嵌套的元素与ansible_dns.nameservers

不知道你要构造什么样的条件,但可能的方式之一:
when: "'192.168.1.2' in ansible_dns.nameservers and '192.168.1.3' in ansible_dns.nameservers"

+0

我实际使用'ansible_dns.nameservers ==“192.168.1.7''。我相信你的方法也会奏效!当我过滤'ansible local -m setup -a'filter = ansible_dns.nameservers''并且。(dot)不起作用时,我认为它在Playbook中不起作用。 –

+0

编辑:只是开玩笑。你的“in”声明有效,我的不会:) –