Relative paths behaviour changes 1.9 => 2.0 => 2.1.2

Hi,

It seems like Ansible 2.1.2 and newer has changed path handling.

My observations are:

  • In 1.9.x it bases relative paths on the path of the playbook itself.
  • In 2.0.0 to 2.1.1 it bases relative paths on the path of where ansible-playbook is being executed from.
  • In 2.1.2 it reverts back to 1.9.x behaviour.

This affects, among others, the template module when using relative paths, as well as pwd from a shell command.

This seems like a pretty big change.

Am I doing something wrong? Which is correct?

To reproduce the observations:

Assuming the following directory tree, and a test.yml playbook:

.

├── ansible

│ ├── group_vars

│ ├── inventory

│ └── test.yml

└── other

test.yml:

  • name: test

hosts: localhost

gather_facts: no

tasks:

  • command: >

pwd

register: result

  • debug: var=result.stdout

Executing:

cd /projects/acme-corp/my-project/

ansible-playbook -i local, ./ansible/test.yml

In Ansible 2.1.1, I get:

TASK [debug] *******************************************************************

ok: [localhost] => {

“result.stdout”: “/projects/acme-corp/my-project”

}

In Ansible 2.1.2 and 1.9.0, I get:

TASK [debug] *******************************************************************

ok: [localhost] => {

“result.stdout”: “/projects/acme-corp/my-project/ansible”

}

Thanks,

Steve

First, not all paths are equal nor work the same way. The execution path, which is what you are getting when running pwd, depends on the connection plugin, it normally is the ‘login directory’ which for ssh is usually the remote $HOME. For most plugins this has not changed across versions.

The ‘local’ connection plugin (default for localhost/local_action) had a bug introduced in 2.0 in which the path changed from ‘playbook directory’ to invocation path, 2.1.2 fixed that bug.

This is what you are seeing in your tests, which do not really apply to the template plugin.

Hi Brian,

Thanks for the prompt reply.

For the template module, in 2.0.0-2.1.1, this worked:

  • template:
    src: templates/template-file.txt.j2
    dest: ./subdirectory/result.txt

For 2.1.2 and later I have had to change this to:

  • template:
    src: templates/template-file.txt.j2
    dest: …/subdirectory/result.txt

(Note the .. as opposed to the . in the dest parameter)

Whether the cause is the same or different to command: pwd, the result seems to be the same.

Regardless, I now know that the 2.0 to 2.1.1 behaviour is buggy, and I should change playbooks to use the “fixed” behaviour.

Thanks so much for the help.

Steve

Ah, sorry, I seem to have misinterpreted the problem. The template patching i was referring to was for src=, for dest= you rely on ‘execution pathing’, which thankfully I also answered in the previous email.

src gets handled mainly by the action plugin, dest gets handled by the module of the same name, which does run relative to execution path.

My bad. I should have been clearer.

Thanks for the support!