Ansible loop, set different variables

I need to check if certain paths exists. More than one path may exist on a server:
/home/user1/Scripts
/home/user2/Scripts
/home/user3/Scripts

If it exists, I want to define a variable. For user1, variable user1 will be defined, user2 for user2 and so on.

I know I can easily check the paths in a loop, but how would I go about setting a custom var for each in the same loop?

`

  • name: Check paths
    stat:
    path: {{ item.path }}
    with_items:
  • { path: ‘/home/user1/Scripts’ }
    - { path: '/home/user2/Scripts' }
    - { path: '/home/user3/Scripts' }

`

As register isn’t part of stat, I don’t know how I would register different vars.

maybe something like:

`

  • set_fact:
    users: [ ‘user1’, ‘user2’, ‘user3’]

  • name: Check paths
    stat:
    path: “/home/{{ item }}/Scripts”
    with_items: “{{ users}}”
    register: stat_results

`