How do I override Ansible movie file?
I am using the zzet.rbenv role in my book. It has a file files/default-gems
that it copies to the prepared system.
I need my notebook to check myplaybook/files/default-gems
and use it if it exists, using zzet.rbenv/files/default-gems
it if not.
How can i do this?
source to share
After some research and trial / error. I found out that Ansible is not capable of checking if files exist between roles. This is due to how the role of dependencies (the roles themselves) will expand to what is required, making it part of the tutorial. There are no tasks to tell you my_role/files/my_file.txt
from required_role/files/my_file.txt
.
One approach to the problem (the one I found to be the simplest and cleanest) was as follows:
- Add a variable in
my_role
with the path to the file I want to use (overriding the default) - Add a task (identical to the one using the default file) that checks if the above variable is defined and runs it with
Example
required_role
# Existing task
- name: some task
copy: src=roles_file.txt dest=some/directory/file.txt
when: my_file_path is not defined
# My custom task
- name: my custom task (an alteration of the above task)
copy: src={{ my_file_path }} dest=/some/directory/file.txt
when: my_file_path is defined
my_role
#... existing code
my_file_path: "path/to/my/file"
As mentioned by Ramon de la Fuente: this decision was made in the zzet.rbenv repo :)
source to share