# Variable to be selected from the options

**URL:** <https://forum.ansible.com/t/variable-to-be-selected-from-the-options/38262>\
**Category:** Ansible Project\
**Created:** [July 26, 2023, 12:39pm UTC](https://forum.ansible.com/t/variable-to-be-selected-from-the-options/38262 "2023-07-26T12:39:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [July 26, 2023, 12:39pm UTC](https://forum.ansible.com/t/variable-to-be-selected-from-the-options/38262/1 "2023-07-26T12:39:40Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [July 26, 2023, 1:00pm UTC](https://forum.ansible.com/t/variable-to-be-selected-from-the-options/38262/2 "2023-07-26T13:00:58Z")

</div>

Using ansible’s order of precedence you can set the default value in the playbook and override it with extra\_vars.

**override.yaml:**

---

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [July 26, 2023, 2:44pm UTC](https://forum.ansible.com/t/variable-to-be-selected-from-the-options/38262/3 "2023-07-26T14:44:35Z")

</div>

Thanks Walter
