I have an ansible role that defines two parameters and a default for the second one.
roles/upstream/tasks/main.yml
:
---
- debug:
msg: "Parameter in upstream is {{param}} and param2 is {{param2}}"
roles/upstream/defaults/main.yml
:
---
param2: []
And then this exemplary play:
---
- name: test
hosts: localhost
roles:
- role: upstream
vars:
param: 21
- role: upstream
vars:
param: 42
param2: test
When I execute this, I see the following:
TASK [Gathering Facts] **********************************************************************************
ok: [localhost]
TASK [upstream : debug] *********************************************************************************
ok: [localhost] => {
"msg": "Parameter in upstream is 21 and param2 is test"
}
TASK [upstream : debug] *********************************************************************************
ok: [localhost] => {
"msg": "Parameter in upstream is 42 and param2 is test"
}
What is the rationale that the second call to the role also overrides the default for param2
for the other call and how to avoid this?