Issue 1:
Not work shell with grep pipline:

- shell: find /TEST/PATH -name requirements.txt -exec cat {} \; | grep -o '^[^#]*'
- shell: "find /TEST/PATH -name requirements.txt -exec cat {} \\; | grep -o '^[^#]*'"
- shell: find /TEST/PATH -name requirements.txt -exec cat {} \; | grep test
- shell: "find /TEST/PATH -name requirements.txt -exec cat {} \\; | grep test"
- shell: find /TEST/PATH -name requirements.txt -print0 | xargs -0 cat | grep -o '^[^#]*'
- shell: "find /TEST/PATH -name requirements.txt -print0 | xargs -0 cat | grep -o '^[^#]*'"
- shell: find /TEST/PATH -name requirements.txt -print0 | xargs -0 cat | grep test
- shell: "find /TEST/PATH -name requirements.txt -print0 | xargs -0 cat | grep test"

with next message:

failed: [test-instance] => {"changed": true, "cmd": "find /TEST/PATH -name requirements.txt -exec cat {} \\; | grep -o '^[^#]*'", "delta": "0:00:00.003797", "end": "2015-06-03 21:40:57.502797", "rc": 1, "start": "2015-06-03 21:40:57.499000", "warnings": []}

FATAL: all hosts have already failed -- aborting

When I replace grep something for example to tail all work, this commands also work fine on shell on instance for bash and sh, also this work for python subprocess.Popen with shell=True.

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

SSH connection

ANSIBLE VERSION

ansible 2.2.0 (devel eb33ed4219) last updated 2016/09/27 11:16:30 (GMT +200)
lib/ansible/modules/core: (detached HEAD c03697c81e) last updated 2016/09/27 11:17:10 (GMT +200)
lib/ansible/modules/extras: (detached HEAD 119bc466be) last updated 2016/09/27 11:17:58 (GMT +200)
config file =
configured module search path = Default w/o overrides

CONFIGURATION

N/A

OS / ENVIRONMENT

Linux localhost 3.8.11 #1 SMP Mon Sep 12 21:56:54 PDT 2016 x86_64 x86_64 x86_64 GNU/Linux
Python 2.7.11
OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6, OpenSSL 1.0.1f 6 Jan 2014

~/ansible$ pip list

ansible (2.2.0)

apache-libcloud (0.20.1)

aws (0.2.5)

awscli (1.10.61)

backports.ssl-match-hostname (3.5.0.1)

boto (2.40.0)

boto3 (1.1.3)

botocore (1.4.51)

certifi (2015.11.20.1)

cffi (1.7.0)

colorama (0.3.7)

Cython (0.20.1.post0)

docutils (0.12)

ecdsa (0.13)

enum34 (1.1.6)

Fabric (1.11.1)

futures (3.0.5)

google-api-python-client (1.1)

httplib2 (0.8)

idna (2.1)

ipaddress (1.0.16)

Jinja2 (2.8)

jmespath (0.9.0)

jsonpatch (1.13)

jsonpointer (1.10)

jwt (0.3.2)

lxml (3.3.3)

MarkupSafe (0.23)

numpy (1.8.2)

paramiko (1.17.0)

pip (8.1.2)

ply (3.4)

prettytable (0.7.2)

pyasn1 (0.1.9)

pycparser (2.14)

pycrypto (2.6.1)

pygpgme (0.3)

pyOpenSSL (0.13)

python-apt (0.9.3.5ubuntu2)

python-dateutil (2.5.3)

python-gflags (3.0.4)

python-nghttp2 (1.3.5.dev0)

PyYAML (3.11)

rsa (3.4.2)

s3transfer (0.1.3)

setuptools (23.0.0)

simplejson (3.3.1)

six (1.10.0)

tabulate (0.7.5)

urllib3 (1.14)

virtualenv (1.11.4)

SUMMARY

Using a repo installed version of Ansible, 2.1.1 all works fine.

When I remove that version and then clone the devel branch, ansible-playbook fails to connect to hosts while running ansible -m setup consistently works and gets facts from the host.

STEPS TO REPRODUCE

ansible mng -m setup -a 'gather_subset=!all' -vvvvvv

Using /home/fvant/ansible-local/ansible.cfg as config file
Loading callback plugin minimal of type stdout, v2.0 from /home/fvant/ansible/lib/ansible/plugins/callback/__init__.pyc
Using module file /home/fvant/ansible/lib/ansible/modules/core/system/setup.py
<10.0.91.104> ESTABLISH SSH CONNECTION FOR USER: root
<10.0.91.104> SSH: ansible.cfg set ssh_args: (-C)(-o)(ControlMaster=auto)(-o)(ControlPersist=60s)
<10.0.91.104> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no)
<10.0.91.104> SSH: ANSIBLE_PRIVATE_KEY_FILE/private_key_file/ansible_ssh_private_key_file set: (-o)(IdentityFile="./vars/keys/ansible_id_rsa")
<10.0.91.104> SSH: ansible_password/ansible_ssh_pass not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no)
<10.0.91.104> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=root)
<10.0.91.104> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=5)
<10.0.91.104> SSH: PlayContext set ssh_common_args: ()
<10.0.91.104> SSH: PlayContext set ssh_extra_args: ()
<10.0.91.104> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/home/fvant/.ansible/cp/ansible-ssh-%h-%p-%r)
<10.0.91.104> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'IdentityFile="./vars/keys/ansible_id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=5 -o ControlPath=/home/fvant/.ansible/cp/ansible-ssh-%h-%p-%r 10.0.91.104 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /tmp/ansible-tmp-1474979078.18-42020272005162 `" && echo ansible-tmp-1474979078.18-42020272005162="` echo /tmp/ansible-tmp-1474979078.18-42020272005162 `" ) && sleep 0'"'"''
<10.0.91.104> PUT /tmp/tmpUCSQuH TO /tmp/ansible-tmp-1474979078.18-42020272005162/setup.py
<10.0.91.104> SSH: ansible.cfg set ssh_args: (-C)(-o)(ControlMaster=auto)(-o)(ControlPersist=60s)
<10.0.91.104> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no)
<10.0.91.104> SSH: ANSIBLE_PRIVATE_KEY_FILE/private_key_file/ansible_ssh_private_key_file set: (-o)(IdentityFile="./vars/keys/ansible_id_rsa")
<10.0.91.104> SSH: ansible_password/ansible_ssh_pass not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no)
<10.0.91.104> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=root)
<10.0.91.104> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=5)
<10.0.91.104> SSH: PlayContext set ssh_common_args: ()
<10.0.91.104> SSH: PlayContext set sftp_extra_args: ()
<10.0.91.104> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/home/fvant/.ansible/cp/ansible-ssh-%h-%p-%r)
<10.0.91.104> SSH: EXEC sftp -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'IdentityFile="./vars/keys/ansible_id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=5 -o ControlPath=/home/fvant/.ansible/cp/ansible-ssh-%h-%p-%r '[10.0.91.104]'
<10.0.91.104> ESTABLISH SSH CONNECTION FOR USER: root
<10.0.91.104> SSH: ansible.cfg set ssh_args: (-C)(-o)(ControlMaster=auto)(-o)(ControlPersist=60s)
<10.0.91.104> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no)
<10.0.91.104> SSH: ANSIBLE_PRIVATE_KEY_FILE/private_key_file/ansible_ssh_private_key_file set: (-o)(IdentityFile="./vars/keys/ansible_id_rsa")
<10.0.91.104> SSH: ansible_password/ansible_ssh_pass not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no)
<10.0.91.104> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=root)
<10.0.91.104> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=5)
<10.0.91.104> SSH: PlayContext set ssh_common_args: ()
<10.0.91.104> SSH: PlayContext set ssh_extra_args: ()
<10.0.91.104> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/home/fvant/.ansible/cp/ansible-ssh-%h-%p-%r)
<10.0.91.104> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'IdentityFile="./vars/keys/ansible_id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=5 -o ControlPath=/home/fvant/.ansible/cp/ansible-ssh-%h-%p-%r 10.0.91.104 '/bin/sh -c '"'"'chmod u+x /tmp/ansible-tmp-1474979078.18-42020272005162/ /tmp/ansible-tmp-1474979078.18-42020272005162/setup.py && sleep 0'"'"''
<10.0.91.104> ESTABLISH SSH CONNECTION FOR USER: root
<10.0.91.104> SSH: ansible.cfg set ssh_args: (-C)(-o)(ControlMaster=auto)(-o)(ControlPersist=60s)
<10.0.91.104> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no)
<10.0.91.104> SSH: ANSIBLE_PRIVATE_KEY_FILE/private_key_file/ansible_ssh_private_key_file set: (-o)(IdentityFile="./vars/keys/ansible_id_rsa")
<10.0.91.104> SSH: ansible_password/ansible_ssh_pass not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no)
<10.0.91.104> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=root)
<10.0.91.104> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=5)
<10.0.91.104> SSH: PlayContext set ssh_common_args: ()
<10.0.91.104> SSH: PlayContext set ssh_extra_args: ()
<10.0.91.104> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/home/fvant/.ansible/cp/ansible-ssh-%h-%p-%r)
<10.0.91.104> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'IdentityFile="./vars/keys/ansible_id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=5 -o ControlPath=/home/fvant/.ansible/cp/ansible-ssh-%h-%p-%r -tt 10.0.91.104 '/bin/sh -c '"'"'/usr/bin/python /tmp/ansible-tmp-1474979078.18-42020272005162/setup.py; rm -rf "/tmp/ansible-tmp-1474979078.18-42020272005162/" > /dev/null 2>&1 && sleep 0'"'"''
mng-a-sandbox01 | SUCCESS => {
"ansible_facts": {
"ansible_architecture": "x86_64",
"ansible_cmdline": {
"BOOT_IMAGE": "/boot/vmlinuz-3.10.0-327.10.1.el7.x86_64",
"LANG": "en_US.UTF-8",
"console": "ttyS0,115200",
"crashkernel": "auto",
"ro": true,
"root": "UUID=ef6ba050-6cdc-416a-9380-c14304d0d206"
},

</snip>

EXPECTED RESULTS

ACTUAL RESULTS

ansible-playbook playbooks/main.yml -e env=mng --ask-vault-pass -e account=playground -vvvvvvvvv

Loading callback plugin default of type stdout, v2.0 from /home/fvant/ansible/lib/ansible/plugins/callback/__init__.pyc
Loading callback plugin profile_tasks of type aggregate, v2.0 from /home/fvant/ansible/lib/ansible/plugins/callback/__init__.pyc

PLAYBOOK: main.yml *************************************************************
11 plays in playbooks/main.yml

PLAY [mng] *********************************************************************

TASK [setup] *******************************************************************
Tuesday 27 September 2016 14:19:31 +0200 (0:00:00.177) 0:00:01.441 *****
Using module file /home/fvant/ansible/lib/ansible/modules/core/system/setup.py
<10.0.91.104> ESTABLISH SSH CONNECTION FOR USER: root
<10.0.91.104> SSH: ansible.cfg set ssh_args: (-C)(-o)(ControlMaster=auto)(-o)(ControlPersist=60s)
<10.0.91.104> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no)
<10.0.91.104> SSH: ANSIBLE_PRIVATE_KEY_FILE/private_key_file/ansible_ssh_private_key_file set: (-o)(IdentityFile="./vars/keys/ansible_id_rsa")
<10.0.91.104> SSH: ansible_password/ansible_ssh_pass not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no)
<10.0.91.104> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=root)
<10.0.91.104> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=5)
<10.0.91.104> SSH: PlayContext set ssh_common_args: ()
<10.0.91.104> SSH: PlayContext set ssh_extra_args: ()
<10.0.91.104> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/home/fvant/.ansible/cp/ansible-ssh-%h-%p-%r)
<10.0.91.104> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'IdentityFile="./vars/keys/ansible_id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=5 -o ControlPath=/home/fvant/.ansible/cp/ansible-ssh-%h-%p-%r 10.0.91.104 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /tmp/ansible-tmp-1474978771.34-100536752987114 `" && echo ansible-tmp-1474978771.34-100536752987114="` echo /tmp/ansible-tmp-1474978771.34-100536752987114 `" ) && sleep 0'"'"''
fatal: [mng-a-sandbox01]: UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh.",
"unreachable": true
}