# Can't understand Ansible 2.0 paths logic

**URL:** <https://forum.ansible.com/t/cant-understand-ansible-2-0-paths-logic/20827>\
**Category:** Ansible Project\
**Created:** [March 10, 2016, 2:33pm UTC](https://forum.ansible.com/t/cant-understand-ansible-2-0-paths-logic/20827 "2016-03-10T14:33:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florent\_B](https://avatars.discourse-cdn.com/v4/letter/f/7ba0ec/32.png) [@Florent\_B](https://forum.ansible.com/u/Florent_B)\
**Post date:** [March 10, 2016, 2:33pm UTC](https://forum.ansible.com/t/cant-understand-ansible-2-0-paths-logic/20827/1 "2016-03-10T14:33:14Z")

</div>

Hi everyone,

Since upgrade Ansible 2.0, I have a lot of problems with path finding in modules like template or file.

Can someone explain me the logic to have this :

- name: Create temporary folder  
local\_action: file path= **templates/** \_tmp state=directory

- name: Get files to process template  
fetch: src=/var/www/test.php dest= **…/templates/** \_tmp/test.php flat=yes

- name: Process template  
template: src= **…/templates/** \_tmp/test.php dest=/var/www/test.php

- name: Remove temporary folder  
local\_action: file path= **templates/** \_tmp state=absent

Sometimes we need to specify “…/” to go to project template’s directory, sometimes not. Where is the logic ?

In this example, “templates/” and “…/templates/” are referring to the SAME directory !

With Ansible 1.9, all was working fine with “…/templates/” everywhere !

We have a lot of changes like this to do, that’s annoying.

That’s very strange.

Florent

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 10, 2016, 2:47pm UTC](https://forum.ansible.com/t/cant-understand-ansible-2-0-paths-logic/20827/2 "2016-03-10T14:47:52Z")

</div>

You are conflating 2 different systems for ‘relative path resolution’:

The first applies to ‘remote actions’ run from ‘cwd’ on the target machine, normally the home dir of the login user. But with local action translates to the directory from which you invoked Ansible. This is what `file` is using, it is hard to predict this from the play as I show below.

The second applies only to some plugins that use ‘master’ as a source (via action plugins) like template/copy, etc follow a set of paths like this:  
( can be files/ vars/ or templates/ depending on plugin)

if inrole:  
role\_dir//  
role\_dir/tasks/  
role\_dir/

play\_dir//  
play\_dir/

In 1.9 this was somewhat broken and it pathed across this tree multiple times and in 1.9.4 it even included ‘cwd’, but the above is the way this was always meant to work as you can execute Ansible from anywhere (i.e /tmp, /etc/, /dev/) and you cannot construct a playbook predictably that way.

So I recommend you rewrite the `file` and `fetch` tasks to use role\_path or playbook\_dir variables to use a predictable path, otherwise if you execute from a different directory you will start having issues again.

Relying on cwd makes these all these commands work differently:  
ansible-playbook …/path/to/plays/play.yml

ansible-playbook ./play.yml

ansible-playbook plays/play.yml
