# Changing ansible\_shell\_type - is ansible reusing ssh connection?

**URL:** <https://forum.ansible.com/t/changing-ansible-shell-type-is-ansible-reusing-ssh-connection/34869>\
**Category:** Ansible Project\
**Created:** [March 27, 2021, 12:06am UTC](https://forum.ansible.com/t/changing-ansible-shell-type-is-ansible-reusing-ssh-connection/34869 "2021-03-27T00:06:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![need\_abettername](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@need\_abettername](https://forum.ansible.com/u/need_abettername)\
**Post date:** [March 27, 2021, 12:06am UTC](https://forum.ansible.com/t/changing-ansible-shell-type-is-ansible-reusing-ssh-connection/34869/1 "2021-03-27T00:06:31Z")

</div>

Trying to make a dual boot script and came across these results, the shell is changed during the playbook but subsequent tasks are somehow using the old one.

How can I force a new connection please?

1. Change shell to cmd -Success

win\_ping using powershell - success  
win\_ping using cmd - failure

The reverse is true when changing it back.  
I’ve confimed the shells are changing by normal ssh from CLI

–Part of Playbook–

---

<div class="post-metadata">

**Author:** ![need\_abettername](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@need\_abettername](https://forum.ansible.com/u/need_abettername)\
**Post date:** [March 27, 2021, 12:36am UTC](https://forum.ansible.com/t/changing-ansible-shell-type-is-ansible-reusing-ssh-connection/34869/2 "2021-03-27T00:36:26Z")

</div>

My explanation in the first message wasn’t great - apologies.  
Just to be clear…

In a playbook…

1. A Tasks changes remote shell on windows system (ansible\_shell\_type) from powershell to cmd  
Subsequent tasks then run but have the opposite results as if the shell hasn’t been changed

2. win\_ping using powershell - success - when it should fail

3. win\_ping using cmd shell - failure - when it should work, as we’ve changed the shell in 1

Just been reading about multiplexing, sounded a likely culprit so I set

ansible.cfg

[ssh\_connection]  
-o ControlMaster=no

But no change, it’s still hanging onto it’s old shell despite having been changed.  
Or I’m tired and misreading something

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [March 28, 2021, 11:12pm UTC](https://forum.ansible.com/t/changing-ansible-shell-type-is-ansible-reusing-ssh-connection/34869/3 "2021-03-28T23:12:38Z")

</div>

The way to reset the connection in Ansible is to run

- meta: reset\_connection

This will delete the existing control persist socket so the subsequent task will use a new connection.

---

<div class="post-metadata">

**Author:** ![need\_abettername](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@need\_abettername](https://forum.ansible.com/u/need_abettername)\
**Post date:** [March 29, 2021, 1:04pm UTC](https://forum.ansible.com/t/changing-ansible-shell-type-is-ansible-reusing-ssh-connection/34869/4 "2021-03-29T13:04:40Z")

</div>

Thank you, incredible helpful. Off to read more about that now.

Also wanted to take the opportunity to thank you, I was reading your excelelnt article on Windows Mapped drives the other day.  
Still some testing to do on that but I may have a question there. If so shall I put it on this list?

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [March 29, 2021, 7:07pm UTC](https://forum.ansible.com/t/changing-ansible-shell-type-is-ansible-reusing-ssh-connection/34869/5 "2021-03-29T19:07:38Z")

</div>

Best to just ask it here, benefits others who might want to search the history if they have the same question.
