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

[1]
https://docs.ansible.com/ansible/latest/user_guide/windows.html#windows-guides

https://www.ansible.com/resources/webinars-training/introduction-to-ansible

-
Ompragash

On Sat, 30 May 2020 at 07:37, Work-Hard <[email protected]> wrote:

> 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
>
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/d3ac2729-3f78-49f5-a834-1b40e1de81a6%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/d3ac2729-3f78-49f5-a834-1b40e1de81a6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAEFccTWN1fcKYYXpqq1iwXHRaNzabvJHwTQqGNnCKpzHsHJ%2BtA%40mail.gmail.com.

Reply via email to