Repository: ansible/ansible-modules-extras

Issue:
vmware_local_user_manager error: 'module' not defined
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

vmware_local_user_manager
##### ANSIBLE VERSION

```
ansible 2.2.0 (devel 321d2e8cee) last updated 2016/08/21 14:29:27 (GMT +200)
  lib/ansible/modules/core: (detached HEAD 91a839f1e3) last updated 2016/08/21 14:32:29 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD 1aeb9f8a8c) last updated 2016/08/21 14:32:44 (GMT +200)
```
##### CONFIGURATION

None
##### OS / ENVIRONMENT

Execution from: Ubuntu 14.04
Execution to: VMware ESXi 6.0 U2
##### SUMMARY

Execution of module vmware_local_user_manager fails with error
##### STEPS TO REPRODUCE

```
- name: "vSphere ESXi: Add users"
       vmware_local_user_manager: validate_certs=False hostname={{ inventory_hostname }} username=root password=mypassword local_user_name=foo local_user_password=bar
```
##### EXPECTED RESULTS

Create user on target system
##### ACTUAL RESULTS

Error:

```
TASK [vSphere ESXi: Add users] *************************************************
task path: /home/devel/ansible-configuration/vmware.yml:15
Using module file /home/devel/ansible/lib/ansible/modules/extras/cloud/vmware/vmware_local_user_manager.py
<esxi> ESTABLISH LOCAL CONNECTION FOR USER: devel
<esxi> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1471786926.92-121489380863382 `" && echo ansible-tmp-1471786926.92-121489380863382="` echo $HOME/.ansible/tmp/ansible-tmp-1471786926.92-121489380863382 `" ) && sleep 0'
<esxi> PUT /tmp/tmpHVuXHh TO /home/devel/.ansible/tmp/ansible-tmp-1471786926.92-121489380863382/vmware_local_user_manager.py
<esxi> EXEC /bin/sh -c 'chmod u+x /home/devel/.ansible/tmp/ansible-tmp-1471786926.92-121489380863382/ /home/devel/.ansible/tmp/ansible-tmp-1471786926.92-121489380863382/vmware_local_user_manager.py && sleep 0'
<esxi> EXEC /bin/sh -c '/usr/bin/python /home/devel/.ansible/tmp/ansible-tmp-1471786926.92-121489380863382/vmware_local_user_manager.py; rm -rf "/home/devel/.ansible/tmp/ansible-tmp-1471786926.92-121489380863382/" > /dev/null 2>&1 && sleep 0'
fatal: [esxi]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "hostname": "esxi", 
            "local_user_description": null, 
            "local_user_name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "local_user_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "state": "present", 
            "username": "devel", 
            "validate_certs": false
        }, 
        "module_name": "vmware_local_user_manager"
    }, 
    "msg": "global name 'module' is not defined"
}
```



Discussion:
<!-- @kaisero: Thanks for filing this bug report! -->

@chrrrles ping, this issue is waiting for your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->

I have found the reason for module failure. If the password complexity is not given the module will fail with the error shown. Maybe this should be enhanced to display why the creation has failed.


Resolving patch:
diff --git a/cloud/vmware/vmware_local_user_manager.py b/cloud/vmware/vmware_local_user_manager.py
--- a/cloud/vmware/vmware_local_user_manager.py
+++ b/cloud/vmware/vmware_local_user_manager.py
@@ -137,9 +137,9 @@ def state_create_user(self):
             task = self.content.accountManager.CreateUser(account_spec)
             self.module.exit_json(changed=True)
         except vmodl.RuntimeFault as runtime_fault:
-            module.fail_json(msg=runtime_fault.msg)
+            self.module.fail_json(msg=runtime_fault.msg)
         except vmodl.MethodFault as method_fault:
-            module.fail_json(msg=method_fault.msg)
+            self.module.fail_json(msg=method_fault.msg)
 
     def state_update_user(self):
         account_spec = self.create_account_spec()
@@ -148,9 +148,9 @@ def state_update_user(self):
             task = self.content.accountManager.UpdateUser(account_spec)
             self.module.exit_json(changed=True)
         except vmodl.RuntimeFault as runtime_fault:
-            module.fail_json(msg=runtime_fault.msg)
+            self.module.fail_json(msg=runtime_fault.msg)
         except vmodl.MethodFault as method_fault:
-            module.fail_json(msg=method_fault.msg)
+            self.module.fail_json(msg=method_fault.msg)
 
 
     def state_remove_user(self):
@@ -158,9 +158,9 @@ def state_remove_user(self):
             task = self.content.accountManager.RemoveUser(self.local_user_name)
             self.module.exit_json(changed=True)
         except vmodl.RuntimeFault as runtime_fault:
-            module.fail_json(msg=runtime_fault.msg)
+            self.module.fail_json(msg=runtime_fault.msg)
         except vmodl.MethodFault as method_fault:
-            module.fail_json(msg=method_fault.msg)
+            self.module.fail_json(msg=method_fault.msg)
 
 
     def state_exit_unchanged(self):


Test patch: