ssh:disconnect does not work when ansible_host is not explicitly defined
Summary
...ssh:disconnect
does not work when ansible_host
is not explicitly defined. The action tries to disconnect localhost
instead of {{ inventory_hostname }}
.
Steps to reproduce
- Do not define
anisble_host
. - Call
ssh:disconnect
.
Expected behavior
SSH disconnects.
Actual behavior
Everything ends in tears
Relevant logs and/or screenshots
fatal: [gs0420 -> localhost]: FAILED! => {"changed": true, "cmd": "ssh -O stop -S \"~/.ansible/cp/ansible-ssh-localhost-22-cloud-admin\" \"localhost\"", "delta": "0:00:00.005448", "end": "2017-03-24 10:15:21.642328", "failed": true, "failed_when_result": true, "rc": 255, "start": "2017-03-24 10:15:21.636880", "stderr": "Control socket connect(/home/tziol/.ansible/cp/ansible-ssh-localhost-22-cloud-admin): No such file or directory", "stdout": "", "stdout_lines": [], "warnings": []}
Possible fixes
Change
-S "~/.ansible/cp/ansible-ssh-{{ ansible_host | default(inventory_hostname) }}-{{ ansible_port | default('22') }}-{{ ansible_user }}"
to
-S "~/.ansible/cp/ansible-ssh-{{ hostvars[inventory_hostname].ansible_host | default(inventory_hostname) }}-{{ ansible_port | default('22') }}-{{ ansible_user }}"