# Required variables in var in inline vars

**URL:** <https://forum.ansible.com/t/required-variables-in-var-in-inline-vars/19256>\
**Category:** Ansible Project\
**Created:** [September 14, 2015, 10:18am UTC](https://forum.ansible.com/t/required-variables-in-var-in-inline-vars/19256 "2015-09-14T10:18:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Wade](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@Andrew\_Wade](https://forum.ansible.com/u/Andrew_Wade)\
**Post date:** [September 14, 2015, 10:18am UTC](https://forum.ansible.com/t/required-variables-in-var-in-inline-vars/19256/1 "2015-09-14T10:18:40Z")

</div>

Hey,

(I’m using Ansible 1.9.2)

I’ve got a playbook like this:

`

- hosts:  
vars:  
var\_required\_by\_role:
- name: “{{ variable }}”  
user: “foo”  
roles:
- myrole

`

My issue is that no error is raised if ‘variable’ is undefined; Ansible outputs a changed line like:

=\> … ‘name’: u’{# variable #}’

I’m constructing a more complex variable form a simple value passed in with -e and I don’t want to define the complex variable on the command line.

Is there a better way to do this, or to force error checking? I tried the mandatory filter, but I don’t think it gets parsed.

Thanks.

---

<div class="post-metadata">

**Author:** ![Frank\_Perks](https://avatars.discourse-cdn.com/v4/letter/f/90ced4/32.png) [@Frank\_Perks](https://forum.ansible.com/u/Frank_Perks)\
**Post date:** [September 14, 2015, 4:03pm UTC](https://forum.ansible.com/t/required-variables-in-var-in-inline-vars/19256/2 "2015-09-14T16:03:50Z")

</div>

You make an variable mandatory to throw an error if a var is not defined:

`

- hosts:  
vars:  
var\_required\_by\_role:
- name: “{{ variable | mandatory }}”  
user: “foo”  
roles:
- myrole  
`

Alternatively you can edit ansible.cfg to change this setting to True

`  
error\_on\_undefined\_vars = False

`
