title: How to build a list of file names in a local directory?
body: <p>I have bunch of .keys files in my /files folder. What I want to do is to create users on remote hosts that match these keys files. </p>
  
  <p>Say I have alice.keys, bob.keys, and john.keys in /files. I want the script to create alice, bob and john users, if they do not exist and update/add SSH keys from appropriate .keys file for each user.</p>
  
  <p>I know I can use the <code>loop</code> module to loop through the files, but I do not know how to form the list which contains just file-names, so I can use it later.</p>
  
  <p>My role structure looks like:</p>
  
  <pre><code>sshrole
  ├── defaults
  │   └── main.yml
  ├── files
  │   ├── alice.keys
  │   ├── bob.keys
  │   └── john.keys
  ├── handlers
  │   └── main.yml
  ├── README.md
  ├── tasks
  │   ├── main.yml
  │   ├── setup.yml
  │   ├── update.yml
  │   ├── useradd.yml
  │   └── userdel.yml
  ├── templates
  │   └── ssh_config.j2
  └── vars
      └── main.yml
  </code></pre>
  
  <p>In short, what I want is to have a variable <code>ssh_users</code> containing <code>{'alice', 'bob', 'john'}</code> values.</p>
  
  <p>UPDATE:
  Using the accepted answer as a guide, I decided to have a task like:</p>
  
  <pre><code>- name: Extract user-names.
    shell: echo {{item}} | sed 's/.*\/\(.*\)\.keys/\1/'
    register: sed_commands
    with_fileglob: ../files/*.keys
  </code></pre>
  
  <p>And then I use {{sed_commands.results}} in other tasks.</p>