Skip to content

Instantly share code, notes, and snippets.

@reyjrar
Created April 14, 2021 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reyjrar/7fa04172e7851eab5f9236cf7856b391 to your computer and use it in GitHub Desktop.
Save reyjrar/7fa04172e7851eab5f9236cf7856b391 to your computer and use it in GitHub Desktop.
Ansible bug with parameterized roles
PLAY [localhost] ***************************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************
ok: [localhost]
TASK [Running for first] *******************************************************************************************************************
TASK [bar : debug] *************************************************************************************************************************
ok: [localhost] => {
"msg": "var_bar is second"
}
TASK [Running for second] ******************************************************************************************************************
TASK [bar : debug] *************************************************************************************************************************
ok: [localhost] => {
"msg": "var_bar is second"
}
PLAY RECAP *********************************************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
---
- hosts: localhost
connection: local
roles:
- role: foo
vars:
var_foo: 'first'
- role: foo
vars:
var_foo: 'second'
---
# tasks file for bar
- debug:
msg: "var_bar is {{ var_bar }}"
---
# tasks file for foo
- name: "Running for {{ var_foo }}"
include_role:
name: bar
vars:
var_bar: "{{ var_foo }}"
@reyjrar
Copy link
Author

reyjrar commented Apr 14, 2021

Notice the task names for each parameterized role inclusion have the corect value for var_foo.

However, during the execution of the include_role, var_bar is set for both the first and second invocation to the value of var_foo in tthe last instance of the parameterized role.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment