# Ansible when condition with ansible\_facts

**URL:** <https://forum.ansible.com/t/ansible-when-condition-with-ansible-facts/18100>\
**Category:** Ansible Project\
**Created:** [April 28, 2015, 12:15am UTC](https://forum.ansible.com/t/ansible-when-condition-with-ansible-facts/18100 "2015-04-28T00:15:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Liu](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@Michael\_Liu](https://forum.ansible.com/u/Michael_Liu)\
**Post date:** [April 28, 2015, 12:15am UTC](https://forum.ansible.com/t/ansible-when-condition-with-ansible-facts/18100/1 "2015-04-28T00:15:41Z")

</div>

Hey All,

Trying to create a (when: ) condition, where a task runs only when a mount point does NOT exists.

- name: format disk with ext4  
filesystem: fstype=ext4 dev={{ item }}  
with\_items:
- /dev/xvdc  
when: ansible\_mounts.mount doesn’t contain “/path/to/my/mount/point”

The expectation is that ansible\_mounts contains 1 or more mount points.

Any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 28, 2015, 12:34am UTC](https://forum.ansible.com/t/ansible-when-condition-with-ansible-facts/18100/2 "2015-04-28T00:34:53Z")

</div>

ansible\_mounts is a list of dictionaries, each of which has a 'mount'  
so you are really comparing to a complex structure, you can try  
something like this (though with set\_fact to create the list you  
need):

&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;newdevices:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- /dev/xvdc  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- /dev/sda1  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- debug: msg="mounted {{item.device}}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: ansible\_mounts  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: item.device in newdevices
