Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get parent directory in Ansible?

Tags:

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.

like image 514
Pithikos Avatar asked Feb 08 '16 13:02

Pithikos


People also ask

How do I find my role path in Ansible?

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.

What is path in Ansible?

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.

What is register in Ansible?

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.

What is the ansible playbook execution order?

Playbook execution. A playbook runs in order from top to bottom. Within each play, tasks also run in order from top to bottom.


1 Answers

You can use the dirname filter:

{{ inventory_dir | dirname }} 

For reference, see Managing file names and path names in the docs.

like image 101
udondan Avatar answered Sep 21 '22 16:09

udondan