Ansible: ERROR! failed to combine variables, expected dicts but got a 'dict' and a 'AnsibleSequence'
I was slowly refactoring my standard playbooks to roles when I encountered this error. It took me a while to figure out what was wrong.
Start: the All-In-One playbook
myplaybook.yml
- hosts: rhel
vars:
...
tasks:
- name: ...
...
This kind of playbook is hard to maintain. Also, some tasks where common to several playbooks, so I've decided to split it into several:
myplaybook.yml
- hosts: rhel
vars:
...
tasks:
- name: ...
include_tasks: path/to/task-1.yml
include_tasks: path/to/task-2.yml
...
This was nice, but I encountered issues with variables that were not seen by sub-tasks. Must be mentioned that sub-tasks should not include the tasks keyword; only a list of tasks.
task-1.yml
- name: ...
...
Here comes the roles
Roles has been precisely designed to split complex tasks into reusable modules.
playbooks
roles
my_custom_role
defaults
main.yml
files
my-cert-ad.pem
handlers
main.yml
meta
main.yml
tasks
main.yml
templates
...
vars
main.yml
Ansible requires a standard directory structure; some of the names (in bold above) are like keywords. I mean: these folders don't have necessarily to exist, but if you create a folder named tasks or vars, the YAML scripts in these directories, they must follow some rules.
And this was precisely my mistake: a script inside the vars folder must not have the vars keyword, only a list of vars.
myvars.yml vars: <- remove this varname: "value" ...


Comments