file path variable for playbook

I use ansible to prepare some (unfortunately untidy) updates which consist of replacing old files by new files. Therefore I would need to

  1. backup old files
  2. copy new files

So I create for each update a playbook folder with
backup.yml → saves the old files (loops over vars.yml)
copy.yml → copies the new files (loops over vars.yml)
vars.yml → defines where new files shall be copied to
(see tree below)

update2014-05-12/

– backup.yml
– copy.yml
– newfiles

– file1.jar
– file2.jar
– file3.jar
`–file4jar
– oldfiles

– vars.yml

The problem is now:
If in my copy.yml I copy from newfiles directory, the newfiles directory is not found (I posted my copy task below)

  • name: copy files
    synchronize:
    archive=no
    src=newfiles/{{item.1}}
    dest={{ item.0.dest_dir }}{{ item.1 }}
    with_subelements:
  • copy_files
  • files

Is there a way to specify in a playbook where to look up files (like the ‘files’ directory in roles)?

​You have some magic vars for that:
- playbook_dir
- inventory_dir

I have been thinking it would also be nice to have a role_dir.

  Serge​

Is there a way to specify in a playbook where to look up files (like the ‘files’ directory in roles)?”

The answer here is that you shouldn’t need it.

The files will first be looked for in the “roles/files” directory, and then in a directory alongside the playbook.

The error message you get when the file is not found will tell you where it is searching, and you should just be able to put things in the right place without having to rely on variables to find path locations.