Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

SSH connection plugin

ANSIBLE VERSION

ansible 2.3.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]

CONFIGURATION

Default configuration.

OS / ENVIRONMENT

Ubuntu 14.04.5

Kernel 3.13.0-83-generic

Ansible installed via pip

SUMMARY

Looks like SSH connection sharing is broken. I have one single server defined in inventory twice – with the same hostname, but different alias.

STEPS TO REPRODUCE

Any playbook.

Inventory like:

server.io-8721 ansible_host=server.io
server.io-d4f2 ansible_host=server.io

EXPECTED RESULTS

Setup task success.

ACTUAL RESULTS

On setup task I get:

TASK [setup] *******************************************************************
fatal: [server.io-8721]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Shared connection to server.io closed.\r\n", "unreachable": true}

msg: Failed to connect to the host via ssh: Shared connection to server.io closed.

fatal: [server.io-d4f2]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Shared connection to server.io closed.\r\n", "unreachable": true}

msg: Failed to connect to the host via ssh: Shared connection to server.io closed.

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

ansible-playbook / SSH connection type

ANSIBLE VERSION

ansible 2.1.1.0
config file =
configured module search path = Default w/o overrides

CONFIGURATION

No custom config present

OS / ENVIRONMENT

# OracleLinux 7.2
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.2 (Maipo)

SUMMARY

I'm seeing random (but persistent) failures in ansible-playbook around the setup task failing due to what seems to be SSH multiplexing.

We run a playbook comprised of about 15 roles, each with a multitude of tasks. Almost without fail, each run of the playbook will fail at some random point during the "setup" stage, at which point it dumps the contents of the facts discovered about the target node and continues on to the next node. I can reproduce this with a very simple playbook, which I will link below[0] along with the error[1].

Looking in the error output, you can see the following type of output: "mux_client_read_packet: read header failed: Broken pipe". I can reproduce this using a very simple SSH command, trimmed down from what Ansible is using:

# ssh -vvv -o ControlMaster=auto -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r database02 hostname
...
debug2: set_control_persist_exit_time: schedule exit in 60 seconds
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 0

If I remove the -o ControlPath from the above, or clean out ~/.ansible/cp, the ssh command works fine, but a re-run of ansible-playbook seems to recreate the faulty socket (at a non deterministic point in the playbook).

I have played with many different combinations of ssh_args in ~/.ansible.cfg, including higher values for ControlPersist, ServerAliveInterval, ServerAliveCountMax, changing ControlPath, and enabling pipelining, none seem to make a difference.

Can anyone provide any other possible workarounds or ways I can debug this? Is there a way to force Ansible to disable ControlPersist?

STEPS TO REPRODUCE

ansible-playbook -i ~/multinode test.yml -vvvv

[0] https://gist.github.com/brk3/1562e595a04d85b9df04bac9c8054273 (playbook: test.yml)

[1] https://gist.github.com/brk3/f06da830405d0cb3ffeed59d2901e5a9 (error output)

[2] https://gist.github.com/brk3/7fe02114c804eef58a108c086d8cb26c (inventory)