Ansible Pilot

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.

March 23, 2022
Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons

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

Video Course

Books

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

win_user troubleshooting

fix code

---
- name: windows user add
  hosts: all
  vars:
    usr_name: 'example'
    usr_password: '[email protected]'
  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

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

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

Want to keep this project going? Please donate

Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons
Trustpilot
Follow me

Subscribe not to miss any new releases

FREE Top 10 Best Practices

Top 10 Best Practices of Ansible Automation: save time, reduce errors and stress