Ansible when condition with ansible_facts

166 views
Skip to first unread message

Michael Liu

unread,
Apr 27, 2015, 8:15:41 PM4/27/15
to ansible...@googlegroups.com
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!

Brian Coca

unread,
Apr 27, 2015, 8:34:57 PM4/27/15
to ansible...@googlegroups.com
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):

vars:
newdevices:
- /dev/xvdc
- /dev/sda1
tasks:
- debug: msg="mounted {{item.device}}"
with_items: ansible_mounts
when: item.device in newdevices



--
Brian Coca
Reply all
Reply to author
Forward
0 new messages