I would like to change the variable format, if it gets passed as a blank.
When running the playbook:
`
ansible-playbook -vvv -i host deploy.yml --extra-vars “dal_version=”
`
Which has a task (where I want to change the context of a blank variable):
`
-
set_fact:
dal_version: ‘hello’
when: dal_version == “” -
debug:
msg: Dal version is {{ dal_version }}
`
I should expect to see the new format of the variable, in this case “hello”. However, I continue to see the blank.
However, I see the following Result:
`
TASK [deploy : set_fact] *****************************************************************************************************
task path:
ok: [linux.local] => {
“ansible_facts”: {
“dal_version”: “hello”
},
“changed”: false
}
TASK [deploy : debug] ********************************************************************************************************
task path:
ok: [linux.local] => {
“msg”: "Dal version is "
}
`
However, if I change the new variable to dal_version2, I see the correct result:
When running the playbook:
`
ansible-playbook -vvv -i host deploy.yml --extra-vars “dal_version=”
`
Which has the task
`
-
set_fact:
dal_version2: ‘hello’
when: dal_version == “” -
debug:
msg: Dal version is {{ dal_version2 }}
`
Result is as expected.
`
TASK [deploy : set_fact] *****************************************************************************************************
task path:
ok: [linux.local] => {
“ansible_facts”: {
“dal_version2”: “hello”
},
“changed”: false
}
TASK [deploy : debug] ********************************************************************************************************
task path:
ok: [linux.local] => {
“msg”: “Dal version is hello”
}
`
Is there a way I can set the same extra-vars variable to something else if it is passed as a blank?
Thanks!
JS