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.