Is there a way to evaluate a relative path in Ansible?
tasks: - name: Run docker containers include: tasks/dockerup.yml src_code='..'
Essentially I am interested in passing the source code path to my task. It happens that the source code is the parent path of {{ansible_inventory}}
but there doesn't seem to be anything to accomplish that out of the box.
---- further info ----
Project structure:
myproj app deploy deploy.yml
So I am trying to access app
from deploy.yml
.
Role Search Path Ansible will search for roles in the following way: A roles/ directory, relative to the playbook file. By default, in /etc/ansible/roles.
You can control the paths Ansible searches to find resources on your control node (including configuration, modules, roles, ssh keys, and more) as well as resources on the remote nodes you are managing. Use absolute paths to tell Ansible where to find resources whenever you can.
Ansible register is a way to capture the output from task execution and store it in a variable. This is an important feature, as this output is different for each remote host, and the basis on that we can use conditions loops to do some other tasks. Also, each register value is valid throughout the playbook execution.
Playbook execution. A playbook runs in order from top to bottom. Within each play, tasks also run in order from top to bottom.
You can use the dirname
filter:
{{ inventory_dir | dirname }}
For reference, see Managing file names and path names in the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With