问题描述
我今天有一个奇怪的情况.我在剧本 environment
中调用了我的变量之一.如果我使用 debug
指令转储变量,则显示为正常
I've got a strange situation today. I called one of my variables in a playbook environment
. If I dump variables using debug
instruction, it is shown ok
"environment": "development",
但是,如果我尝试使用 {{environment}}
从脚本中访问它,则始终会为其分配一个 {}
值.我重命名它,它工作正常.这是为什么? environment
是Ansible中的保留名称吗?我检查了变量转储-与定义的变量没有冲突.
But if I try to access it from a script using {{ environment }}
it is always assigned a value of {}
. I renamed it and it worked ok. Why is that? Is environment
a reserved name in Ansible? I checked variable dump - there is no clashes with defined vars.
推荐答案
我在:
inject['environment'] = self.environment
因此它将清除由vars清单设置的任何值.
so it will erase whatever value was set by inventory of vars.
还有一个尚未解决的功能请求,用于警告是否使用了保留变量.
There is a yet unaddressed feature request to warn if reserved variables are used.
这篇关于变量名`environment`是否被保留?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!