"/bin/sh: 1: powershell: not found\n"

i have a simple ansible playbook that i am using to configure some windows machines. i am getting the following error. i have installed powershell. is it the bash shell that is complaining? winrm is configured fine and i have tested it as well. i’ll really appreciate any help with this.

$ ansible-playbook -i winhosts awsenvcfgtest.yml

PLAY [infrastructure setup] ********************************************************************************************************

TASK [ec2] *************************************************************************************************************************
ok: [localhost]

TASK [add hosts to group] **********************************************************************************************************
changed: [localhost]

TASK [win_domain] ******************************************************************************************************************
fatal: [localhost]: FAILED! => {“changed”: false, “module_stderr”: “/bin/sh: 1: powershell: not found\n”, “module_stdout”: “”, “msg”: “MODULE FAILURE”, “rc”: 127}

PLAY RECAP *************************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=1

Which version of powershell you have on remotes? Ensure it’s 3.0 and above.

You said you are using winrm, which protocol service you are using, credssp or kerberos?

Without seeing your playbook I don’t know how you are trying to do it but Ansible is trying to connect to localhost with the PowerShell plugin. Usually you need to run the provisioning tasks in 1 play and then the Windows tasks in a separate play. An example of how I did this can be seen here https://github.com/jborean93/ansible-win-demos/blob/master/ec2-win-ami/main.yml. The first play provisions the host in AWS and then adds it into the windows group. The 2nd play then runs on the Windows group which seems to be what you want.

Thanks

Jordan

This is exactly what I’m doing.

From the error message, it seemed to me that /bin/sh is trying to execute the command ‘powershell’ which it can’t find. On investigating, I found that powershell is invoked through pwsh command.

I created a symbol link named powershell for the pwsh command, and it’s working flawlessly now.

I don’t understand why I had to do all this! Why it’s looking for powershell and not pwsh?

Thanks
Ali

We don’t support PowerShell core (pwsh) and the PowerShell/WinRM is currently only designed for Windows hosts which use PowerShell.exe not pwsh.exe. As I said, the issue you have is that you are running the PowerShell module on the localhost as a local command and not on the Windows host through WinRM like it should be.

Thanks

Jordan

Thanks for the pointer. I’ll take a look at your suggested playbook and reply back. Thanks Again!

Thanks. I had connection=local which I removed and its working fine now.

i have a simple ansible playbook that i am using to configure some windows machines. i am getting the following error. i have installed powershell. is it the bash shell that is complaining? winrm is configured fine and i have tested it as well. i’ll really appreciate any help with this.

$ ansible-playbook -i winhosts awsenvcfgtest.yml

PLAY [infrastructure setup] ********************************************************************************************************

TASK [ec2] *************************************************************************************************************************
ok: [localhost]

TASK [add hosts to group] **********************************************************************************************************
changed: [localhost]

TASK [win_domain] ******************************************************************************************************************
fatal: [localhost]: FAILED! => {“changed”: false, “module_stderr”: “/bin/sh: 1: powershell: not found\n”, “module_stdout”: “”, “msg”: “MODULE FAILURE”, “rc”: 127}

PLAY RECAP *************************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=1

Hi All,

Can anyone help to sort this.I am trying to achieve the installation of a software to a windows instance at provisiong time. Software is deploy but not installed.Below i got the error when running the playbook:-

PLAY [localhost] *******************************************************************************************************************************************************

TASK [ensure instances are running] ************************************************************************************************************************************
changed: [localhost]

TASK [ensure Automation_Anywhere_Enterprise_Client is installed via win_package] ***************************************************************************************
fatal: [localhost]: FAILED! => {“changed”: false, “module_stderr”: “/bin/sh: powershell: command not found\n”, “module_stdout”: “”, “msg”: “MODULE FAILURE”, “rc”: 127}
to retry, use: --limit @/root/awswinins.retry

PLAY RECAP *************************************************************************************************************************************************************
localhost : ok=1 changed=1 unreachable=0 failed=1

  • hosts: localhost
    gather_facts: no
    vars:
    target_aws_region: “us-east-1”
    vars_files:
  • secret.yml

tasks:

  • name: ensure instances are running
    ec2:
    aws_access_key: " "
    aws_secret_key: " "
    key_name: " "
    region: " "
    image: “ami-050202fb72f001b47”
    instance_type: t2.micro
    group_id: “sg-00cfe7b7ee9a5aea8”
    wait: yes
    wait_timeout: 500
    exact_count: 1
    vpc_subnet_id: " "
    instance_profile_name: " "
    count_tag:
    Name: win-ami
    instance_tags:
    Name: win-ami
    user_data: “{{ lookup(‘template’, ‘userdata.txt.j2’) }}”
    register: ec2_result

  • name: ensure Automation_Anywhere_Enterprise_Client is installed via win_package
    win_package:
    path: C:\Windows\Temp\Automation_Anywhere_Enterprise_Client_10.7.0.exe
    product_id: Autmation_Anywhere_Enterprise_Client
    state: present

Thanks and Regards,
Akshay Kaushik

You are running the module over SSH with the wrong shell plugin. Ensure this is run with either ‘ansible_connection: winrm’ or ‘ansible_connection: psrp’ so the PowerShell modules work properly.

Hi,

Sorry for late response. Below is my host file:-

[win]

localhost ansible_connection=local

[win:vars]
ansible_connection=winrm
ansible_ssh_port=5986
ansible_ssh_user=Administrator
ansible_ssh_pass={{ }}
ansible_winrm_server_cert_validation=ignore

Please see and tell what i am doing wrong.

There are a few things wrong with that inventory

  • Change the ansible_ssh_* variables to just ansible_*, e.g. ansible_ssh_port becomes ansible_port and so on
  • You are defining ansible_connection=winrm on the group but then override that with ansible_connection=local on the host var meaning this will run on the Ansible controller
  • You have defined the Windows host as localhost, this is quite rare and I’ve only really seen it for WSL installations
    Try out the following

`
[win]
windows-hostname

[win:vars]
ansible_user=Administrator
ansible_password=…
ansible_port=5986
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore

`

This will connect to the host ‘windows-hostname’ but you can change that to an IP address if you wish.

Thanks

Jordan