<p dir="auto">Hello I have the below task and fails with "You cannot call a method on a null-valued expression." only when parameter "force" is specified. The "KIT" directory is already created.<br>
Ansible version is 2.0.0.2 on CentOS 6.7. The target operating system is Windows Server 2012 R2.</p>
<p dir="auto">name: Download kit<br>
win_get_url:<br>
force: no<br>
url: 'http://some_random_url/some_random_program.exe'<br>
dest: 'C:\KIT\some_random_program.exe'</p>
<p dir="auto">Thanks!</p>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Feature Idea</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 --version
ansible 2.0.0.2
  config file = 
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">$ ansible --version
ansible 2.0.0.2
  config file = 
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">Ansible Configuration:</h5>
<p dir="auto">No custom configuration.</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Ubuntu 15.04</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">When using <code class="notranslate">shell</code> module with attribute <code class="notranslate">environment</code> defined as <code class="notranslate">{{provided_env|default(omit)}}</code>, the attribute is not omitted and it fails with error "ERROR! environment must be a dictionary, received __omit_place_holder__dd43d6f3183f203e2d5011d3fe7f9d265a37ba74 (&lt;type 'unicode'&gt;)"</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="- hosts: localhost
  vars:
    my_env:
      ENV_VAR: &quot;my env var&quot;
  tasks:
    - name: test with valid env
      shell: echo $ENV_VAR
      environment:
          ENV_VAR: &quot;my env var&quot;
      register: result
    - debug: var=result.stdout

    - name: test with valid env
      shell: echo $ENV_VAR
      environment: &quot;{{my_env}}&quot;
      register: result
    - debug: var=result.stdout

    - name: test with no env
      shell: echo $ENV_VAR
      register: result
    - debug: var=result.stdout

    - name: test with missing env default empty
      shell: echo $ENV_VAR
      environment: &quot;{{unknown_env|default({})}}&quot;
      register: result
    - debug: var=result.stdout

      # Fails with message &quot;ERROR! environment must be a dictionary, received __omit_place_holder__dd43d6f3183f203e2d5011d3fe7f9d265a37ba74 (&lt;type 'unicode'&gt;)&quot;
    - name: test with missing env default omit
      shell: echo $ENV_VAR
      environment: &quot;{{unknown_env|default(omit)}}&quot;
      register: result
    - debug: var=result.stdout

      # Would fail with message &quot;ERROR! 'unknown_env' is undefined&quot; (or better &quot;environment must be a dictionary, received {{unknown_env}}&quot; in ansible 1.9.4)
    - name: test with missing env
      shell: echo $ENV_VAR
      environment: &quot;{{unknown_env}}&quot;
      register: result
    - debug: var=result.stdout"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">localhost</span>
  <span class="pl-ent">vars</span>:
    <span class="pl-ent">my_env</span>:
      <span class="pl-ent">ENV_VAR</span>: <span class="pl-s"><span class="pl-pds">"</span>my env var<span class="pl-pds">"</span></span>
  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">name</span>: <span class="pl-s">test with valid env</span>
      <span class="pl-ent">shell</span>: <span class="pl-s">echo $ENV_VAR</span>
      <span class="pl-ent">environment</span>:
          <span class="pl-ent">ENV_VAR</span>: <span class="pl-s"><span class="pl-pds">"</span>my env var<span class="pl-pds">"</span></span>
      <span class="pl-ent">register</span>: <span class="pl-s">result</span>
    - <span class="pl-ent">debug</span>: <span class="pl-s">var=result.stdout</span>

    - <span class="pl-ent">name</span>: <span class="pl-s">test with valid env</span>
      <span class="pl-ent">shell</span>: <span class="pl-s">echo $ENV_VAR</span>
      <span class="pl-ent">environment</span>: <span class="pl-s"><span class="pl-pds">"</span>{{my_env}}<span class="pl-pds">"</span></span>
      <span class="pl-ent">register</span>: <span class="pl-s">result</span>
    - <span class="pl-ent">debug</span>: <span class="pl-s">var=result.stdout</span>

    - <span class="pl-ent">name</span>: <span class="pl-s">test with no env</span>
      <span class="pl-ent">shell</span>: <span class="pl-s">echo $ENV_VAR</span>
      <span class="pl-ent">register</span>: <span class="pl-s">result</span>
    - <span class="pl-ent">debug</span>: <span class="pl-s">var=result.stdout</span>

    - <span class="pl-ent">name</span>: <span class="pl-s">test with missing env default empty</span>
      <span class="pl-ent">shell</span>: <span class="pl-s">echo $ENV_VAR</span>
      <span class="pl-ent">environment</span>: <span class="pl-s"><span class="pl-pds">"</span>{{unknown_env|default({})}}<span class="pl-pds">"</span></span>
      <span class="pl-ent">register</span>: <span class="pl-s">result</span>
    - <span class="pl-ent">debug</span>: <span class="pl-s">var=result.stdout</span>

      <span class="pl-c"><span class="pl-c">#</span> Fails with message "ERROR! environment must be a dictionary, received __omit_place_holder__dd43d6f3183f203e2d5011d3fe7f9d265a37ba74 (&lt;type 'unicode'&gt;)"</span>
    - <span class="pl-ent">name</span>: <span class="pl-s">test with missing env default omit</span>
      <span class="pl-ent">shell</span>: <span class="pl-s">echo $ENV_VAR</span>
      <span class="pl-ent">environment</span>: <span class="pl-s"><span class="pl-pds">"</span>{{unknown_env|default(omit)}}<span class="pl-pds">"</span></span>
      <span class="pl-ent">register</span>: <span class="pl-s">result</span>
    - <span class="pl-ent">debug</span>: <span class="pl-s">var=result.stdout</span>

      <span class="pl-c"><span class="pl-c">#</span> Would fail with message "ERROR! 'unknown_env' is undefined" (or better "environment must be a dictionary, received {{unknown_env}}" in ansible 1.9.4)</span>
    - <span class="pl-ent">name</span>: <span class="pl-s">test with missing env</span>
      <span class="pl-ent">shell</span>: <span class="pl-s">echo $ENV_VAR</span>
      <span class="pl-ent">environment</span>: <span class="pl-s"><span class="pl-pds">"</span>{{unknown_env}}<span class="pl-pds">"</span></span>
      <span class="pl-ent">register</span>: <span class="pl-s">result</span>
    - <span class="pl-ent">debug</span>: <span class="pl-s">var=result.stdout</span></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto"><code class="notranslate">environment</code> is simply omitted.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [test with valid env] *****************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;result.stdout&quot;: &quot;my env var&quot;
}

TASK [test with valid env] *****************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;result.stdout&quot;: &quot;my env var&quot;
}

TASK [test with no env] ********************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;result.stdout&quot;: &quot;&quot;
}

TASK [test with missing env default empty] *************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;result.stdout&quot;: &quot;&quot;
}

TASK [test with missing env default omit] **************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;result.stdout&quot;: &quot;&quot;
}

TASK [test with missing env] ***************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;result.stdout&quot;: &quot;&quot;
}

PLAY RECAP *********************************************************************
localhost                  : ok=13   changed=6    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [test with valid env] *****************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "result.stdout": "my env var"
}

TASK [test with valid env] *****************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "result.stdout": "my env var"
}

TASK [test with no env] ********************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "result.stdout": ""
}

TASK [test with missing env default empty] *************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "result.stdout": ""
}

TASK [test with missing env default omit] **************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "result.stdout": ""
}

TASK [test with missing env] ***************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "result.stdout": ""
}

PLAY RECAP *********************************************************************
localhost                  : ok=13   changed=6    unreachable=0    failed=0
</code></pre></div>
<h5 dir="auto">Actual Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [test with valid env] *****************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;result.stdout&quot;: &quot;my env var&quot;
}

TASK [test with valid env] *****************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;result.stdout&quot;: &quot;my env var&quot;
}

TASK [test with no env] ********************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;result.stdout&quot;: &quot;&quot;
}

TASK [test with missing env default empty] *************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;result.stdout&quot;: &quot;&quot;
}

TASK [test with missing env default omit] **************************************
fatal: [localhost]: FAILED! =&gt; {&quot;failed&quot;: true, &quot;msg&quot;: &quot;ERROR! environment must be a dictionary, received __omit_place_holder__853b09b8abd224611d49aeb565bc95ac972fd575 (&lt;type 'unicode'&gt;)&quot;}

PLAY RECAP *********************************************************************
localhost                  : ok=9    changed=4    unreachable=0    failed=1"><pre class="notranslate"><code class="notranslate">
PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [test with valid env] *****************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "result.stdout": "my env var"
}

TASK [test with valid env] *****************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "result.stdout": "my env var"
}

TASK [test with no env] ********************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "result.stdout": ""
}

TASK [test with missing env default empty] *************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "result.stdout": ""
}

TASK [test with missing env default omit] **************************************
fatal: [localhost]: FAILED! =&gt; {"failed": true, "msg": "ERROR! environment must be a dictionary, received __omit_place_holder__853b09b8abd224611d49aeb565bc95ac972fd575 (&lt;type 'unicode'&gt;)"}

PLAY RECAP *********************************************************************
localhost                  : ok=9    changed=4    unreachable=0    failed=1
</code></pre></div>