Some Ansible roles, such as https://github.com/bertvv/ansible-role-hosts, use template files that may be a near miss for the needs of this project. When the role author has not provided a variable substitution for the name of the template, is there still a way to replace the template file? Obviously, I could fork the role and use my own fork, but I'm hoping there's a better answer, such as "just drop your replacement template file in the templates directory of your role that depends on Bert's role."
Asked
Active
Viewed 1,978 times
3
-
There's really no other solution other than locally editing either the template or the corresponding task (e.g., to have the task use an alternate template). – larsks Apr 09 '19 at 15:15
2 Answers
4
Playbook pathing has some "do what I mean" magic for relative paths. rolename/templates
is searched first in dependency order, then {{playbook_dir}}/templates
You cannot change this without altering the role somehow, one of:
altering the src file name
adding a dependency on your role that provides a different template of the same name
editing their template
I like changing the file name the best. Send them a change that make the source template name into a variable in role defaults.
![](../../users/profiles/241174.webp)
John Mahowald
- 30,009
- 1
- 17
- 32
1
If you are willing to have changes occur at every ansible run you could use a lineinfile
task on the instantiated template file (i.e. the dest
in the template
task) after the role is applied.
![](../../users/profiles/48857.webp)
Mark Wagner
- 17,764
- 2
- 30
- 47