Using ansible's order of precedence you can set the default value in the playbook and override it with extra_vars.
override.yaml:
---
- name: test overriding playbook variable
hosts: all
become: false
gather_facts: false
vars:
rebootSetting: "ifRequired"
tasks:
- name: reboot setting
debug: var=rebootSetting
% ansible-playbook -i localhost, override.yaml
PLAY [test overriding playbook variable] *******************************************************************************
TASK [reboot setting] **************************************************************************************************
ok: [localhost] => {
"rebootSetting": "ifRequired"
}
PLAY RECAP *************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
% ansible-playbook -i localhost, override.yaml -e rebootSetting=Never
PLAY [test overriding playbook variable] *******************************************************************************
TASK [reboot setting] **************************************************************************************************
ok: [localhost] => {
"rebootSetting": "Never"
}
PLAY RECAP *************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
% ansible-playbook -i localhost, override.yaml -e rebootSetting=Always
PLAY [test overriding playbook variable] *******************************************************************************
TASK [reboot setting] **************************************************************************************************
ok: [localhost] => {
"rebootSetting": "Always"
}
PLAY RECAP *************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/90154402-8d8b-4041-8a9f-d1bbea023a6en%40googlegroups.com.