Introduction

Today we’re going to talk about Ansible troubleshooting, specifically about Ansible troubleshooting - Unhandled exception while executing module win_user. This is a tricky fatal error message that happens when something extraordinary happens during the module execution. These circumstances are usually not related to Ansible and you need to deep dive into the system configuration. I’m Luca Berton and welcome to today’s episode of Ansible Pilot.

Join 50+ hours of courses in our exclusive community

Playbook

The best way of talking about Ansible troubleshooting is to jump in a live Playbook to show you practically the Unhandled exception while executing module win_user and how to solve it!

error code

---
- name: windows user add
  hosts: all
  vars:
    usr_name: 'example'
    usr_password: 'password'
  tasks:
    - name: create local user
      ansible.windows.win_user:
        name: "{{ usr_name }}"
        password: "{{ usr_password }}"

error execution

ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory troubleshooting/windows_user_add_error.yml
PLAY [windows user add] ***************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [WindowsServer]
TASK [create local user] **************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: at <ScriptBlock>, <No file>: line 260
fatal: [WindowsServer]: FAILED! => {"changed": false, "msg": "Unhandled exception while executing module: Exception calling \"SetPassword\" with \"1\" argument(s): \"The password does not meet the password policy requirements. Check the minimum password length, password complexity and password history requirements.\r\n\""}
PLAY RECAP ****************************************************************************************
WindowsServer              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
ansible-pilot $

troubleshooting

win_user troubleshooting

fix code

---
- name: windows user add
  hosts: all
  vars:
    usr_name: 'example'
    usr_password: 'NRns@bOFJNyX'
  tasks:
    - name: create local user
      ansible.windows.win_user:
        name: "{{ usr_name }}"
        password: "{{ usr_password }}"

fix execution

ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory troubleshooting/windows_user_add_fix.yml
PLAY [windows user add] ***************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [WindowsServer]
TASK [create local user] **************************************************************************
changed: [WindowsServer]
PLAY RECAP ****************************************************************************************
WindowsServer              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ansible-pilot $

win_user after execution

code with ❤️ in GitHub

Conclusion

Now you know better how to troubleshoot the Ansible Unhandled exception while executing the module win_user message. Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.

Academy

Learn the Ansible automation technology with some real-life examples in my Udemy 300+ Lessons Video Course.

BUY the Complete Udemy 300+ Lessons Video Course

My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Want to keep this project going? Please donate

Patreon Buy me a Pizza