I have a static inventory setup with the hope of applying different roles to different hosts, but am finding that this playbook is not achieving what I would like:
- hosts: “{{target}}”
pre_tasks: - debug: var=role
roles: - “{{role}}”
tasks: - debug: var=role
post_tasks: - debug: var=role
Ultimately with an inventory of:
192.168.1.13 role=test
Executing this playbook:
ansible-playbook -i inventory testrole.yml -e “target=192.168.1.13”
ERROR! ‘role’ is undefined
This persists no matter where I attempt to define that role variable, in inventory, group_vars, host_vars, etc. If I comment out the roles stanza, all the debug tasks report the variable being interpolated correctly no matter how I do it. The only way I have found the role to be variable so far is to define it with --extra-args at the command line.
I this a bug, or am I running into a hard boundary of ansible?