ssh disconnect does not work if ansible_user is not passed
Summary
ssh disconnect does not work if ansible_user is not passed
since we are using local action (part of disconnect.yml action):
- name: "disconnect the local SSH connection to the host"
local_action:
module: >-
shell
ssh
-O stop
-S "{{ ssh_control_path }}"
"{{ _ssh_host }}"
register: "_result_ssh_stop"
when: "_result_ssh_check.stat.exists"
failed_when:
- "_result_ssh_stop | failed"
- "'No such file or directory' in _result_ssh_stop.stderr"
If host does not have ansible_user
set, ansible will use ansible_user
of localhost which default to currently logged in user.
Steps to reproduce
- use ssh connection without specifying ansible_user
- call
disconnect
action ofssh
role
Expected behavior
- host should disconnect
Actual behavior
- host does not disconnect
Relevant logs and/or screenshots
N/A
Possible fixes
modify:
_ssh_port: "{{ ansible_port | default('None') }}"
_ssh_user: "{{ ansible_user | default('None') }}"
to:
_ssh_port: "{{ hostvars[inventory_hostname].ansible_port | default('None') }}"
_ssh_user: "{{ hostvars[inventory_hostname].ansible_user | default('None') }}"
Edited by Piotr Korthals