Thanks Walter
On Wednesday, July 26, 2023 at 6:31:15 PM UTC+5:30 Rowe, Walter P. (Fed)
wrote:
> 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
>
>
> *Execution: note the first test does not provide an extra_var value for
> rebootSetting, while the second and third do provide one.*
>
>
> *% 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
>
>
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123 <(202)%20355-4123>
>
> On Jul 26, 2023, at 8:39 AM, Veera <[email protected]> wrote:
>
> Hi,
>
> I have the below variable defined in my playbook.
> reboot_option:
> - IfRequired
> - Never
> - Always
>
> while calling the same variable from the playbook , the value
> "IfRequired' must be the default.
> "rebootSetting": "{{ reboot_option | default(Ifrequired) }}"
>
> While executing the playbook without extra-vars reboot_option then by
> "ifrequired " need to the default,.
> If the playbook is executed with -e "reboot_option=Never" or "Always"
> then it should select the given option.
>
> how to call the dictionary items with default as "Ifrequired"?
> Or I have to declare the variables in a different way ?
>
>
>
>
>
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/90154402-8d8b-4041-8a9f-d1bbea023a6en%40googlegroups.com
>
> <https://groups.google.com/d/msgid/ansible-project/90154402-8d8b-4041-8a9f-d1bbea023a6en%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/eef714c1-9047-488a-a3aa-cf0311bf5985n%40googlegroups.com.