# Register variables in tasks that use with\_items?

**URL:** <https://forum.ansible.com/t/register-variables-in-tasks-that-use-with-items/21346>\
**Category:** Ansible Project\
**Created:** [May 3, 2016, 8:11pm UTC](https://forum.ansible.com/t/register-variables-in-tasks-that-use-with-items/21346 "2016-05-03T20:11:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [May 3, 2016, 8:11pm UTC](https://forum.ansible.com/t/register-variables-in-tasks-that-use-with-items/21346/1 "2016-05-03T20:11:03Z")

</div>

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:  
&nbsp;&nbsp;- foo  
&nbsp;&nbsp;- 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"  
&nbsp;&nbsp;stat: path="/home/{{item}}/some/path"  
&nbsp;&nbsp;with\_items: {{ userlist }}  
&nbsp;&nbsp;register: check\_for\_path

- fail: msg="path does not exist"  
&nbsp;&nbsp;when: check\_for\_path.stat.isdir is undefined

Johannes
