Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible variable name `environment` is reserved?

Tags:

ansible

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",

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.

like image 580
Vladislav Rastrusny Avatar asked May 03 '15 13:05

Vladislav Rastrusny


1 Answers

I found a statement regarding environment in the Google group:

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.

like image 108
udondan Avatar answered Sep 21 '22 15:09

udondan