Ansible 用jinja模板中的var内容替换正则表达式
我有一个jinja模板,我想用变量的内容替换字符串 例如:Ansible 用jinja模板中的var内容替换正则表达式,ansible,ansible-template,Ansible,Ansible Template,我有一个jinja模板,我想用变量的内容替换字符串 例如: ansible_hostname: 'host-to' item.suffixe: 'cool' 结果将是:主机冷却到 我这样做: {{ansible_hostname}regex_replace('-to','-{{item.subfixe}}-to')} 当然,'-{item.suffix}}}-to'没有被解释,结果是: 主机{{item.suffix}}-to 是否可以在regex_replace中使用变量?怎样?在ansib
ansible_hostname: 'host-to'
item.suffixe: 'cool'
结果将是:主机冷却到
我这样做:
{{ansible_hostname}regex_replace('-to','-{{item.subfixe}}-to')}
当然,'-{item.suffix}}}-to'没有被解释,结果是:
主机{{item.suffix}}-to
是否可以在regex_replace中使用变量?怎样?在ansible示例中,它们没有显示任何类似的内容
Q:“是否可以在regex_replace中使用变量?”
A:是的。这是可能的。将参数放入变量中更容易。比如说
-调试:
msg:{{hostname | regex_replace(regex,replace)}”
变量:
主机名:主机到
后缀:酷
正则表达式:'-to'
替换:'-{suffix}}-to'
给予
msg:host cool to