<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Feature Idea</li>
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto"><code class="notranslate">with_dict</code></p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible --version
ansible 2.1.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible --version
ansible 2.1.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Running Ansible from: Arch Linux<br>
Target Host: Centos 7, Arch Linux</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When passing a dictionary via <code class="notranslate">with_dict</code> in a task and using certain portions of it to create values of another dictionary variable, nulls are not being preserved and incorrectly passed as empty string ""</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- hosts: localhost
  gather_facts: no
  vars:
        # defaults (for single nodes)
        param1: &quot;defaultParam1&quot;
        param2: ~
        param3: &quot;&quot;
        param4: []

        # overrides (for multiple nodes)
        nodes:
          node1:
            config_path: /tmp/node1.conf
            config_overrides:
              param1: &quot;node1Param1&quot;
              param2: ~
              param3: &quot;&quot;
              param4: []
          node2:
            config_path: /tmp/node2.conf
            config_overrides:

        # dictionaries to be converted to json in config
        single_node_config:
          Param1: &quot;{{ param1 }}&quot;
          Param2: &quot;{{ param2 }}&quot;
          Param3: &quot;{{ param3 }}&quot;
          Param4: &quot;{{ param4 }}&quot;

        multi_node_config:
          Param1: &quot;{{ item.value.config_overrides.param1 | default(param1) }}&quot;
          Param2: &quot;{{ item.value.config_overrides.param2 | default(param2) }}&quot;
          Param3: &quot;{{ item.value.config_overrides.param3 | default(param3) }}&quot;
          Param4: &quot;{{ item.value.config_overrides.param4 | default(param4) }}&quot;

        # toggle
        enable_multi_nodes: false
  tasks:
        # task for single node
        - name: create config
          copy:
            content: &quot;{{ single_node_config | to_nice_json }}&quot;
            dest: /tmp/single.conf
          when: enable_multi_nodes != true

        # task multi nodes
        - name: create configs
          copy:
            content: &quot;{{ multi_node_config | to_nice_json }}&quot;
            dest: &quot;{{ item.value.config_path }}&quot;
          with_dict: &quot;{{ nodes }}&quot;
          when: enable_multi_nodes == true"><pre class="notranslate"><code class="notranslate">- hosts: localhost
  gather_facts: no
  vars:
        # defaults (for single nodes)
        param1: "defaultParam1"
        param2: ~
        param3: ""
        param4: []

        # overrides (for multiple nodes)
        nodes:
          node1:
            config_path: /tmp/node1.conf
            config_overrides:
              param1: "node1Param1"
              param2: ~
              param3: ""
              param4: []
          node2:
            config_path: /tmp/node2.conf
            config_overrides:

        # dictionaries to be converted to json in config
        single_node_config:
          Param1: "{{ param1 }}"
          Param2: "{{ param2 }}"
          Param3: "{{ param3 }}"
          Param4: "{{ param4 }}"

        multi_node_config:
          Param1: "{{ item.value.config_overrides.param1 | default(param1) }}"
          Param2: "{{ item.value.config_overrides.param2 | default(param2) }}"
          Param3: "{{ item.value.config_overrides.param3 | default(param3) }}"
          Param4: "{{ item.value.config_overrides.param4 | default(param4) }}"

        # toggle
        enable_multi_nodes: false
  tasks:
        # task for single node
        - name: create config
          copy:
            content: "{{ single_node_config | to_nice_json }}"
            dest: /tmp/single.conf
          when: enable_multi_nodes != true

        # task multi nodes
        - name: create configs
          copy:
            content: "{{ multi_node_config | to_nice_json }}"
            dest: "{{ item.value.config_path }}"
          with_dict: "{{ nodes }}"
          when: enable_multi_nodes == true
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="cat /tmp/single.conf /tmp/node1.conf  /tmp/node2.conf
{
    &quot;Param1&quot;: &quot;defaultParam1&quot;,
    &quot;Param2&quot;: null,
    &quot;Param3&quot;: &quot;&quot;,
    &quot;Param4&quot;: []
}
{
    &quot;Param1&quot;: &quot;node1Param1&quot;,
    &quot;Param2&quot;: null,
    &quot;Param3&quot;: &quot;&quot;,
    &quot;Param4&quot;: []
}
{
    &quot;Param1&quot;: &quot;defaultParam1&quot;,
    &quot;Param2&quot;: null,
    &quot;Param3&quot;: &quot;&quot;,
    &quot;Param4&quot;: []
}"><pre class="notranslate"><code class="notranslate">cat /tmp/single.conf /tmp/node1.conf  /tmp/node2.conf
{
    "Param1": "defaultParam1",
    "Param2": null,
    "Param3": "",
    "Param4": []
}
{
    "Param1": "node1Param1",
    "Param2": null,
    "Param3": "",
    "Param4": []
}
{
    "Param1": "defaultParam1",
    "Param2": null,
    "Param3": "",
    "Param4": []
}
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="cat /tmp/single.conf /tmp/node1.conf  /tmp/node2.conf
{
    &quot;Param1&quot;: &quot;defaultParam1&quot;,
    &quot;Param2&quot;: null,
    &quot;Param3&quot;: &quot;&quot;,
    &quot;Param4&quot;: []
}
{
    &quot;Param1&quot;: &quot;node1Param1&quot;,
    &quot;Param2&quot;: &quot;&quot;,
    &quot;Param3&quot;: &quot;&quot;,
    &quot;Param4&quot;: []
}
{
    &quot;Param1&quot;: &quot;defaultParam1&quot;,
    &quot;Param2&quot;: &quot;&quot;,
    &quot;Param3&quot;: &quot;&quot;,
    &quot;Param4&quot;: []
}"><pre class="notranslate"><code class="notranslate">cat /tmp/single.conf /tmp/node1.conf  /tmp/node2.conf
{
    "Param1": "defaultParam1",
    "Param2": null,
    "Param3": "",
    "Param4": []
}
{
    "Param1": "node1Param1",
    "Param2": "",
    "Param3": "",
    "Param4": []
}
{
    "Param1": "defaultParam1",
    "Param2": "",
    "Param3": "",
    "Param4": []
}
</code></pre></div>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">None becomes <code class="notranslate">""</code> when assigned to variable.</p>
<p dir="auto">A comparison between a variable and what was assigned to it will return <code class="notranslate">false</code>.</p>
<p dir="auto">Ran into this while using <code class="notranslate">lookup('file', '/nonexistent', errors='ignore')</code> - had to change a <code class="notranslate">when:</code> condition depending on whether comparing the lookup, or a variable with the lookup result.</p>
<h5 dir="auto">ISSUE TYPE</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">core</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.7.0.dev0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/foo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0]"><pre class="notranslate"><code class="notranslate">ansible 2.7.0.dev0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/foo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">N/A</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- set_fact:
    foo: &quot;{{ None }}&quot;
- debug:
    msg: &quot;{{ foo == None }}&quot;
- debug:
    msg: &quot;{{ foo == '' }}&quot;"><pre class="notranslate">- <span class="pl-ent">set_fact</span>:
    <span class="pl-ent">foo</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ None }}<span class="pl-pds">"</span></span>
- <span class="pl-ent">debug</span>:
    <span class="pl-ent">msg</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ foo == None }}<span class="pl-pds">"</span></span>
- <span class="pl-ent">debug</span>:
    <span class="pl-ent">msg</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ foo == '' }}<span class="pl-pds">"</span></span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto"><code class="notranslate">true</code>, <code class="notranslate">false</code></p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto"><code class="notranslate">false</code>, <code class="notranslate">true</code></p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK [debug] **********************************************************************************************************************************************************************************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: false
}

TASK [debug] **********************************************************************************************************************************************************************************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: true
}"><pre class="notranslate"><code class="notranslate">TASK [debug] **********************************************************************************************************************************************************************************************************************************
ok: [localhost] =&gt; {
    "msg": false
}

TASK [debug] **********************************************************************************************************************************************************************************************************************************
ok: [localhost] =&gt; {
    "msg": true
}
</code></pre></div>