title: Ansible: how to compact jinja2 template using conditions
body: <p>I am using ansible 2.1. Most webserver's has one IP only, but some server's has two IPs. Each webserver has special website for internal usage, i have special variable to define which IP is used for this site: if INTERNALWEBSITE_LISTEN_IP is null - used main IP, if not - custom IP from host_vars.</p>
  
  <p>content of <code>roles/web_std/defaults/main.yml</code>:</p>
  
  <pre><code>r_web_std:
    INTERNALWEBSITE_LISTEN_IP: null
  </code></pre>
  
  <p>content on <code>inventory/host_vars/100.200.1.2</code>:</p>
  
  <pre><code>r_web_std:
    INTERNALWEBSITE_LISTEN_IP: "100.200.1.4"
  </code></pre>
  
  <p>(this host has two IP: 100.200.1.2 and 100.200.1.4, and 100.200.1.2 is default IP)</p>
  
  <p>and here is fragment from <code>server.conf.j2</code>:</p>
  
  <pre><code>DocumentRoot /www/{% if r_web_std.INTERNALWEBSITE_LISTEN_IP == null %}{{ ansible_default_ipv4.address }}{% else %}{{ r_web_std.INTERNALWEBSITE_LISTEN_IP }}{% endif %}/www
  ErrorLog /var/log/httpd/{% if r_web_std.INTERNALWEBSITE_LISTEN_IP == null %}{{ ansible_default_ipv4.address }}{% else %}{{ r_web_std.INTERNALWEBSITE_LISTEN_IP }}{% endif %}/error.log
  CustomLog "/var/log/httpd/{% if r_web_std.INTERNALWEBSITE_LISTEN_IP == null %}{{ ansible_default_ipv4.address }}{% else %}{{ r_web_std.INTERNALWEBSITE_LISTEN_IP }}{% endif %}/access.log" combined
  </code></pre>
  
  <p>My eyes!</p>
  
  <p>Is it possible to simplify this?</p>
  
  <pre><code>{% if r_web_std.INTERNALWEBSITE_LISTEN_IP == null %}
  {{ ansible_default_ipv4.address }}
  {% else %}
  {{ r_web_std.INTERNALWEBSITE_LISTEN_IP }}
  {% endif %}
  </code></pre>