Feature: SSH disconnect
Description
Sometimes, you just wanna disconnect.
Proposal
Something like that:
# this will force Ansible to create new connection(s) so that changes in ssh
# settings will have effect (normally Ansible uses ControlPersist feature to
# reuse one connection for all tasks). Note that the path to the socket must
# be the same as what is configured in ansible.cfg.
- name: kill cached ssh connection
local_action: >
shell ssh -O stop {{ hostvars[item].ansible_ssh_host|default(inventory_hostname) }}
-o ControlPath=~/.ansible/cp/ansible-ssh-{{ hostvars[item].ansible_ssh_host|default(inventory_hostname) }}-{{ hostvars[item].ansible_ssh_port|default('22') }}-{{ hostvars[item].ansible_ssh_user }}
run_once: yes
register: socket_removal
failed_when: >
socket_removal|failed
and "No such file or directory" not in socket_removal.stderr
with_items: "{{ play_hosts }}"