# How to make mandatory variables if variable is defined

**URL:** <https://forum.ansible.com/t/how-to-make-mandatory-variables-if-variable-is-defined/27193>\
**Category:** Ansible Project\
**Created:** [April 5, 2018, 6:57am UTC](https://forum.ansible.com/t/how-to-make-mandatory-variables-if-variable-is-defined/27193 "2018-04-05T06:57:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javier\_Marti](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@Javier\_Marti](https://forum.ansible.com/u/Javier_Marti)\
**Post date:** [April 5, 2018, 6:57am UTC](https://forum.ansible.com/t/how-to-make-mandatory-variables-if-variable-is-defined/27193/1 "2018-04-05T06:57:46Z")

</div>

Hi, I want to make sure before execution of the role that if a variable is defined you have to define another variables, can I do that?

I have a template:

{% if variable1 != ‘’ %}  
variable1 = {{ variable1 }}  
variable2 = {{ variable2 }}  
variable3 = {{ variable3 }}  
{% endif %}

How to make mandatory variable2 and variable3 if variable1 is defined?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 5, 2018, 7:25am UTC](https://forum.ansible.com/t/how-to-make-mandatory-variables-if-variable-is-defined/27193/2 "2018-04-05T07:25:31Z")

</div>

- assert:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;that:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- variable2 is defined  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- variable3 is defined  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: variable1 is defined
