Register variables in tasks that use with_items?

13 views
Skip to first unread message

Johannes Kastl

unread,
May 3, 2016, 4:11:17 PM5/3/16
to ansible...@googlegroups.com
Hi all,

say I want to create a file for two users. I create a list containing
the users and create a task with a loop using with_items:

userlist:
- foo
- bar

To avoid trouble I want to check if the target folder exists and fail
if it does not.

How to get this working?

- name: "Check if folder exists"
stat: path="/home/{{item}}/some/path"
with_items: {{ userlist }}
register: check_for_path

- fail: msg="path does not exist"
when: check_for_path.stat.isdir is undefined

Johannes

signature.asc
Reply all
Reply to author
Forward
0 new messages