title: How to add a key/value to a dict in an ansible playbook, conditional
body: <p>Let's say I want to add <code>InterestingVar</code> dict key and the associated value when the variable <code>test_var</code> exists (passed with <code>-e in command line</code>), how can I do that ?</p>
  
  <pre><code># ansible-playbook ./add_to_dict_on_condition.yml -i 127.0.0.1, -e env=test -e test_var=123
  - hosts: localhost
    gather_facts: no
    vars:
      - tags:
          InterestingVar: "{{test_var}}" # How to omit this line if test_var == '' ?
          Name: xxx
          Env: "{{ env }}"
  
    tasks:
      - debug: var=tags
  </code></pre>
  
  <p>I tested </p>
  
  <pre><code> InterestingVar: "{{test_var|default(omit)}}
  </code></pre>
  
  <p>but I get :</p>
  
  <pre><code>"InterestingVar": "__omit_place_holder__caca01e207397883640613b08e8ce3a8fbdd6"
  </code></pre>
  
  <p>instead of nothing.</p>
  
  <p>Any help will be greatly appreciated.</p>
  
  <p>I use <code>ansible 1.8</code></p>