# Windows module error with ansible.legacy.setup  PowerShell -NoProfile -NonInteractive?

**URL:** <https://forum.ansible.com/t/windows-module-error-with-ansible-legacy-setup-powershell-noprofile-noninteractive/34422>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [January 11, 2021, 10:16pm UTC](https://forum.ansible.com/t/windows-module-error-with-ansible-legacy-setup-powershell-noprofile-noninteractive/34422 "2021-01-11T22:16:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Nix](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@Ryan\_Nix](https://forum.ansible.com/u/Ryan_Nix)\
**Post date:** [January 11, 2021, 10:16pm UTC](https://forum.ansible.com/t/windows-module-error-with-ansible-legacy-setup-powershell-noprofile-noninteractive/34422/1 "2021-01-11T22:16:28Z")

</div>

Hello,

I had my playbook working perfectly until I made what I thought was a small change! I’m running the latest version of Ansible, version 2.10.4.

Ansible keeps telling me there is a problem with line 1 but I’m having a hard time interpreting what the error means. Almost seems like VS Code did something?

Error:

**_fatal: [server1.edu]: FAILED! =\> {“ansible\_facts”: {}, “changed”: false, “failed\_modules”: {“ansible.legacy.setup”: {“failed”: true, “module\_stderr”: “At line:1 char:26\r\n+ [chcp.com](http://chcp.com) 65001 \>nul 2\>&1 && PowerShell -NoProfile -NonInteractive -Ex …\r\n+ ~~\r\nThe token ‘&&’ is not a valid statement separator in this version.\r\n + CategoryInfo : ParserError: (🙂 [], ParentContainsErrorRecordException\r\n + FullyQualifiedErrorId : InvalidEndOfLine\r\n \r\n”, “module\_stdout”: “”, “msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”, “rc”: 1}}, “msg”: “The following modules failed to execute: ansible.legacy.setup\n”}_**

**_fatal: [server2.edu]: FAILED! =\> {“ansible\_facts”: {}, “changed”: false, “failed\_modules”: {“ansible.legacy.setup”: {“failed”: true, “module\_stderr”: “At line:1 char:26\r\n+ [chcp.com](http://chcp.com) 65001 \>nul 2\>&1 && PowerShell -NoProfile -NonInteractive -Ex …\r\n+ ~~\r\nThe token ‘&&’ is not a valid statement separator in this version.\r\n + CategoryInfo : ParserError: (🙂 [], ParentContainsErrorRecordException\r\n + FullyQualifiedErrorId : InvalidEndOfLine\r\n \r\n”, “module\_stdout”: “”, “msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”, “rc”: 1}}, “msg”: “The following modules failed to execute: ansible.legacy.setup\n”}_**

My playbook:

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [January 11, 2021, 10:48pm UTC](https://forum.ansible.com/t/windows-module-error-with-ansible-legacy-setup-powershell-noprofile-noninteractive/34422/2 "2021-01-11T22:48:38Z")

</div>

> Hello,
> 
> I had my playbook working perfectly until I made what I thought was a small  
> change!

It would probably help if you told us exactly what that change was - show us  
the old version and the new one (or, at least, the bits that are different).

> Ansible keeps telling me there is a problem with line 1 but I'm having a  
> hard time interpreting what the error means. Almost seems like VS Code did  
> something?
> 
> Error:
> 
> "At line:1 char:26\r\n+ chcp.com 65001 \>nul 2\>&1 && PowerShell -NoProfile -  
> NonInteractive -Ex ...\r\n+ ~~\r\nThe token '&&' is not a valid statement  
> separator in this version.\r\n"

That to me looks more like a complaint about the powershell script you're  
using to call ansible than it does about the ansible playbook itself (however  
on the other hand I know nothing whatever about powershell so I could be  
completely wrong). I simply don't see an instance of '&&' in your playbook,  
so the error can't be talking about that.

Antony.

---

<div class="post-metadata">

**Author:** ![Ryan\_Nix](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@Ryan\_Nix](https://forum.ansible.com/u/Ryan_Nix)\
**Post date:** [January 12, 2021, 12:10am UTC](https://forum.ansible.com/t/windows-module-error-with-ansible-legacy-setup-powershell-noprofile-noninteractive/34422/3 "2021-01-12T00:10:47Z")

</div>

Sorry, you’re right, I should have posted what I changed.

I added these lines from the example here. [https://docs.ansible.com/ansible/latest/user\_guide/windows\_setup.html#installing-win32-openssh](https://docs.ansible.com/ansible/latest/user_guide/windows_setup.html#installing-win32-openssh)

- name: set the default shell to PowerShell  
win\_regedit:  
path: HKLM:\SOFTWARE\OpenSSH  
name: DefaultShell  
data: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  
type: string  
state: present

It worked fine when I ran it after the addition, but the _subsequent runs of my playbook_ turned up the error. I’ve even tried removing the “set the default shell to Powershell” snippet and it’s still turning up this vexing error.

So you’re right, it’s like this Powershell example did something that is breaking subsequent runs.

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [January 12, 2021, 12:12am UTC](https://forum.ansible.com/t/windows-module-error-with-ansible-legacy-setup-powershell-noprofile-noninteractive/34422/4 "2021-01-12T00:12:01Z")

</div>

Why do you put that in just out of interest

---

<div class="post-metadata">

**Author:** ![Ryan\_Nix](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@Ryan\_Nix](https://forum.ansible.com/u/Ryan_Nix)\
**Post date:** [January 12, 2021, 12:46am UTC](https://forum.ansible.com/t/windows-module-error-with-ansible-legacy-setup-powershell-noprofile-noninteractive/34422/5 "2021-01-12T00:46:55Z")

</div>

So that when I ssh into our Windows systems, my shell is using Powershell instead of the standard cmd.

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [January 12, 2021, 12:47am UTC](https://forum.ansible.com/t/windows-module-error-with-ansible-legacy-setup-powershell-noprofile-noninteractive/34422/6 "2021-01-12T00:47:58Z")

</div>

The supported process is through winrm.

---

<div class="post-metadata">

**Author:** ![Ryan\_Nix](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@Ryan\_Nix](https://forum.ansible.com/u/Ryan_Nix)\
**Post date:** [January 12, 2021, 2:53am UTC](https://forum.ansible.com/t/windows-module-error-with-ansible-legacy-setup-powershell-noprofile-noninteractive/34422/7 "2021-01-12T02:53:04Z")

</div>

I’m aware that using SSH with Windows is experimental. The connection isn’t the issue, though.

---

<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:** [January 12, 2021, 8:07pm UTC](https://forum.ansible.com/t/windows-module-error-with-ansible-legacy-setup-powershell-noprofile-noninteractive/34422/8 "2021-01-12T20:07:47Z")

</div>

If your default shell is PowerShell you need to tell Ansible that with ‘ansible\_shell\_type=powershell’. Right now it’s using cmd hence the cmd syntax which isn’t valid in PowerShell.

---

<div class="post-metadata">

**Author:** ![Ryan\_Nix](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@Ryan\_Nix](https://forum.ansible.com/u/Ryan_Nix)\
**Post date:** [January 12, 2021, 10:19pm UTC](https://forum.ansible.com/t/windows-module-error-with-ansible-legacy-setup-powershell-noprofile-noninteractive/34422/9 "2021-01-12T22:19:49Z")

</div>

Ah, that makes more sense.

Thank you so much!!!

---

<div class="post-metadata">

**Author:** ![Ryan\_Nix](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@Ryan\_Nix](https://forum.ansible.com/u/Ryan_Nix)\
**Post date:** [January 12, 2021, 10:28pm UTC](https://forum.ansible.com/t/windows-module-error-with-ansible-legacy-setup-powershell-noprofile-noninteractive/34422/10 "2021-01-12T22:28:32Z")

</div>

As it turns out I had _ansible\_shell\_type=cmd_ in my ansible host’s file under the windows server section. Thanks again for the help!
