# Unable to run command on windows. Please explain!

**URL:** <https://forum.ansible.com/t/unable-to-run-command-on-windows-please-explain/33056>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [May 30, 2020, 2:07am UTC](https://forum.ansible.com/t/unable-to-run-command-on-windows-please-explain/33056 "2020-05-30T02:07:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Work\_Email](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@Work\_Email](https://forum.ansible.com/u/Work_Email)\
**Post date:** [May 30, 2020, 2:07am UTC](https://forum.ansible.com/t/unable-to-run-command-on-windows-please-explain/33056/1 "2020-05-30T02:07:02Z")

</div>

Hi, I am unable to run command and throws an error. What am I doing wrong? Please explain! Thanks

“ansible\_facts”: {  
“discovered\_interpreter\_python”: “/usr/bin/python”  
},  
“changed”: false,  
“module\_stderr”: "Exception calling "Create" with "1" argument(s): "At line:4 char:21\r\n+ def \_ansiballz\_main():\r\n+ ~\r\nAn expression was expected after ‘(’.\r\nAt line:13 char:27\r\n+ except (AttributeError, OSError):\r\n+ ~\r\nMissing argument in parameter list.\r\nAt line:15 char:7\r\n+ if scriptdir is not None:\r\n+ ~\r\nMissing ‘(’ after ‘if’ in if statement.\r\nAt line:22 char:7\r\n+ if sys.version\_info \< (3,):\r\n+ ~\r\nMissing ‘(’ after ‘if’ in if statement.\r\nAt line:22 char:30\r\n+ if sys.version\_info \< (3,):\r\n+ ~\r\nMissing expression after ‘,’.\r\nAt line:22 char:25\r\n+ if sys.version\_info \< (3,):\r\n+ ~\r\nThe ‘\<’ operator is reserved for future use.\r\nAt line:27 char:34\r\n+ def invoke\_module(modlib\_path, temp\_path, json\_params):\r\n+ ~\r\nMissing argument in parameter list.\r\nAt line:28 char:40\r\n+ z = zipfile.ZipFile(modlib\_path, mode=‘a’)\r\n+ ~\r\nMissing argument in parameter list.\r\nAt line:31 char:33\r\n+ zinfo = zipfile.ZipInfo()\r\n+ ~\r\nAn expression was expected after ‘(’.\r\nAt line:34 char:25\r\n+ z.writestr(zinfo, sitecustomize)\r\n+ ~\r\nMissing argument in parameter list.\r\nNot all parse errors were reported. Correct the reported errors and try again."\r\nAt line:6 char:1\r\n+ $exec\_wrapper = [ScriptBlock]::Create($split\_parts[0])\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : NotSpecified: (🙂 , MethodInvocationException\r\n + FullyQualifiedErrorId : ParseException\r\n \r\nThe expression after ‘&’ in a pipeline element produced an object that was not valid. It must result in a command \r\nname, a script block, or a CommandInfo object.\r\nAt line:7 char:2\r\n+ &$exec\_wrapper\r\n+~~~~~~~~~~~~~\r\n + CategoryInfo : InvalidOperation: (🙂 , RuntimeException\r\n + FullyQualifiedErrorId : BadExpression\r\n ",  
“module\_stdout”: “”,  
“msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”,  
“rc”: 1  
}

task:

- hosts: windows  
vars:  
ansible\_connection: winrm  
ansible\_ssh\_port: 5986  
anisble\_winrm\_transport: kerberos  
ansible\_winrm\_server\_cert\_validation: ignore  
validate\_certs: false  
ansible\_winrm\_scheme: https  
ansibe\_winrm\_read\_timeout\_sec: 30  
ignore\_unreachable: true  
gather\_facts: false  
tasks:

- name: Updating intial GPO’s  
command:  
cmd: gpupdate/force

- name: Reboot the workstation for first intiation  
command:  
cmd: shutdown/r  
pause:  
minutes: 1

- name: Ensure WinRM starts when the system has settled and is ready to work reliably  
win\_service:  
name: WinRM  
start\_mode: delayed

- name: Ensure we wait long enough for the updates to be applied during reboot  
win\_updates:  
reboot: yes  
reboot\_timeout: 3600  
ignore\_errors: yes

- name: Updating GPO’s  
command:  
cmd: gpupdate/force

- name: Reboot the workstation  
command:  
cmd: shutdown/r  
pause:  
minutes: 1

- name: Ensure WinRM starts when the system has settled and is ready to work reliably  
win\_service:  
name: WinRM  
start\_mode: delayed

- name: Ensure we wait long enough for the updates to be applied during reboot  
win\_updates:  
reboot: yes  
reboot\_timeout: 3600  
ignore\_errors: yes

---

<div class="post-metadata">

**Author:** ![Ompragash](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ompragash/32/9070_2.png) [@Ompragash](https://forum.ansible.com/u/Ompragash)\
**Post date:** [May 30, 2020, 5:45am UTC](https://forum.ansible.com/t/unable-to-run-command-on-windows-please-explain/33056/2 "2020-05-30T05:45:36Z")

</div>

You cannot use python modules(i.e. command) against windows server. Try with win\_command module. Also, you need to modify your entire playbook as it’s incorrect.

Both “ignore\_unreachable” and “gather\_facts” are playbook keywords and you cannot pass them as variables check[0].

You’ve also passed inventory parameters(i.e. ansible\_\*) as variables which is wrong. Follow[1] Ansible Windows guide to set up and manage windows server from Ansible.

[0] Ansible Playbook Keywords: [https://docs.ansible.com/ansible/latest/reference\_appendices/playbooks\_keywords.html#playbook-keywords](https://docs.ansible.com/ansible/latest/reference_appendices/playbooks_keywords.html#playbook-keywords)

[1] [https://docs.ansible.com/ansible/latest/user\_guide/windows.html#windows-guides](https://docs.ansible.com/ansible/latest/user_guide/windows.html#windows-guides)

[https://www.ansible.com/resources/webinars-training/introduction-to-ansible](https://www.ansible.com/resources/webinars-training/introduction-to-ansible)
