template module: Failed to get information on remote file : Connection closed

Hi,

with ansible v2.4.2.0 I have a problem on some hosts with the template module:

TASK [etc_hosts : generate /etc/hosts for this domain] ************************************************************************************************************************************************************************************** task path: /home/rdxmb/repos/docker-swarm/roles/etc_hosts/tasks/main.yml:2 <docker2> ESTABLISH SSH CONNECTION FOR USER: None <docker2> SSH: EXEC ssh -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=50 docker2 '/bin/sh -c '"'"'( umask 77 && mkdir -p " echo $HOME/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861 " && echo ansible-tmp-1516637919.08-250152219503861=" echo $HOME/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861 " ) && sleep 0'"'"'' <docker3> ESTABLISH SSH CONNECTION FOR USER: None <docker3> SSH: EXEC ssh -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=50 docker3 '/bin/sh -c '"'"'( umask 77 && mkdir -p " echo $HOME/.ansible/tmp/ansible-tmp-1516637919.09-157549027250555 " && echo ansible-tmp-1516637919.09-157549027250555=" echo $HOME/.ansible/tmp/ansible-tmp-1516637919.09-157549027250555 " ) && sleep 0'"'"'' <docker3> (0, 'ansible-tmp-1516637919.09-157549027250555=/root/.ansible/tmp/ansible-tmp-1516637919.09-157549027250555\n', '') <docker2> (0, 'ansible-tmp-1516637919.08-250152219503861=/root/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861\n', '') Using module file /home/rdxmb/.local/lib/python2.7/site-packages/ansible/modules/files/stat.py Using module file /home/rdxmb/.local/lib/python2.7/site-packages/ansible/modules/files/stat.py <docker3> PUT /tmp/tmpX12xW0 TO /root/.ansible/tmp/ansible-tmp-1516637919.09-157549027250555/stat.py <docker2> PUT /tmp/tmpThZUDh TO /root/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861/stat.py <docker3> SSH: EXEC scp -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=50 /tmp/tmpX12xW0 '[docker3]:/root/.ansible/tmp/ansible-tmp-1516637919.09-157549027250555/stat.py' <docker2> SSH: EXEC scp -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=50 /tmp/tmpThZUDh '[docker2]:/root/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861/stat.py' <docker3> (0, '', '') <docker3> ESTABLISH SSH CONNECTION FOR USER: None <docker3> SSH: EXEC ssh -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=50 docker3 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1516637919.09-157549027250555/ /root/.ansible/tmp/ansible-tmp-1516637919.09-157549027250555/stat.py && sleep 0'"'"'' <docker2> (0, '', '') <docker2> ESTABLISH SSH CONNECTION FOR USER: None <docker2> SSH: EXEC ssh -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=50 docker2 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861/ /root/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861/stat.py && sleep 0'"'"'' <docker3> (0, '', '') <docker3> ESTABLISH SSH CONNECTION FOR USER: None <docker3> SSH: EXEC ssh -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=50 -tt docker3 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1516637919.09-157549027250555/stat.py && sleep 0'"'"'' <docker2> (0, '', '') <docker2> ESTABLISH SSH CONNECTION FOR USER: None <docker2> SSH: EXEC ssh -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=50 -tt docker2 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861/stat.py && sleep 0'"'"'' <docker3> (0, '\r\n{"exception": " File \\"/tmp/ansible_bmvKmn/ansible_modlib.zip/ansible/module_utils/basic.py\\", line 2762, in run_command\\n cmd = subprocess.Popen(args, **kwargs)\\n File \\"/usr/lib/python2.7/subprocess.py\\", line 711, in __init__\\n errread, errwrite)\\n File \\"/usr/lib/python2.7/subprocess.py\\", line 1343, in _execute_child\\n raise child_exception\\n", "cmd": "/usr/local/bin/file -i /tmp/hosts", "failed": true, "rc": 8, "invocation": {"module_args": {"checksum_algorithm": "sha1", "get_checksum": true, "path": "/tmp/hosts", "checksum_algo": "sha1", "follow": false, "get_md5": false, "get_mime": true, "get_attributes": true}}, "msg": "[Errno 8] Exec format error"}\r\n\r\n{"invocation": {"module_args": {"checksum_algorithm": "sha1", "get_checksum": true, "path": "/tmp/hosts", "checksum_algo": "sha1", "follow": false, "get_md5": false, "get_mime": true, "get_attributes": true}}, "stat": {"charset": "unknown", "uid": 0, "exists": true, "attr_flags": "e", "woth": false, "isreg": true, "device_type": 0, "mtime": 1516635934.884241, "block_size": 4096, "inode": 851154, "isgid": false, "size": 502, "executable": false, "isuid": false, "readable": true, "version": "18446744072591930902", "pw_name": "root", "gid": 0, "ischr": false, "wusr": true, "writeable": true, "mimetype": "unknown", "blocks": 8, "xoth": false, "islnk": false, "nlink": 1, "issock": false, "rgrp": true, "gr_name": "root", "path": "/tmp/hosts", "xusr": false, "atime": 1516636123.771911, "isdir": false, "ctime": 1516635936.2162387, "isblk": false, "wgrp": false, "checksum": "a12e084a52551a05dae3d81d803b3bda0b590c65", "dev": 2049, "roth": true, "isfifo": false, "mode": "0644", "xgrp": false, "rusr": true, "attributes": ["extents"]}, "changed": false}\r\n', 'Connection to docker3 closed.\r\n') fatal: [docker3]: FAILED! => { "msg": "Failed to get information on remote file (/tmp/hosts): Connection to docker3 closed.\r\n" } <docker2> (0, '\r\n{"invocation": {"module_args": {"checksum_algorithm": "sha1", "get_checksum": true, "path": "/tmp/hosts", "checksum_algo": "sha1", "follow": false, "get_md5": false, "get_mime": true, "get_attributes": true}}, "stat": {"charset": "us-ascii", "uid": 0, "exists": true, "attr_flags": "e", "woth": false, "isreg": true, "device_type": 0, "mtime": 1516636124.853028, "block_size": 4096, "inode": 5789587, "isgid": false, "size": 502, "executable": false, "isuid": false, "readable": true, "version": "1384366644", "pw_name": "root", "gid": 0, "ischr": false, "wusr": true, "writeable": true, "mimetype": "text/plain", "blocks": 8, "xoth": false, "islnk": false, "nlink": 1, "issock": false, "rgrp": true, "gr_name": "root", "path": "/tmp/hosts", "xusr": false, "atime": 1516637049.8171554, "isdir": false, "ctime": 1516636126.693037, "isblk": false, "wgrp": false, "checksum": "28692ee893136fe343e585258e10619bc2ad6581", "dev": 2049, "roth": true, "isfifo": false, "mode": "0644", "xgrp": false, "rusr": true, "attributes": ["extents"]}, "changed": false}\r\n', 'Connection to docker2 closed.\r\n') Using module file /home/rdxmb/.local/lib/python2.7/site-packages/ansible/modules/files/file.py <docker2> PUT /tmp/tmp4rwgOe TO /root/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861/file.py <docker2> SSH: EXEC scp -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=50 /tmp/tmp4rwgOe '[docker2]:/root/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861/file.py' <docker2> (0, '', '') <docker2> ESTABLISH SSH CONNECTION FOR USER: None <docker2> SSH: EXEC ssh -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=50 docker2 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861/ /root/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861/file.py && sleep 0'"'"'' <docker2> (0, '', '') <docker2> ESTABLISH SSH CONNECTION FOR USER: None <docker2> SSH: EXEC ssh -o ForwardAgent=yes -o StrictHostKeyChecking=no -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=50 -tt docker2 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861/file.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1516637919.08-250152219503861/" > /dev/null 2>&1 && sleep 0'"'"'' <docker2> (0, '\r\n{"group": "root", "uid": 0, "changed": false, "owner": "root", "state": "file", "gid": 0, "mode": "0644", "path": "/tmp/hosts", "invocation": {"module_args": {"directory_mode": null, "force": false, "remote_src": null, "path": "/tmp/hosts", "owner": "root", "follow": false, "group": "root", "unsafe_writes": null, "serole": null, "content": null, "state": "file", "diff_peek": null, "setype": null, "dest": "/tmp/hosts", "selevel": null, "original_basename": "mbr.intern.j2", "regexp": null, "validate": null, "src": "mbr.intern.j2", "seuser": null, "recurse": false, "delimiter": null, "mode": 420, "attributes": null, "backup": null}}, "diff": {"after": {"path": "/tmp/hosts"}, "before": {"path": "/tmp/hosts"}}, "size": 502}\r\n', 'Connection to docker2 closed.\r\n') ok: [docker2] => { "changed": false, "checksum": "28692ee893136fe343e585258e10619bc2ad6581", "diff": { "after": { "path": "/tmp/hosts" }, "before": { "path": "/tmp/hosts" } }, "gid": 0, "group": "root", "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "delimiter": null, "dest": "/tmp/hosts", "diff_peek": null, "directory_mode": null, "follow": false, "force": false, "group": "root", "mode": 420, "original_basename": "mbr.intern.j2", "owner": "root", "path": "/tmp/hosts", "recurse": false, "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": "mbr.intern.j2", "state": "file", "unsafe_writes": null, "validate": null } }, "mode": "0644", "owner": "root", "path": "/tmp/hosts", "size": 502, "state": "file", "uid": 0 }

`

ansible --version

ansible 2.4.2.0
config file = /home/rdxmb/repos/docker-swarm/ansible.cfg
configured module search path = [u’/home/rdxmb/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /home/rdxmb/.local/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]
`

ansible.cfg :

`
[defaults]

remote_tmp = $HOME/.ansible/tmp
pattern = *
forks = 5
poll_interval = 15
ask_pass = False
transport = smart
remote_port = 22
module_lang = C

ansible_python_interpreter=“/usr/bin/python”

gathering = smart

roles_path = roles:/tmp/galaxy_roles
host_key_checking = False

timeout = 50

action_plugins = /usr/share/ansible_plugins/action_plugins
callback_plugins = /usr/share/ansible_plugins/callback_plugins
connection_plugins = /usr/share/ansible_plugins/connection_plugins
lookup_plugins = /usr/share/ansible_plugins/lookup_plugins
vars_plugins = /usr/share/ansible_plugins/vars_plugins
filter_plugins = /usr/share/ansible_plugins/filter_plugins

[ssh_connection]
ssh_args = -o ForwardAgent=yes

scp_if_ssh = True
`

become is not used here, SSH is working with rroot and key-login only.

`
cat roles/etc_hosts/tasks/main.yml

just created a new issue:

https://github.com/ansible/ansible/issues/35274