<h5 dir="auto">Issue Type:</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<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 = /opt/tmp/vagrant/homelab/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">$ ansible --version
ansible 2.0.0.2
  config file = /opt/tmp/vagrant/homelab/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">Ansible Configuration:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ egrep -v '(^$|^#)' ansible.cfg 
[defaults] 
roles_path = ./
transport = ssh
forks=5
callback_plugins = callback_plugins/
[ssh_connection]
ssh_args = -o ForwardAgent=yes
pipelining=True
$ env |grep ANSIBLE_
$"><pre class="notranslate"><code class="notranslate">$ egrep -v '(^$|^#)' ansible.cfg 
[defaults] 
roles_path = ./
transport = ssh
forks=5
callback_plugins = callback_plugins/
[ssh_connection]
ssh_args = -o ForwardAgent=yes
pipelining=True
$ env |grep ANSIBLE_
$
</code></pre></div>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Ubuntu trusty host. guest is trusty or centos7</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Since upgrade to ansible2, part of my roles are failing because some variables which are set as ansible_ssh_user in defaults/main.yml are  seen empty</p>
<p dir="auto">See also<br>
<a href="https://github.com/debops/ansible-libvirtd/commit/6f3916bd3965c62d8f84c87c9283d9ca6d2ada50">https://github.com/debops/ansible-libvirtd/commit/6f3916bd3965c62d8f84c87c9283d9ca6d2ada50</a><br>
<a href="http://docs.debops.org/en/latest/ansible/roles/ansible-atd/docs/defaults.html" rel="nofollow">http://docs.debops.org/en/latest/ansible/roles/ansible-atd/docs/defaults.html</a><br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="129603462" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/14195" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/14195/hovercard" href="https://github.com/ansible/ansible/issues/14195">#14195</a></p>
<p dir="auto">Possibly because of<br>
"* We do not ignore the explicitly set login user for ssh when it matches the 'current user' anymore, this allows overriding .ssh/config when it is set<br>
explicitly. Leaving it unset will still use the same user and respect .ssh/config. This also means ansible_ssh_user can now return a None value."<br>
in <a href="https://raw.githubusercontent.com/ansible/ansible/v2.0.0.0-1/CHANGELOG.md" rel="nofollow">https://raw.githubusercontent.com/ansible/ansible/v2.0.0.0-1/CHANGELOG.md</a></p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">below playbook reproduce my issue<br>
with first definition of myuser, last task fails with myuser appearing empty even if before, the debug displayed vagrant user correctly<br>
the other definition are setting the value during all the playbook with my host user which is different, so no good.<br>
Got a temporary quick fix but clearly not ideal</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- hosts: test
  vars:
    - myuser: &quot;{{ ansible_ssh_user }}&quot;
## got lookup on host, not on guest...
#    - myuser: '{{ (ansible_ssh_user
#            if (ansible_ssh_user | bool and
#            ansible_ssh_user != &quot;root&quot;)
#            else lookup(&quot;env&quot;, &quot;USER&quot;)) }}'
## got lookup on host, not on guest...
#    - myuser: &quot;{{ ansible_user | default(lookup('env', 'USER'), True) }}&quot;
    - mygopath: &quot;/home/{{ myuser }}/go&quot;
  tasks:
    - debug: var=myuser
    - debug: var=ansible_ssh_user
    - debug: var=ansible_user
    - debug: var=remote_user
    - fail: msg=&quot;myuser is not defined or empty!&quot;
      when: myuser is not defined or myuser == ''

    - stat: path=&quot;/home/{{ myuser }}/.bashrc&quot;
      register: homemiguser
    - debug: var=homemiguser
    - debug: var=myuser
## quick fix
#    - set_fact:
#        myuser: 'vagrant'
#        when: myuser is not defined or myuser != &quot;&quot; or myuser == null
    - debug: var=myuser
    - name: Update PATH and GOPATH in bashrc - myuser
      lineinfile:
        dest: &quot;{{ item.d }}&quot;
        line: &quot;{{ item.l }}&quot;
        regexp: &quot;{{ item.r }}&quot;
        insertafter: EOF 
        state: present
        create: False
      with_items:
        - { d: &quot;/home/{{ myuser }}/.bashrc&quot;, r: &quot;go/bin&quot;, l: 'export PATH=$PATH\:/usr/local/go/bin' }
        - { d: &quot;/home/{{ myuser }}/.bashrc&quot;, r: &quot;GOPATH={{ mygopath }}&quot;, l: &quot;export GOPATH={{ mygopath }}&quot; }
    ## on centos7, missing this for fpm
        - { d: &quot;/home/{{ myuser }}/.bashrc&quot;, r: &quot;/usr/local/bin&quot;, l: 'export PATH=$PATH\:/usr/local/bin' }
      when: homemiguser.stat.exists"><pre class="notranslate"><code class="notranslate">- hosts: test
  vars:
    - myuser: "{{ ansible_ssh_user }}"
## got lookup on host, not on guest...
#    - myuser: '{{ (ansible_ssh_user
#            if (ansible_ssh_user | bool and
#            ansible_ssh_user != "root")
#            else lookup("env", "USER")) }}'
## got lookup on host, not on guest...
#    - myuser: "{{ ansible_user | default(lookup('env', 'USER'), True) }}"
    - mygopath: "/home/{{ myuser }}/go"
  tasks:
    - debug: var=myuser
    - debug: var=ansible_ssh_user
    - debug: var=ansible_user
    - debug: var=remote_user
    - fail: msg="myuser is not defined or empty!"
      when: myuser is not defined or myuser == ''

    - stat: path="/home/{{ myuser }}/.bashrc"
      register: homemiguser
    - debug: var=homemiguser
    - debug: var=myuser
## quick fix
#    - set_fact:
#        myuser: 'vagrant'
#        when: myuser is not defined or myuser != "" or myuser == null
    - debug: var=myuser
    - name: Update PATH and GOPATH in bashrc - myuser
      lineinfile:
        dest: "{{ item.d }}"
        line: "{{ item.l }}"
        regexp: "{{ item.r }}"
        insertafter: EOF 
        state: present
        create: False
      with_items:
        - { d: "/home/{{ myuser }}/.bashrc", r: "go/bin", l: 'export PATH=$PATH\:/usr/local/go/bin' }
        - { d: "/home/{{ myuser }}/.bashrc", r: "GOPATH={{ mygopath }}", l: "export GOPATH={{ mygopath }}" }
    ## on centos7, missing this for fpm
        - { d: "/home/{{ myuser }}/.bashrc", r: "/usr/local/bin", l: 'export PATH=$PATH\:/usr/local/bin' }
      when: homemiguser.stat.exists
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">myuser should be set once and for all to remote user (in my case vagrant)</p>
<h5 dir="auto">Actual Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible-playbook -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory --limit lcentral test-user.yml

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [lcentral]

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    &quot;myuser&quot;: &quot;vagrant&quot;
}

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    &quot;ansible_ssh_user&quot;: &quot;vagrant&quot;
}

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    &quot;ansible_user&quot;: &quot;vagrant&quot;
}

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    &quot;remote_user&quot;: &quot;VARIABLE IS NOT DEFINED!&quot;
}

TASK [fail] ********************************************************************
skipping: [lcentral]

TASK [stat] ********************************************************************
ok: [lcentral]

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    &quot;homemiguser&quot;: {
        &quot;changed&quot;: false, 
        &quot;stat&quot;: {
            &quot;atime&quot;: 1456064521.0777302, 
            &quot;checksum&quot;: &quot;c76cbba3f0b550225c6dc31bf763a9415dc35934&quot;, 
            &quot;ctime&quot;: 1456064489.9417298, 
            &quot;dev&quot;: 2049, 
            &quot;exists&quot;: true, 
[...]
            &quot;path&quot;: &quot;/home/vagrant/.bashrc&quot;, 
            &quot;pw_name&quot;: &quot;vagrant&quot;, 
[...]
        }
    }
}

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    &quot;myuser&quot;: &quot;vagrant&quot;
}

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    &quot;myuser&quot;: &quot;vagrant&quot;
}

TASK [Update PATH and GOPATH in bashrc - myuser] *******************************
failed: [lcentral] =&gt; (item={u'r': u'go/bin', u'd': u'/home//.bashrc', u'l': u'export PATH=$PATH\\:/usr/local/go/bin'}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;d&quot;: &quot;/home//.bashrc&quot;, &quot;l&quot;: &quot;export PATH=$PATH\\:/usr/local/go/bin&quot;, &quot;r&quot;: &quot;go/bin&quot;}, &quot;msg&quot;: &quot;Destination /home//.bashrc does not exist !&quot;, &quot;rc&quot;: 257}
failed: [lcentral] =&gt; (item={u'r': u'GOPATH=/home//go', u'd': u'/home//.bashrc', u'l': u'export GOPATH=/home//go'}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;d&quot;: &quot;/home//.bashrc&quot;, &quot;l&quot;: &quot;export GOPATH=/home//go&quot;, &quot;r&quot;: &quot;GOPATH=/home//go&quot;}, &quot;msg&quot;: &quot;Destination /home//.bashrc does not exist !&quot;, &quot;rc&quot;: 257}
failed: [lcentral] =&gt; (item={u'r': u'/usr/local/bin', u'd': u'/home//.bashrc', u'l': u'export PATH=$PATH\\:/usr/local/bin'}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;d&quot;: &quot;/home//.bashrc&quot;, &quot;l&quot;: &quot;export PATH=$PATH\\:/usr/local/bin&quot;, &quot;r&quot;: &quot;/usr/local/bin&quot;}, &quot;msg&quot;: &quot;Destination /home//.bashrc does not exist !&quot;, &quot;rc&quot;: 257}

PLAY RECAP *********************************************************************
lcentral                   : ok=9    changed=0    unreachable=0    failed=1 "><pre class="notranslate"><code class="notranslate">$ ansible-playbook -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory --limit lcentral test-user.yml

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [lcentral]

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    "myuser": "vagrant"
}

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    "ansible_ssh_user": "vagrant"
}

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    "ansible_user": "vagrant"
}

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    "remote_user": "VARIABLE IS NOT DEFINED!"
}

TASK [fail] ********************************************************************
skipping: [lcentral]

TASK [stat] ********************************************************************
ok: [lcentral]

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    "homemiguser": {
        "changed": false, 
        "stat": {
            "atime": 1456064521.0777302, 
            "checksum": "c76cbba3f0b550225c6dc31bf763a9415dc35934", 
            "ctime": 1456064489.9417298, 
            "dev": 2049, 
            "exists": true, 
[...]
            "path": "/home/vagrant/.bashrc", 
            "pw_name": "vagrant", 
[...]
        }
    }
}

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    "myuser": "vagrant"
}

TASK [debug] *******************************************************************
ok: [lcentral] =&gt; {
    "myuser": "vagrant"
}

TASK [Update PATH and GOPATH in bashrc - myuser] *******************************
failed: [lcentral] =&gt; (item={u'r': u'go/bin', u'd': u'/home//.bashrc', u'l': u'export PATH=$PATH\\:/usr/local/go/bin'}) =&gt; {"failed": true, "item": {"d": "/home//.bashrc", "l": "export PATH=$PATH\\:/usr/local/go/bin", "r": "go/bin"}, "msg": "Destination /home//.bashrc does not exist !", "rc": 257}
failed: [lcentral] =&gt; (item={u'r': u'GOPATH=/home//go', u'd': u'/home//.bashrc', u'l': u'export GOPATH=/home//go'}) =&gt; {"failed": true, "item": {"d": "/home//.bashrc", "l": "export GOPATH=/home//go", "r": "GOPATH=/home//go"}, "msg": "Destination /home//.bashrc does not exist !", "rc": 257}
failed: [lcentral] =&gt; (item={u'r': u'/usr/local/bin', u'd': u'/home//.bashrc', u'l': u'export PATH=$PATH\\:/usr/local/bin'}) =&gt; {"failed": true, "item": {"d": "/home//.bashrc", "l": "export PATH=$PATH\\:/usr/local/bin", "r": "/usr/local/bin"}, "msg": "Destination /home//.bashrc does not exist !", "rc": 257}

PLAY RECAP *********************************************************************
lcentral                   : ok=9    changed=0    unreachable=0    failed=1 
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">docker_container</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.4.1.0
  config file = /home/ubuntu/.ansible.cfg
  configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 20 2017, 18:23:56) [GCC 5.4.0 20160609]"><pre class="notranslate"><code class="notranslate">$ ansible --version
ansible 2.4.1.0
  config file = /home/ubuntu/.ansible.cfg
  configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 20 2017, 18:23:56) [GCC 5.4.0 20160609]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">ANSIBLE_SSH_ARGS(/home/ubuntu/.ansible.cfg) = -o StrictHostKeyChecking=no<br>
DEFAULT_REMOTE_USER(/home/ubuntu/.ansible.cfg) = hoylu<br>
DEFAULT_ROLES_PATH(/home/ubuntu/.ansible.cfg) = [u'/home/ubuntu/ansible-roles']<br>
DEFAULT_SCP_IF_SSH(/home/ubuntu/.ansible.cfg) = True<br>
DEFAULT_TRANSPORT(/home/ubuntu/.ansible.cfg) = ssh</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">NA</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">when a container is started with the 'dns_servers' parameter set, and then the parameter is . removed and the task is run again, one would expect that the container gets re-created with the Docker Dns parameter set to null.</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="- name: &quot;test docker containerr recreate with server_dns&quot;
  hosts:  localhost
  tasks:
    - name: start the test container
      docker_container:
        name: tester
        image: redis
    - name: this should restart the test container
      docker_container:
        name: tester
        image: redis
        dns_servers: &quot;8.8.8.8&quot;
    - name: this should also restart the test container
      docker_container:
        name: tester
        image: redis"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s"><span class="pl-pds">"</span>test docker containerr recreate with server_dns<span class="pl-pds">"</span></span>
  <span class="pl-ent">hosts</span>:  <span class="pl-s">localhost</span>
  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">name</span>: <span class="pl-s">start the test container</span>
      <span class="pl-ent">docker_container</span>:
        <span class="pl-ent">name</span>: <span class="pl-s">tester</span>
        <span class="pl-ent">image</span>: <span class="pl-s">redis</span>
    - <span class="pl-ent">name</span>: <span class="pl-s">this should restart the test container</span>
      <span class="pl-ent">docker_container</span>:
        <span class="pl-ent">name</span>: <span class="pl-s">tester</span>
        <span class="pl-ent">image</span>: <span class="pl-s">redis</span>
        <span class="pl-ent">dns_servers</span>: <span class="pl-s"><span class="pl-pds">"</span>8.8.8.8<span class="pl-pds">"</span></span>
    - <span class="pl-ent">name</span>: <span class="pl-s">this should also restart the test container</span>
      <span class="pl-ent">docker_container</span>:
        <span class="pl-ent">name</span>: <span class="pl-s">tester</span>
        <span class="pl-ent">image</span>: <span class="pl-s">redis</span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">Expected a <code class="notranslate">changed</code> on the task 'this should also restart the container'</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">Got an <code class="notranslate">ok</code> on the task. The container was not restarted despite the configuration being different. Running it in -vvvv mode shows <code class="notranslate">module_args:dns_servers</code> set to null, but that is not applied to the container.</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [test docker containerr recreate with server_dns] ********************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************
ok: [localhost]

TASK [start the test container] *******************************************************************************************************************************
changed: [localhost]

TASK [this should restart the test container] *****************************************************************************************************************
changed: [localhost]

TASK [this should also restart the test container] ************************************************************************************************************
ok: [localhost]

PLAY RECAP ****************************************************************************************************************************************************
localhost                  : ok=4    changed=2    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">PLAY [test docker containerr recreate with server_dns] ********************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************
ok: [localhost]

TASK [start the test container] *******************************************************************************************************************************
changed: [localhost]

TASK [this should restart the test container] *****************************************************************************************************************
changed: [localhost]

TASK [this should also restart the test container] ************************************************************************************************************
ok: [localhost]

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