1
Ansible中是否存在“全局”变量(即跨多个主机)?我想设置一个错误标志,然后调用一个特定的单独的剧本,如果我们打错了状态。我的结构像下面的东西:Ansible - 全局变量
- hosts: localhost
connection: local
gather_facts: no
roles:
- role1 <-- some error flag is set here
- role2
- include: teardown.yml
when: error_flag is defined and error_flag == true
我试过在group_vars
设置一个变量,但在我看来,这里还有在运行时改变变量值没有真正的方法。
Set_fact不起作用,因为拆卸的when
不在本地主机中。即使我尝试访问hostvars['localhost']['error_flag]
,这也不起作用,因为您似乎无法在when
子句中使用Jinja模板。
主机变量'hostvars.localhost.error_flag'应该可以在没有Jinja2模板的'when'子句中访问。也就是说,不用'{{''}}'Jinja2分隔符来写这个表达式。 –