# Help on using the wen condition

**URL:** <https://forum.ansible.com/t/help-on-using-the-wen-condition/32047>\
**Category:** Ansible Project\
**Created:** [January 24, 2020, 11:21am UTC](https://forum.ansible.com/t/help-on-using-the-wen-condition/32047 "2020-01-24T11:21:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Nanboe](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@Daniel\_Nanboe](https://forum.ansible.com/u/Daniel_Nanboe)\
**Post date:** [January 24, 2020, 11:21am UTC](https://forum.ansible.com/t/help-on-using-the-wen-condition/32047/1 "2020-01-24T11:21:35Z")

</div>

I have a list of users defined as variable on my inventory.

I want to create a task that checks if for each user exists a file in a folder if it exists will run a task if not will run an other task. I have a task that add the user with password if password exists and no ssh key is found and another that adds the user with both password and key.

This one checks if there is an ssh key defined for the client:

`

- name: Add sftp users  
block:
- name: Check if diapason folder exists  
stat:  
path: “SYMPHONY\_HOME + '/config/ssh\_keys/clients/keys/{{ item.ssh\_key }}.pub”  
register: sshkey\_status  
with\_items: “{{ sftp\_users }}”  
`

And then I want to use the info in a conditional

`

- name: Add sftp users with ssh key  
user:  
name: “{{ item.remote\_user }}”  
state: “{{ item.state | default(‘present’) }}”  
shell: /usr/bin/false  
skeleton: yes  
group: “{{ item.remote\_user }}”  
groups:
- sftpgroup  
with\_items: “{{ sftp\_users }}”  
when: (item.state != “absent”) and (sshkey\_status.stat.exists == true)  
`

The problem is that sshkey\_status is a variable with a list for each user from the user list and I cannot use it like that. I have te required info there but not sure how to get to it in the when statement.

Can somebody point me towards a working direction.
