Reserved variable name `environment` reserved?

Today I have a strange situation. I have named one of my variables in the playbook environment

. If I dump the variables using the command debug

, it shows up fine

   "environment": "development",

      

But if I try to access it from within a script using {{ environment }}

, it is always assigned a value {}

. I renamed it and it worked fine. Why is this? environment

reserved name in Ansible? I checked the dump of the variable - no conflicts with certain vars.

+3


source to share


2 answers


I found an expression about environment

in the google group :

Yes, environment is a limited keyword. Originally playbooks, but it's injected into the runner:

inject['environment'] = self.environment

      

so that it erases any value set by the inventory of vars.



There is a pending function request to warn if reserved variables are being used.

+8


source


Interestingly, Environment

(correct case) can be used, but Environment

(lowercase) not in the way you found out.

I stumbled upon this day when I was accidentally using my existing lowercase environment variable and had fun trying to diagnose the problem.



I would like to use a different name (although I still use it Environment

specifically to remind myself of case sensitivity in variable names).

+2


source







All Articles