Ansible Playbook 语法问题 - when: list

Ansible Playbook Syntax Issue - when: list

我正在本地主机上收集资料。

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'

您可以使用 访问嵌套元素:ansible_dns.nameservers.

不确定要构造什么条件,但可能的方法之一是:
when: "'192.168.1.2' in ansible_dns.nameservers and '192.168.1.3' in ansible_dns.nameservers"