I forgot that ansible_ssh_port and ansible_ssh_host may be unset.  This 
version should work:

  # 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 }}"




On Tuesday, March 29, 2016 at 3:35:51 PM UTC+2, [email protected] wrote:
>
> Hello,
>
> thanks a lot!  For the sake of people having the same problem as me, 
> here's a complete task that kills connections to all hosts from the current 
> play:
>
>   # 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 }}
>     -o ControlPath=/tmp/ansible-ssh-{{ hostvars[item].ansible_ssh_user 
> }}-{{ hostvars[item].ansible_ssh_host }}-{{ hostvars[item].ansible_ssh_port 
> }}
>   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 }}"
>
> If you have any further suggestions, let me know!
>
> best,
> Jan
>
>
> On Friday, March 18, 2016 at 9:26:08 PM UTC+1, Brian Coca wrote:
>>
>> you can run a command to kill the connection locally:
>>
>> ssh -O stop <hostname>-o 
>> ControlPath=~/.ansible/cp/ansible-ssh-<hostname>-22-<user> 
>>
>>
>> ----------
>> Brian Coca
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0da7b7c3-fccb-4c7d-bd1e-4c6e46295f95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to