# file path variable for playbook

**URL:** <https://forum.ansible.com/t/file-path-variable-for-playbook/15232>\
**Category:** Ansible Project\
**Created:** [May 14, 2014, 11:47am UTC](https://forum.ansible.com/t/file-path-variable-for-playbook/15232 "2014-05-14T11:47:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [May 14, 2014, 11:47am UTC](https://forum.ansible.com/t/file-path-variable-for-playbook/15232/1 "2014-05-14T11:47:57Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [May 14, 2014, 11:58am UTC](https://forum.ansible.com/t/file-path-variable-for-playbook/15232/2 "2014-05-14T11:58:35Z")

</div>

​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.

&nbsp;&nbsp;Serge​

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 14, 2014, 12:25pm UTC](https://forum.ansible.com/t/file-path-variable-for-playbook/15232/3 "2014-05-14T12:25:43Z")

</div>

“ **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.
