title: Finding file name in files section of current Ansible role
body: <p>I'm fairly new to Ansible and I'm trying to create a role that copies a file to a remote server. The local file can have a different name every time I'm running the playbook, but it needs to be copied to the same name remotely, something like this:</p>
  
  <pre><code>- name: copy file
    copy:
      src=*.txt
      dest=/path/to/fixedname.txt
  </code></pre>
  
  <p>Ansible doesn't allow wildcards, so when I wrote a simple playbook with the tasks in the main playbook I could do:</p>
  
  <pre><code>- name: find the filename
      connection: local
      shell: "ls -1 files/*.txt"
      register: myfile
  
  - name: copy file
    copy:
      src="files/{{ item }}"
      dest=/path/to/fixedname.txt
    with_items:
     - myfile.stdout_lines
  </code></pre>
  
  <p>However, when I moved the tasks to a role, the first action didn't work anymore, because the relative path is relative to the role while the playbook executes in the root dir of the 'roles' directory. I could add the path to the role's files dir, but is there a more elegant way?</p>