# How include argument in task if some variable is defined?

**URL:** <https://forum.ansible.com/t/how-include-argument-in-task-if-some-variable-is-defined/19987>\
**Category:** Ansible Project\
**Created:** [December 11, 2015, 7:43am UTC](https://forum.ansible.com/t/how-include-argument-in-task-if-some-variable-is-defined/19987 "2015-12-11T07:43:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![viatoriche](https://avatars.discourse-cdn.com/v4/letter/v/ea5d25/32.png) [@viatoriche](https://forum.ansible.com/u/viatoriche)\
**Post date:** [December 11, 2015, 7:43am UTC](https://forum.ansible.com/t/how-include-argument-in-task-if-some-variable-is-defined/19987/1 "2015-12-11T07:43:49Z")

</div>

Example:

- name: Update databases  
postgresql\_db:  
name={{ name }}  
…  
login\_host={{ login\_host }} {% if login\_host is defined %}  
…

→   
vars:  
login\_host: “localhost”

postgresql\_db:  
name={{ name }}  
login\_host={{ login\_host }}

or  
vars: empty

postgresql\_db:  
name={{ name }}

---

<div class="post-metadata">

**Author:** ![vadimv\_Vatlin](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vadimv\_Vatlin](https://forum.ansible.com/u/vadimv_Vatlin)\
**Post date:** [December 20, 2015, 8:22am UTC](https://forum.ansible.com/t/how-include-argument-in-task-if-some-variable-is-defined/19987/2 "2015-12-20T08:22:11Z")

</div>

Maybe this will help you. [http://docs.ansible.com/ansible/playbooks\_filters.html#omitting-undefined-variables-and-parameters](http://docs.ansible.com/ansible/playbooks_filters.html#omitting-undefined-variables-and-parameters)

---

<div class="post-metadata">

**Author:** ![chrismeyersfsu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chrismeyersfsu/32/1016_2.png) [@chrismeyersfsu](https://forum.ansible.com/u/chrismeyersfsu)\
**Post date:** [December 31, 2015, 10:37pm UTC](https://forum.ansible.com/t/how-include-argument-in-task-if-some-variable-is-defined/19987/3 "2015-12-31T22:37:09Z")

</div>

viatoriche,

Two solutions.

1. Code two tasks. One with login\_host param, one without. Use when to check if the login\_host is defined or not defined. The idea is two execute one task bu t not the other depending on the variable in question.

2. Assign login\_host a "good" default. In your case it would seem localhost is a good default.
