Ansible troubleshooting - Unhandled exception while executing module win_user
Unhandled exception errors are nasty Ansible problems. In a live demo, we are going to troubleshoot starting from the error message. We are going to investigate the root cause of the problem and fix using the win_user module.


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.
The Best Resources For Ansible
Certifications
Video Course
Printed Book
eBooks
Ansible by Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Ansible Cookbook: A Comprehensive Guide to Unleashing the Power of Ansible via Best Practices, Troubleshooting, and Linting Rules with Luca Berton
Ansible For Windows By Examples: 50+ Automation Examples For Windows System Administrator And DevOps
Ansible For Linux by Examples: 100+ Automation Examples For Linux System Administrator and DevOps
Ansible Linux Filesystem By Examples: 40+ Automation Examples on Linux File and Directory Operation for Modern IT Infrastructure
Ansible For Security by Examples: 100+ Automation Examples to Automate Security and Verify Compliance for IT Modern Infrastructure
Ansible Tips and Tricks: 10+ Ansible Examples to Save Time and Automate More Tasks
Ansible Linux Users & Groups By Examples: 20+ Automation Examples on Linux Users and Groups Operation for Modern IT Infrastructure
Ansible For PostgreSQL by Examples: 10+ Examples To Automate Your PostgreSQL database
Ansible For Amazon Web Services AWS By Examples: 10+ Examples To Automate Your AWS Modern Infrastructure
Ansible Automation Platform By Example: A step-by-step guide for the most common user scenarios
demo
The best way of talking about Ansible troubleshooting is to jump in a live demo 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
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 $
Recap
Now you know better how to troubleshoot the Ansible Unhandled exception while executing the module win_user message. Subscribe to the YouTube channel, Medium, Website, Twitter, and Substack to not miss the next episode of the Ansible Pilot.
Academy
Learn the Ansible automation technology with some real-life examples in my
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate