So I had a role where I needed to define lots of variables. I decided to split them over multiple files like this:
my_app/defaults/main/
main.yml
another.yml
yet_another.yml
Tinkering with my shiny new role I moved all of the variables from
yet_another.yml
to group_vars
. Being cautious, I just commented
them out.
I ran my role and got:
TASK [include_role : my_app]
***********************************************************************
ERROR! failed to combine variables, expected dicts but
got a 'NoneType' and a 'AnsibleMapping':
null
Trying to find out which of the variables caused the issue, I commented them out one by one. When I arrived at the last variable in the file, the role failed. Aha! Found the culprit. Or so I thought.
Then the search for the misspelled variable began. To no avail.
Okay, maybe the var does not properly get propagated from group_vars?
$ ansible-inventory --graph my_app --vars -i environments/mine/ | less
[...]
| |--{my_app_default_permission = read-write}
| |--{my_app_default_user_role = Super admin role}
Nope, it's right there, wether I comment out the variable or not, with the expected values. Hm.
-
Comment it out, and another variable back in. Role runs fine. What is worng here?
-
Add a variable that is used nowhere in the role instead, role runs fine. What?
stupid_unused_var: nothing
-
move
yet_another.yml
toyet_another.yml.bak
and the role runs. Waiiiit... -
add a new variables file with nothing but
---
and a comment: role fails.
Head -> Desk.
Variable files in default/main/whatever.yml
need to contain more than
just the three dashes declaring that this is a yaml file and a couple
of comments.
---
# just a comment
# and nothing more
This will be interpreted as a null
-value by Ansible (2.10 in my case), which will
entail all sorts of weird errors, that are really not what they look like.