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

**URL:** <https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [April 25, 2018, 11:01am UTC](https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369 "2018-04-25T11:01:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ali.khawaja](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@ali.khawaja](https://forum.ansible.com/u/ali.khawaja)\
**Post date:** [April 25, 2018, 11:01am UTC](https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369/1 "2018-04-25T11:01:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Virasat\_Khan](https://avatars.discourse-cdn.com/v4/letter/v/eb9ed0/32.png) [@Virasat\_Khan](https://forum.ansible.com/u/Virasat_Khan)\
**Post date:** [April 25, 2018, 8:31pm UTC](https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369/2 "2018-04-25T20:31:16Z")

</div>

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?

---

<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:** [April 25, 2018, 9:18pm UTC](https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369/3 "2018-04-25T21:18:51Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![ali.khawaja](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@ali.khawaja](https://forum.ansible.com/u/ali.khawaja)\
**Post date:** [April 25, 2018, 10:01pm UTC](https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369/4 "2018-04-25T22:01:14Z")

</div>

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

---

<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:** [April 25, 2018, 11:39pm UTC](https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369/5 "2018-04-25T23:39:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ali.khawaja](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@ali.khawaja](https://forum.ansible.com/u/ali.khawaja)\
**Post date:** [April 26, 2018, 9:12am UTC](https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369/6 "2018-04-26T09:12:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ali.khawaja](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@ali.khawaja](https://forum.ansible.com/u/ali.khawaja)\
**Post date:** [April 29, 2018, 8:27am UTC](https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369/7 "2018-04-29T08:27:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Akshay\_Kaushik](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@Akshay\_Kaushik](https://forum.ansible.com/u/Akshay_Kaushik)\
**Post date:** [October 27, 2018, 5:04am UTC](https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369/8 "2018-10-27T05:04:52Z")

</div>

> 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

---

<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:** [October 27, 2018, 12:44pm UTC](https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369/9 "2018-10-27T12:44:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Akshay\_Kaushik](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@Akshay\_Kaushik](https://forum.ansible.com/u/Akshay_Kaushik)\
**Post date:** [November 10, 2018, 1:12pm UTC](https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369/10 "2018-11-10T13:12:12Z")

</div>

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.

---

<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:** [November 11, 2018, 8:29pm UTC](https://forum.ansible.com/t/bin-sh-1-powershell-not-found-n/27369/11 "2018-11-11T20:29:26Z")

</div>

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
