# Is there a way to require a variable be defined for a playbook or role?

**URL:** <https://forum.ansible.com/t/is-there-a-way-to-require-a-variable-be-defined-for-a-playbook-or-role/12849>\
**Category:** Ansible Project\
**Created:** [May 22, 2013, 7:31pm UTC](https://forum.ansible.com/t/is-there-a-way-to-require-a-variable-be-defined-for-a-playbook-or-role/12849 "2013-05-22T19:31:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Golden](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@David\_Golden](https://forum.ansible.com/u/David_Golden)\
**Post date:** [May 22, 2013, 7:31pm UTC](https://forum.ansible.com/t/is-there-a-way-to-require-a-variable-be-defined-for-a-playbook-or-role/12849/1 "2013-05-22T19:31:45Z")

</div>

Is there a way to specify a variable as “required”? E.g. a parameter for a role that _must_ be set?

(Other than inserting a fail task when the variable is not defined.)

David

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 22, 2013, 8:08pm UTC](https://forum.ansible.com/t/is-there-a-way-to-require-a-variable-be-defined-for-a-playbook-or-role/12849/2 "2013-05-22T20:08:32Z")

</div>

There isn’t, though this will work just fine:

fail: msg=‘missing required variables’  
when: not (foo is defined and bar is defined and baz is defined)
