Ansible Playbook - when: list?

43 views
Skip to first unread message

Jeffrey Wen

unread,
Nov 22, 2016, 12:07:15 PM11/22/16
to Ansible Project
localhost | SUCCESS => {
   
"ansible_facts": {
       
"ansible_dns": {
           
"nameservers": [
               
"192.168.1.1",
               
"192.168.1.2"
           
],
           
"search": [
               
"example.com",
           
]
       
}
   
},
   
"changed": false
}

I am trying to reference my nameservers but I am running into syntactical issues. I cannot find any docs online that show me how to access a list from gathering facts.

I have tried the following:

- 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.1' and ansible_dns == nameservers == '192.168.1.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.1' and nameservers == '192.168.1.2'


Kai Stian Olstad

unread,
Nov 22, 2016, 12:53:52 PM11/22/16
to ansible...@googlegroups.com
On 21. nov. 2016 19:14, 'Jeffrey Wen' via Ansible Project wrote:
> localhost | SUCCESS => {
> "ansible_facts": {
> "ansible_dns": {
> "nameservers": [
> "192.168.1.1",
> "192.168.1.2"
> ],
> "search": [
> "example.com",
> ]
> }
> },
> "changed": false
> }
>
> *I am trying to reference my nameservers but I am running into syntactical
> issues. I cannot find any docs online that show me how to access a list
> from gathering facts.*
>
> I have tried the following:
>
> - 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.1' and ansible_dns ==
> nameservers == '192.168.1.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.1' and nameservers == '192.168.1.2'

when: '192.168.1.1' in ansible_dns.nameservers and '192.168.1.2' in
ansible_dns.nameservers

--
Kai Stian Olstad

Jeffrey Wen

unread,
Nov 22, 2016, 1:26:42 PM11/22/16
to Ansible Project, ansible-pr...@olstad.com
Thank you!
Reply all
Reply to author
Forward
0 new messages