Issue 1:
Issue Type:

Bug Report

Ansible Version:

$ ansible --version
ansible 2.0.0.2
config file = /opt/tmp/vagrant/homelab/ansible.cfg
configured module search path = Default w/o overrides

Ansible Configuration:

$ 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_
$

Environment:

Ubuntu trusty host. guest is trusty or centos7

Summary:

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

See also

https://github.com/debops/ansible-libvirtd/commit/6f3916bd3965c62d8f84c87c9283d9ca6d2ada50

http://docs.debops.org/en/latest/ansible/roles/ansible-atd/docs/defaults.html

#14195

Possibly because of

"* 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

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."

in https://raw.githubusercontent.com/ansible/ansible/v2.0.0.0-1/CHANGELOG.md

Steps To Reproduce:

below playbook reproduce my issue

with first definition of myuser, last task fails with myuser appearing empty even if before, the debug displayed vagrant user correctly

the other definition are setting the value during all the playbook with my host user which is different, so no good.

Got a temporary quick fix but clearly not ideal

- 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

Expected Results:

myuser should be set once and for all to remote user (in my case vagrant)

Actual Results:

$ ansible-playbook -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory --limit lcentral test-user.yml

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

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

TASK [debug] *******************************************************************
ok: [lcentral] => {
"myuser": "vagrant"
}

TASK [debug] *******************************************************************
ok: [lcentral] => {
"ansible_ssh_user": "vagrant"
}

TASK [debug] *******************************************************************
ok: [lcentral] => {
"ansible_user": "vagrant"
}

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

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

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

TASK [debug] *******************************************************************
ok: [lcentral] => {
"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] => {
"myuser": "vagrant"
}

TASK [debug] *******************************************************************
ok: [lcentral] => {
"myuser": "vagrant"
}

TASK [Update PATH and GOPATH in bashrc - myuser] *******************************
failed: [lcentral] => (item={u'r': u'go/bin', u'd': u'/home//.bashrc', u'l': u'export PATH=$PATH\\:/usr/local/go/bin'}) => {"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] => (item={u'r': u'GOPATH=/home//go', u'd': u'/home//.bashrc', u'l': u'export GOPATH=/home//go'}) => {"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] => (item={u'r': u'/usr/local/bin', u'd': u'/home//.bashrc', u'l': u'export PATH=$PATH\\:/usr/local/bin'}) => {"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

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

docker_container

ANSIBLE VERSION

$ 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]

CONFIGURATION

ANSIBLE_SSH_ARGS(/home/ubuntu/.ansible.cfg) = -o StrictHostKeyChecking=no

DEFAULT_REMOTE_USER(/home/ubuntu/.ansible.cfg) = hoylu

DEFAULT_ROLES_PATH(/home/ubuntu/.ansible.cfg) = [u'/home/ubuntu/ansible-roles']

DEFAULT_SCP_IF_SSH(/home/ubuntu/.ansible.cfg) = True

DEFAULT_TRANSPORT(/home/ubuntu/.ansible.cfg) = ssh

OS / ENVIRONMENT

NA

SUMMARY

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.

STEPS TO REPRODUCE

- name: "test docker containerr recreate with server_dns"
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: "8.8.8.8"
- name: this should also restart the test container
docker_container:
name: tester
image: redis

EXPECTED RESULTS

Expected a changed on the task 'this should also restart the container'

ACTUAL RESULTS

Got an ok on the task. The container was not restarted despite the configuration being different. Running it in -vvvv mode shows module_args:dns_servers set to null, but that is not applied to the container.

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