问题
Couldn't find anything google'ing.
There is group_vars/all/ for variables. Is there something similar for templates? I would like to use some templates across multiple roles.
回答1:
You can put your global templates into templates
directory at the top level of Ansible layout (same level as group_vars
). BTW same goes for global files.
files/
group_vars/
roles/
site.yml
templates/
回答2:
It was possible before 2.2.1, but not after. See issue 20442.
There's a patch that allows you to do out-of-scope includes.
Also as @René suggests you can try to put your common templates into some role and declare it as dependency or call include_role
. As far as I remember while digging the issue, Ansible adds all roles used in current context into search path.
回答3:
A possible solution is to put the reusable template in a dependent role. See role dependencies.
来源:https://stackoverflow.com/questions/46396732/ansible-global-template-folder