AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible troubleshooting - Module Failure on Windows-target

By Luca Berton · Published 2024-01-01 · Category: installation

Discover how to troubleshoot Module Failure on Windows-target in Ansible, focusing on resolving execution errors effectively.

Ansible troubleshooting - Module Failure on Windows-target

Introduction

Today we’re going to talk about Ansible troubleshooting, specifically about the Module Failure on Windows-target. I’m Luca Berton and welcome to today’s episode of Ansible Pilot.

See also: Ansible troubleshooting - Windows 10 Error 0x80370102 WSL: Windows Subsystem for Linux

Root Cause

The error occurs when you use a Linux/Unix module (ansible.builtin.get_url) on a Windows target. Ansible tries to execute Python code on the Windows host, but Windows runs PowerShell — not Python. The error message shows PowerShell trying to parse Python syntax and failing.

The fix: Use the Windows-specific module ansible.windows.win_get_url instead of ansible.builtin.get_url.

Common Module Mapping: Linux vs Windows

| Linux Module | Windows Module | Purpose | |---|---|---| | ansible.builtin.get_url | ansible.windows.win_get_url | Download files | | ansible.builtin.copy | ansible.windows.win_copy | Copy files to remote | | ansible.builtin.file | ansible.windows.win_file | Manage files/directories | | ansible.builtin.template | ansible.windows.win_template | Deploy templates | | ansible.builtin.service | ansible.windows.win_service | Manage services | | ansible.builtin.user | ansible.windows.win_user | Manage users | | ansible.builtin.package | chocolatey.chocolatey.win_chocolatey | Install packages | | ansible.builtin.command | ansible.windows.win_command | Run commands | | ansible.builtin.shell | ansible.windows.win_shell | Run shell commands |

See also: Ansible troubleshooting - Windows 11 Error 0x80370102 WSL: Windows Subsystem for Linux

How to Identify This Error

Look for these signs in the error output: "No python interpreters found" — Ansible is looking for Python on a Windows host PowerShell parse errors"An expression was expected after", ParseException "MODULE FAILURE" with rc: 1 Python syntax in module_stderrdef, import, sys.version_info

Playbook

How to troubleshoot the Module Failure on Windows-target.

See also: Ansible 'Destination Does Not Exist' Error: Fix Path Issues

error code

---
- name: win_get_url module Playbook
  hosts: all
  become: false
  vars:
    myurl: "https://releases.ansible.com/ansible/ansible-2.9.25.tar.gz"
    mydest: 'C:\Users\vagrant\Desktop\ansible-2.9.25.tar.gz'
  tasks:
    - name: download file
      ansible.builtin.get_url:
        url: "{{ myurl }}"
        dest: "{{ mydest }}"

error execution

ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory troubleshooting/get_url_error.yml
PLAY [win_get_url module Playbook] ********************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [WindowsServer]
TASK [download file] ******************************************************************************
[WARNING]: No python interpreters found for host WindowsServer (tried ['python3.10', 'python3.9',
'python3.8', 'python3.7', 'python3.6', 'python3.5', '/usr/bin/python3', '/usr/libexec/platform-
python', 'python2.7', 'python2.6', '/usr/bin/python', 'python'])
fatal: [WindowsServer]: FAILED! => {"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:8 char:19\r\n+         os.getcwd()\r\n+                   ~\r\nAn expression was expected after '('.\r\nAt line:20 char:27\r\n+     except (AttributeError, OSError):\r\n+                           ~\r\nMissing argument in parameter list.\r\nAt line:22 char:29\r\n+     excludes = set(('', '.', scriptdir))\r\n+                             ~\r\nMissing expression after ','.\r\nAt line:22 char:30\r\n+     excludes = set(('', '.', scriptdir))\r\n+                              ~~~~~~~~~\r\nUnexpected token 'scriptdir' in expression or statement.\r\nAt line:22 char:29\r\n+     excludes = set(('', '.', scriptdir))\r\n+                             ~\r\nMissing closing ')' in expression.\r\nAt line:22 char:39\r\n+     excludes = set(('', '.', scriptdir))\r\n+                                       ~\r\nUnexpected token ')' in expression or statement.\r\nAt line:22 char:40\r\n+     excludes = set(('', '.', scriptdir))\r\n+                                        ~\r\nUnexpected token ')' in expression or statement.\r\nAt line:29 char:7\r\n+     if sys.version_info < (3,):\r\n+       ~\r\nMissing '(' after 'if' in if statement.\r\nAt line:29 char:30\r\n+     if sys.version_info < (3,):\r\n+                              ~\r\nMissing expression after ','.\r\nNot all parse errors were reported.  Correct the reported errors and try again.\"\r\nAt line:10 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:11 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}
PLAY RECAP ****************************************************************************************
WindowsServer              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
ansible-pilot $

fix code

---
- name: win_get_url module Playbook
  hosts: all
  become: false
  vars:
    myurl: "https://releases.ansible.com/ansible/ansible-2.9.25.tar.gz"
    mydest: 'C:\Users\vagrant\Desktop\ansible-2.9.25.tar.gz'
  tasks:
    - name: download file
      ansible.windows.win_get_url:
        url: "{{ myurl }}"
        dest: "{{ mydest }}"

fix execution

ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory troubleshooting/get_url_fix.yml
PLAY [win_get_url module Playbook] ********************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [WindowsServer]
TASK [download file] ******************************************************************************
changed: [WindowsServer]
PLAY RECAP ****************************************************************************************
WindowsServer              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ansible-pilot $

code with ❤️ in GitHub

Conclusion

Now you know better how to troubleshoot the Module Failure on Windows-target and how to fix it.

Related Articles

the Ansible become referenceAnsible inventory best practicesdesired-state Windows config with Ansible

FAQ

Why does Ansible try to run Python on Windows?

Linux modules (ansible.builtin.) are Python scripts designed for Unix systems. When used on Windows targets, Ansible sends Python code that PowerShell cannot execute. Windows targets require dedicated ansible.windows. modules that use PowerShell.

How do I know which module to use for Windows?

Check the module documentation. Windows modules are in the ansible.windows collection and are prefixed with win_. Install with: ansible-galaxy collection install ansible.windows.

Can I write playbooks that work on both Linux and Windows?

Yes, use when conditions based on ansible_os_family:

- name: Download file (Linux)
  ansible.builtin.get_url:
    url: "{{ myurl }}"
    dest: "{{ dest_linux }}"
  when: ansible_os_family != "Windows"

- name: Download file (Windows) ansible.windows.win_get_url: url: "{{ myurl }}" dest: "{{ dest_windows }}" when: ansible_os_family == "Windows"

Category: installation

Watch the video: Ansible troubleshooting - Module Failure on Windows-target — Video Tutorial

Browse all Ansible tutorials · AnsiblePilot Home