大网数据广告活动
服务器运维问答

How can I replace a template file in an Ansible role?

· 52CE 我爱测

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 th…

问题原文

原帖链接 · Daniel Ashton · CC BY-SA 4.0

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."

社区高分解答

原帖链接 · John Mahowald · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-04-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。