In my playbook I run a local_action that executes a script and stores the value for future use:
- local_action: command python release.py
register: release_url
This worked great, until I moved my playbook into a subdirectory. It turns out that the command runs from your current working directory (that you run ansible from), so the path needs to look like this:
- local_action: command python roles/ghost/release.py
I have a directory structure as below:
However the roles/ghost folder name can change (and hard-coding this won't let you run the playbook from another directory).
How can I get the directory path of tasks/main.yml (which issues the local_action command), so I can give a relative path to it?
As of ansible 1.8, there's a role_path
variable defined that you can use for this purpose.
Can you put release.py script in roles/ghost/files/ and then use it with local_action
- name: local scrpt
local_action: script release.py
And that way you may not need to get the directory path
This makes reference to doing so in the Directory Layout part http://www.ansibleworks.com/docs/playbooks_best_practices.html
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