1

I'm running a packer build of windows using ansible to provision the VM.

I connect to the VM via OpenSHH. I have powershell 7 set as the default shell for OpenSSH. When I connect to the VM over ssh on the command line, the banner says PowerShell 7.1.3.

I run the following code via ansible-playbook:

    - name: Check powershell version
      ansible.windows.win_shell: | 
        Get-Host | Select-Object Version

    - name:  Check powershell version
      ansible.windows.win_shell: | 
        Get-Host | Select-Object Version
      args:
        executable: pwsh

The first task returns 5.1.19041.1023

The second task returns 7.1.3

So when I don't specify the executable, win_shell is running powershell.exe, aka powershell 5.

When I do specify the executable as pwsh, aka powershell 7, it behaves correctly.

I can't figure out why the win_shell module is ignoring the default set in the registry. Does anyone know what I have done wrong?

Mike A
  • 500
  • 4
  • 16
  • Are you expecting _OpenShell's_ default shell to also become _Ansible's_ default? I don't think the two are connected. I'm not familiar with Ansible, but [according to the docs](https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_shell_module.html) it does appear that specifying an `executable` argument is the - only? - way to specify an alternative shell, in lieu of the default shell, which is _Windows PowerShell_. – mklement0 Oct 08 '21 at 20:32

1 Answers1

-1

Add Powershell 7 install path (where pwsh.exe located) and module path to environment variables and delete 5.x paths from there. Also rename pwsh.exe to powershell.exe.

  • NO. The whole point of powershell 7 being named pwsh is so that it can coexist with powershell 5 (powershell.exe) which is shipped with windows. Renaming the exe is a terrible idea, since 5 and 7 have some different modules. – Mike A Mar 15 '23 at 16:57