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

1,512 views
Skip to first unread message

Ryan Nix

unread,
Jan 11, 2021, 5:16:28 PM1/11/21
to Ansible Project
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 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 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:



---
-
hosts: windows
tasks:
- name: Copy ssh public key to server(s)
ansible.windows.win_copy:
src: /Users/rtn361/.ssh/id_rsa.pub
dest: C:\Users\sadmin\.ssh\authorized_keys

- name: Update Acme's Windows 2012, 2016 and 2019 servers
ansible.windows.win_updates:
category_name:
- SecurityUpdates
- CriticalUpdates
reboot: yes
reboot_timeout: 360
log_path: C:\ansible_wu.txt

- 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
# output results
- name: Display any useful output
debug:
var: hostvars[inventory_hostname]
verbosity: 4

Antony Stone

unread,
Jan 11, 2021, 5:49:05 PM1/11/21
to ansible...@googlegroups.com
On Monday 11 January 2021 at 23:16:28, Ryan Nix wrote:

> 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.

--
All generalisations are inaccurate.

Please reply to the list;
please *don't* CC me.

Ryan Nix

unread,
Jan 11, 2021, 7:10:47 PM1/11/21
to Ansible Project
Sorry, you're right, I should have posted what I changed.


- 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.

Wei-Yen Tan

unread,
Jan 11, 2021, 7:12:20 PM1/11/21
to ansible...@googlegroups.com
Why do you put that in just out of interest


From: ansible...@googlegroups.com <ansible...@googlegroups.com> on behalf of Ryan Nix <ryan...@gmail.com>
Sent: Tuesday, January 12, 2021 1:10:47 PM
To: Ansible Project <ansible...@googlegroups.com>
Subject: Re: [ansible-project] Windows module error with ansible.legacy.setup PowerShell -NoProfile -NonInteractive?
 
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/89476fe1-6c90-470a-ba9b-2e58f6b303een%40googlegroups.com.

Ryan Nix

unread,
Jan 11, 2021, 7:46:55 PM1/11/21
to Ansible Project
So that when I ssh into our Windows systems, my shell is using Powershell instead of the standard cmd.

Wei-Yen Tan

unread,
Jan 11, 2021, 7:48:17 PM1/11/21
to ansible...@googlegroups.com
The supported process is through winrm.


Sent: Tuesday, January 12, 2021 1:46:55 PM

Ryan Nix

unread,
Jan 11, 2021, 9:53:05 PM1/11/21
to Ansible Project
I'm aware that using SSH with Windows is experimental. The connection isn't the issue, though.

jbor...@gmail.com

unread,
Jan 12, 2021, 3:07:47 PM1/12/21
to Ansible Project
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.

Ryan Nix

unread,
Jan 12, 2021, 5:19:49 PM1/12/21
to Ansible Project
Ah, that makes more sense. 

Thank you so much!!!

Ryan Nix

unread,
Jan 12, 2021, 5:28:32 PM1/12/21
to Ansible Project

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!
On Tuesday, January 12, 2021 at 2:07:47 PM UTC-6 jbor...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages