# Buggy code
def main():
    argument_spec = influx.InfluxDb.influxdb_argument_spec()
    argument_spec.update(
        state=dict(default="present", type="str", choices=["present", "absent"]),
        user_name=dict(required=True, type="str"),
        user_password=dict(required=False, type="str", no_log=True),
        admin=dict(default="False", type="bool"),
    )
    module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

    state = module.params["state"]
    user_name = module.params["user_name"]
    user_password = module.params["user_password"]
    admin = module.params["admin"]
    influxdb = influx.InfluxDb(module)
    client = influxdb.connect_to_influxdb()
    user = find_user(module, client, user_name)

    if state == "present":
        if user:
            changed = False

            if not check_user_password(module, client, user_name, user_password):
                set_user_password(module, client, user_name, user_password)
                changed = True

            try:
                if admin and not user["admin"]:
                    client.grant_admin_privileges(user_name)
                    changed = True
                elif not admin and user["admin"]:
                    client.revoke_admin_privileges(user_name)
                    changed = True
            except influx.exceptions.InfluxDBClientError as e:
                module.fail_json(msg=str(e))

            module.exit_json(changed=changed)
        else:
            create_user(module, client, user_name, user_password, admin)

    if state == "absent":
        if user:
            drop_user(module, client, user_name)
        else:
            module.exit_json(changed=False)


# Traceback (AttributeError)
The full traceback is:
Traceback (most recent call last):
File "/home/vagrant/.ansible/tmp/ansible-tmp-1539579756.75-154851055502461/AnsiballZ_influxdb_user.py", line 113, in <module>
_ansiballz_main()
File "/home/vagrant/.ansible/tmp/ansible-tmp-1539579756.75-154851055502461/AnsiballZ_influxdb_user.py", line 105, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/vagrant/.ansible/tmp/ansible-tmp-1539579756.75-154851055502461/AnsiballZ_influxdb_user.py", line 48, in invoke_module
imp.load_module('__main__', mod, module, MOD_DESC)
File "/tmp/ansible_influxdb_user_payload_ko89m0/__main__.py", line 184, in <module>
File "/tmp/ansible_influxdb_user_payload_ko89m0/__main__.py", line 174, in main
File "/tmp/ansible_influxdb_user_payload_ko89m0/__main__.py", line 129, in create_user
File "/home/vagrant/.local/lib/python2.7/site-packages/influxdb/client.py", line 783, in create_user
quote_ident(username), quote_literal(password))
File "/home/vagrant/.local/lib/python2.7/site-packages/influxdb/line_protocol.py", line 77, in quote_literal
return "'{}'".format(value
AttributeError: 'NoneType' object has no attribute 'replace'

fatal: [127.0.0.1]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1539579756.75-154851055502461/AnsiballZ_influxdb_user.py\", line 113, in <module>\n    _ansiballz_main()\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1539579756.75-154851055502461/AnsiballZ_influxdb_user.py\", line 105, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1539579756.75-154851055502461/AnsiballZ_influxdb_user.py\", line 48, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/tmp/ansible_influxdb_user_payload_ko89m0/__main__.py\", line 184, in <module>\n  File \"/tmp/ansible_influxdb_user_payload_ko89m0/__main__.py\", line 174, in main\n  File \"/tmp/ansible_influxdb_user_payload_ko89m0/__main__.py\", line 129, in create_user\n  File \"/home/vagrant/.local/lib/python2.7/site-packages/influxdb/client.py\", line 783, in create_user\n    quote_ident(username), quote_literal(password))\n  File \"/home/vagrant/.local/lib/python2.7/site-packages/influxdb/line_protocol.py\", line 77, in quote_literal\n    return \"'{}'\".format(value\nAttributeError: 'NoneType' object has no attribute 'replace'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}

# Fixed code
def main():
    argument_spec = influx.InfluxDb.influxdb_argument_spec()
    argument_spec.update(
        state=dict(default="present", type="str", choices=["present", "absent"]),
        user_name=dict(required=True, type="str"),
        user_password=dict(required=False, type="str", no_log=True),
        admin=dict(default="False", type="bool"),
    )
    module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

    state = module.params["state"]
    user_name = module.params["user_name"]
    user_password = module.params["user_password"] or ""
    admin = module.params["admin"]
    influxdb = influx.InfluxDb(module)
    client = influxdb.connect_to_influxdb()
    user = find_user(module, client, user_name)

    if state == "present":
        if user:
            changed = False

            if not check_user_password(module, client, user_name, user_password):
                set_user_password(module, client, user_name, user_password)
                changed = True

            try:
                if admin and not user["admin"]:
                    client.grant_admin_privileges(user_name)
                    changed = True
                elif not admin and user["admin"]:
                    client.revoke_admin_privileges(user_name)
                    changed = True
            except influx.exceptions.InfluxDBClientError as e:
                module.fail_json(msg=str(e))

            module.exit_json(changed=changed)
        else:
            create_user(module, client, user_name, user_password, admin)

    if state == "absent":
        if user:
            drop_user(module, client, user_name)
        else:
            module.exit_json(changed=False)