# Trouble with win\_chocolatey and OpenSSH

**URL:** <https://forum.ansible.com/t/trouble-with-win-chocolatey-and-openssh/34350>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [December 17, 2020, 4:47pm UTC](https://forum.ansible.com/t/trouble-with-win-chocolatey-and-openssh/34350 "2020-12-17T16:47:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Alberghini](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mike_alberghini/32/8855_2.png) [@Mike\_Alberghini](https://forum.ansible.com/u/Mike_Alberghini)\
**Post date:** [December 17, 2020, 4:47pm UTC](https://forum.ansible.com/t/trouble-with-win-chocolatey-and-openssh/34350/1 "2020-12-17T16:47:30Z")

</div>

I’m using OpenSSH to connect to Windows boxes to avoid having to deal with WinRM. So far it is working pretty good, but I have found an issue and i’m hoping someone has an idea.

This is what my tasks looks like:

- name: install chocolatey  
win\_chocolatey:  
name: chocolatey  
state: present

- name: Remove the default public source

win\_chocolatey\_source:  
name: chocolatey  
state: absent

The first task runs fine, and installs chocolatey, since it is not on the box. The second fails with “Failed to find Chocolatey installation, make sure choco.exe is in the PATH env value”.

The PATH is not picking up that chocolatey has been added. If I add a win\_reboot between the two, then it works fine. That seems like a bit excessive. Is there a way to get the PATH to update, or have ansible break the connection and reconnect?

Mike A

---

<div class="post-metadata">

**Author:** ![Stu](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Stu](https://forum.ansible.com/u/Stu)\
**Post date:** [December 17, 2020, 5:36pm UTC](https://forum.ansible.com/t/trouble-with-win-chocolatey-and-openssh/34350/2 "2020-12-17T17:36:56Z")

</div>

Can you run

Refreshenv

Between the 2?

---

<div class="post-metadata">

**Author:** ![Stu](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Stu](https://forum.ansible.com/u/Stu)\
**Post date:** [December 17, 2020, 5:40pm UTC](https://forum.ansible.com/t/trouble-with-win-chocolatey-and-openssh/34350/3 "2020-12-17T17:40:20Z")

</div>

Or

$env:Path = [System.Environment]::GetEnvironmentVariable(“Path”,“Machine”) + “;” + [System.Environment]::GetEnvironmentVariable(“Path”,“User”)

Some other ideas here : [https://stackoverflow.com/questions/17794507/reload-the-path-in-powershell](https://stackoverflow.com/questions/17794507/reload-the-path-in-powershell)

---

<div class="post-metadata">

**Author:** ![Mike\_Alberghini](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mike_alberghini/32/8855_2.png) [@Mike\_Alberghini](https://forum.ansible.com/u/Mike_Alberghini)\
**Post date:** [December 17, 2020, 9:04pm UTC](https://forum.ansible.com/t/trouble-with-win-chocolatey-and-openssh/34350/4 "2020-12-17T21:04:35Z")

</div>

Running refreshenv in powershell via win\_shell:  
The term ‘Refreshenv’ is not recognized as the name of a cmdlet, function, script file or operable program.

According to this: [https://stackoverflow.com/questions/46758437/how-to-refresh-the-environment-of-a-powershell-session-after-a-chocolatey-instal](https://stackoverflow.com/questions/46758437/how-to-refresh-the-environment-of-a-powershell-session-after-a-chocolatey-instal)  
it’s installed by chocolatey, so I can’t run it until I have it in the path, and I need it to update the path…

Running  
$env:Path = [System.Environment]::GetEnvironmentVariable(“Path”,“Machine”) + “;” + [System.Environment]::GetEnvironmentVariable(“Path”,“User”)  
executes successfully, but doesn’t seem to fix the problem. The following commands still fail with “Failed to find Chocolatey installation”

---

<div class="post-metadata">

**Author:** ![Stu](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Stu](https://forum.ansible.com/u/Stu)\
**Post date:** [December 18, 2020, 9:22am UTC](https://forum.ansible.com/t/trouble-with-win-chocolatey-and-openssh/34350/5 "2020-12-18T09:22:00Z")

</div>

Interesting,

Can you restart the powershell service rather than the entire server?

That or kill the ssh session and re-connect?

---

<div class="post-metadata">

**Author:** ![Mike\_Alberghini](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mike_alberghini/32/8855_2.png) [@Mike\_Alberghini](https://forum.ansible.com/u/Mike_Alberghini)\
**Post date:** [December 18, 2020, 5:53pm UTC](https://forum.ansible.com/t/trouble-with-win-chocolatey-and-openssh/34350/6 "2020-12-18T17:53:25Z")

</div>

Running meta: reset\_connection does not seem to fix the problem.

Running RefreshEnv from it’s direct path after it is installed does not fix it:

- name: Refresh the shell path  
win\_shell: C:\ProgramData\chocolatey\bin\RefreshEnv.cmd  
args:  
executable: cmd

Restarting the sshd service does not seem to fix it.

- name: Restart sshd  
ansible.windows.win\_service:  
name: sshd  
state: restarted

i’m back to a full system reboot until I can solve this.

Mike
