Server 可变变量库存

Server 可变变量库存,server,ansible,ansible-inventory,Server,Ansible,Ansible Inventory,我在学Ansible。我在看官方文件: 但我有一个小问题。如何在库存中使用VAR 我尝试使用一些默认参数,如自毁倒计时 并将变量应用于所有组。使用自己的var [pruebascomandos:vars] example=true 但我的问题是,在这两种情况下,我都试图用以下方法检查var: $ansible pruebascomandos-m shell-a“echo$self\u destruct\u倒计时” $ansible pruebascomandos-m shell-一个“

我在学Ansible。我在看官方文件:

但我有一个小问题。如何在库存中使用VAR

我尝试使用一些默认参数,如自毁倒计时

并将变量应用于所有组。使用自己的var

[pruebascomandos:vars]
example=true
但我的问题是,在这两种情况下,我都试图用以下方法检查var:

$ansible pruebascomandos-m shell-a“echo$self\u destruct\u倒计时”

$ansible pruebascomandos-m shell-一个“echo$example”

在这两种情况下,我都得到了一个空白的回答。我不知道为什么

如果有人能解释原因或告诉我在哪里读它会很好。谢谢大家

计算变量时需要
{{}
。试试这个

shell>ansible pruebascommandos-i hosts-mshell-a“echo{{{example}”
测试|更改| rc=0>>
真的
测试02 |更改| rc=0>>
真的
shell>ansible pruebascommandos-i hosts-mshell-a“echo{{self_destruct_倒计时}”
测试|失败| rc=-1>>
该任务包括一个带有未定义变量的选项。错误是:自毁倒数未定义
测试|更改| rc=0>>
60
主机
test\u 02
失败,因为变量
self\u destruct\u countdown
仅为
test\u 01
定义

shell>cat主机
[普鲁巴斯科曼多斯]
测试\u 01自毁\u倒计时=60
测试02
[普鲁巴斯科曼多:瓦尔]
示例=真

2.3版不再受支持。升级到。谢谢!现在起作用了。我知道只有在执行命令AD-HOC时变量才存在。要在系统中使用,需要导出或使用剧本(这是我的下一课剧本)
[pruebascomandos:vars]
example=true