Skip to content

Instantly share code, notes, and snippets.

@halberom
Last active September 21, 2017 11:35
Show Gist options
  • Save halberom/2c9aa046f63b096f78b26401a11e78d4 to your computer and use it in GitHub Desktop.
Save halberom/2c9aa046f63b096f78b26401a11e78d4 to your computer and use it in GitHub Desktop.
ansible - broken role vars?
# This one works with the include_/import_ interestingly
---
- hosts: localhost
gather_facts: False
connection: local
vars:
rolename: test2
roles:
- test1
# roles/test1/tasks/main.yml
---
- debug:
msg: "in {{ role_path }}"
- debug:
msg: "{{ rolename }}"
# If either of these are uncommented, no tasks run, and you get an immediate
# ERROR! 'rolename' is undefined
#
#- import_role:
# name: "{{ rolename }}"
#- include_role:
# name: "{{ rolename }}"
PLAY [localhost] *********************************************************************************************************************
TASK [test1 : debug] *****************************************************************************************************************
ok: [localhost] => {
"msg": "in /private/tmp/ansible/roles/test1"
}
TASK [test1 : debug] *****************************************************************************************************************
ok: [localhost] => {
"msg": "test2"
}
PLAY RECAP ***************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
# This one does not work
---
- hosts: localhost
gather_facts: False
connection: local
roles:
- { role: test1, rolename: test2 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment