Ansible 变量名 `environment` 是保留的吗? [英] Ansible variable name `environment` is reserved?

查看:28
本文介绍了Ansible 变量名 `environment` 是保留的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天遇到了一个奇怪的情况.我在剧本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.

推荐答案

我在 Google 群组:

I found a statement regarding environment in the Google group:

是的,environment 是一个受限制的关键字.最初具体在剧本,但它被注入到跑步者中:

Yes, environment is a restricted keyword. Initially specific within playbooks, but it gets injected in the runner:

inject['environment'] = self.environment

所以它会清除变量清单设置的任何值.

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.

这篇关于Ansible 变量名 `environment` 是保留的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆