How include argument in task if some variable is defined?

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 }}

Maybe this will help you. http://docs.ansible.com/ansible/playbooks_filters.html#omitting-undefined-variables-and-parameters

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.