gurudesh/pytracebugs huggingface dataset:
# Buggy code
def exists(self, path):
    path = self._escape(self._unquote(path))
    script = (
        """
            If (Test-Path "%s")
            {
                $res = 0;
            }
            Else
            {
                $res = 1;
            }
            Write-Output "$res";
            Exit $res;
         """
        % path
    )
    return self._encode_script(script)


# Traceback (OSError)
TASK [fetch log files] ***********************************************************************************************************************************************************************
task path: /home/testuser/ansible/test.yml:12
Using module file /usr/local/ansible/2.7/lib/python3.6/site-packages/ansible/modules/windows/win_stat.ps1
<testclient> ESTABLISH WINRM CONNECTION FOR USER: testuser@DOMAIN on PORT 5985 TO testclient
checking if winrm_host testclient is an IPv6 address
EXEC (via pipeline wrapper)
<testclient> FETCH "C:\Temp\testfile_with_$dollar.txt" TO "/home/testuser/ansible/testfile_with_$dollar.txt"
Traceback (most recent call last):
File "/usr/local/ansible/2.7/lib/python3.6/site-packages/ansible/plugins/connection/winrm.py", line 681, in fetch_file
raise IOError(to_native(result.std_err))
OSError: #< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">The variable '$dollar' cannot be retrieved because it has not been set._x000D__x000A_</S><S S="Error">At line:2 char:32_x000D__x000A_</S><S S="Error">+ $path = "C:\Temp\testfile_with_$dollar.txt"_x000D__x000A_</S><S S="Error">+                                ~~~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : InvalidOperation: (dollar:String) [], RuntimeExc _x000D__x000A_</S><S S="Error">   eption_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : VariableIsUndefined_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S><S S="Error">The variable '$path' cannot be retrieved because it has not been set._x000D__x000A_</S><S S="Error">At line:3 char:21_x000D__x000A_</S><S S="Error">+ If (Test-Path -Path $path -PathType Leaf)_x000D__x000A_</S><S S="Error">+                     ~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : InvalidOperation: (path:String) [], RuntimeExcep _x000D__x000A_</S><S S="Error">   tion_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : VariableIsUndefined_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>
fatal: [testclient]: FAILED! => {}

# Fixed code
def exists(self, path):
    path = self._escape(self._unquote(path))
    script = (
        """
            If (Test-Path '%s')
            {
                $res = 0;
            }
            Else
            {
                $res = 1;
            }
            Write-Output '$res';
            Exit $res;
         """
        % path
    )
    return self._encode_script(script)
# Buggy code
def ensure_map_public(conn, module, subnet, map_public, check_mode):
    if check_mode:
        return
    try:
        conn.modify_subnet_attribute(
            SubnetId=subnet["id"], MapPublicIpOnLaunch={"Value": map_public}
        )
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg="Couldn't modify subnet attribute")


# Traceback (ClientError)
Traceback (most recent call last):
File "/tmp/ansible_dPE6PL/ansible_module_ec2_vpc_net.py", line 203, in get_vpc
classic_link = connection.describe_vpc_classic_link(VpcIds=[vpc_id])['Vpcs'][0].get('ClassicLinkEnabled')
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 317, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 615, in _make_api_call
raise error_class(parsed_response, operation_name)
ClientError: An error occurred (InvalidVpcID.NotFound) when calling the DescribeVpcClassicLink operation: The vpc ID 'vpc-1b2bda60' does not exist

# Fixed code
def ensure_map_public(conn, module, subnet, map_public, check_mode, start_time):
    if check_mode:
        return
    try:
        conn.modify_subnet_attribute(
            SubnetId=subnet["id"], MapPublicIpOnLaunch={"Value": map_public}
        )
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg="Couldn't modify subnet attribute")

    if module.params["wait"]:
        if map_public:
            handle_waiter(
                conn,
                module,
                "subnet_has_map_public",
                {"SubnetIds": [subnet["id"]]},
                start_time,
            )
        else:
            handle_waiter(
                conn,
                module,
                "subnet_no_map_public",
                {"SubnetIds": [subnet["id"]]},
                start_time,
            )
# Buggy code
def ensure_assign_ipv6_on_create(
    conn, module, subnet, assign_instances_ipv6, check_mode
):
    if check_mode:
        return

    try:
        conn.modify_subnet_attribute(
            SubnetId=subnet["id"],
            AssignIpv6AddressOnCreation={"Value": assign_instances_ipv6},
        )
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg="Couldn't modify subnet attribute")


# Traceback (ClientError)
Traceback (most recent call last):
File "/tmp/ansible_dPE6PL/ansible_module_ec2_vpc_net.py", line 203, in get_vpc
classic_link = connection.describe_vpc_classic_link(VpcIds=[vpc_id])['Vpcs'][0].get('ClassicLinkEnabled')
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 317, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 615, in _make_api_call
raise error_class(parsed_response, operation_name)
ClientError: An error occurred (InvalidVpcID.NotFound) when calling the DescribeVpcClassicLink operation: The vpc ID 'vpc-1b2bda60' does not exist

# Fixed code
def ensure_assign_ipv6_on_create(
    conn, module, subnet, assign_instances_ipv6, check_mode, start_time
):
    if check_mode:
        return
    try:
        conn.modify_subnet_attribute(
            SubnetId=subnet["id"],
            AssignIpv6AddressOnCreation={"Value": assign_instances_ipv6},
        )
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg="Couldn't modify subnet attribute")

    if module.params["wait"]:
        if assign_instances_ipv6:
            handle_waiter(
                conn,
                module,
                "subnet_has_assign_ipv6",
                {"SubnetIds": [subnet["id"]]},
                start_time,
            )
        else:
            handle_waiter(
                conn,
                module,
                "subnet_no_assign_ipv6",
                {"SubnetIds": [subnet["id"]]},
                start_time,
            )
# Buggy code
def disassociate_ipv6_cidr(conn, module, subnet):
    if subnet.get("assign_ipv6_address_on_creation"):
        ensure_assign_ipv6_on_create(conn, module, subnet, False, False)

    try:
        conn.disassociate_subnet_cidr_block(AssociationId=subnet["ipv6_association_id"])
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(
            e,
            msg="Couldn't disassociate ipv6 cidr block id {0} from subnet {1}".format(
                subnet["ipv6_association_id"], subnet["id"]
            ),
        )


# Traceback (ClientError)
Traceback (most recent call last):
File "/tmp/ansible_dPE6PL/ansible_module_ec2_vpc_net.py", line 203, in get_vpc
classic_link = connection.describe_vpc_classic_link(VpcIds=[vpc_id])['Vpcs'][0].get('ClassicLinkEnabled')
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 317, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 615, in _make_api_call
raise error_class(parsed_response, operation_name)
ClientError: An error occurred (InvalidVpcID.NotFound) when calling the DescribeVpcClassicLink operation: The vpc ID 'vpc-1b2bda60' does not exist

# Fixed code
def disassociate_ipv6_cidr(conn, module, subnet, start_time):
    if subnet.get("assign_ipv6_address_on_creation"):
        ensure_assign_ipv6_on_create(conn, module, subnet, False, False, start_time)

    try:
        conn.disassociate_subnet_cidr_block(AssociationId=subnet["ipv6_association_id"])
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(
            e,
            msg="Couldn't disassociate ipv6 cidr block id {0} from subnet {1}".format(
                subnet["ipv6_association_id"], subnet["id"]
            ),
        )

    # Wait for cidr block to be disassociated
    if module.params["wait"]:
        filters = ansible_dict_to_boto3_filter_list(
            {
                "ipv6-cidr-block-association.state": ["disassociated"],
                "vpc-id": subnet["vpc_id"],
            }
        )
        handle_waiter(
            conn,
            module,
            "subnet_exists",
            {"SubnetIds": [subnet["id"]], "Filters": filters},
            start_time,
        )
# Buggy code
def ensure_subnet_absent(conn, module):
    subnet = get_matching_subnet(
        conn, module, module.params["vpc_id"], module.params["cidr"]
    )
    if subnet is None:
        return {"changed": False}

    try:
        if not module.check_mode:
            conn.delete_subnet(SubnetId=subnet["id"])
        return {"changed": True}
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg="Couldn't delete subnet")


# Traceback (ClientError)
Traceback (most recent call last):
File "/tmp/ansible_dPE6PL/ansible_module_ec2_vpc_net.py", line 203, in get_vpc
classic_link = connection.describe_vpc_classic_link(VpcIds=[vpc_id])['Vpcs'][0].get('ClassicLinkEnabled')
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 317, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 615, in _make_api_call
raise error_class(parsed_response, operation_name)
ClientError: An error occurred (InvalidVpcID.NotFound) when calling the DescribeVpcClassicLink operation: The vpc ID 'vpc-1b2bda60' does not exist

# Fixed code
def ensure_subnet_absent(conn, module):
    subnet = get_matching_subnet(
        conn, module, module.params["vpc_id"], module.params["cidr"]
    )
    if subnet is None:
        return {"changed": False}

    try:
        if not module.check_mode:
            conn.delete_subnet(SubnetId=subnet["id"])
            if module.params["wait"]:
                handle_waiter(
                    conn,
                    module,
                    "subnet_deleted",
                    {"SubnetIds": [subnet["id"]]},
                    time.time(),
                )
        return {"changed": True}
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg="Couldn't delete subnet")
# Buggy code
def ensure_map_public(conn, module, subnet, map_public, check_mode, start_time):
    if check_mode:
        return
    try:
        conn.modify_subnet_attribute(
            SubnetId=subnet["id"], MapPublicIpOnLaunch={"Value": map_public}
        )
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg="Couldn't modify subnet attribute")

    if module.params["wait"]:
        if map_public:
            handle_waiter(
                conn,
                module,
                "subnet_has_map_public",
                {"SubnetIds": [subnet["id"]]},
                start_time,
            )
        else:
            handle_waiter(
                conn,
                module,
                "subnet_no_map_public",
                {"SubnetIds": [subnet["id"]]},
                start_time,
            )


# Traceback (ClientError)
Traceback (most recent call last):
File "/tmp/ansible_dPE6PL/ansible_module_ec2_vpc_net.py", line 203, in get_vpc
classic_link = connection.describe_vpc_classic_link(VpcIds=[vpc_id])['Vpcs'][0].get('ClassicLinkEnabled')
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 317, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 615, in _make_api_call
raise error_class(parsed_response, operation_name)
ClientError: An error occurred (InvalidVpcID.NotFound) when calling the DescribeVpcClassicLink operation: The vpc ID 'vpc-1b2bda60' does not exist

# Fixed code
def ensure_map_public(conn, module, subnet, map_public, check_mode, start_time):
    if check_mode:
        return
    try:
        conn.modify_subnet_attribute(
            SubnetId=subnet["id"], MapPublicIpOnLaunch={"Value": map_public}
        )
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg="Couldn't modify subnet attribute")
# Buggy code
def ensure_assign_ipv6_on_create(
    conn, module, subnet, assign_instances_ipv6, check_mode, start_time
):
    if check_mode:
        return
    try:
        conn.modify_subnet_attribute(
            SubnetId=subnet["id"],
            AssignIpv6AddressOnCreation={"Value": assign_instances_ipv6},
        )
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg="Couldn't modify subnet attribute")

    if module.params["wait"]:
        if assign_instances_ipv6:
            handle_waiter(
                conn,
                module,
                "subnet_has_assign_ipv6",
                {"SubnetIds": [subnet["id"]]},
                start_time,
            )
        else:
            handle_waiter(
                conn,
                module,
                "subnet_no_assign_ipv6",
                {"SubnetIds": [subnet["id"]]},
                start_time,
            )


# Traceback (ClientError)
Traceback (most recent call last):
File "/tmp/ansible_dPE6PL/ansible_module_ec2_vpc_net.py", line 203, in get_vpc
classic_link = connection.describe_vpc_classic_link(VpcIds=[vpc_id])['Vpcs'][0].get('ClassicLinkEnabled')
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 317, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 615, in _make_api_call
raise error_class(parsed_response, operation_name)
ClientError: An error occurred (InvalidVpcID.NotFound) when calling the DescribeVpcClassicLink operation: The vpc ID 'vpc-1b2bda60' does not exist

# Fixed code
def ensure_assign_ipv6_on_create(
    conn, module, subnet, assign_instances_ipv6, check_mode, start_time
):
    if check_mode:
        return
    try:
        conn.modify_subnet_attribute(
            SubnetId=subnet["id"],
            AssignIpv6AddressOnCreation={"Value": assign_instances_ipv6},
        )
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
        module.fail_json_aws(e, msg="Couldn't modify subnet attribute")
# Buggy code
def _hash(self, secret, salt, rounds):
    if rounds is None:
        saltstring = "$%s$%s" % (self.algo_data.crypt_id, salt)
    else:
        saltstring = "$%s$rounds=%d$%s" % (self.algo_data.crypt_id, rounds, salt)
    result = crypt.crypt(secret, saltstring)

    # crypt.crypt returns None if it cannot parse saltstring
    # None as result would be interpreted by the some modules (user module)
    # as no password at all.
    if not result:
        raise AnsibleError(
            "crypt.crypt does not support '%s' algorithm" % self.algorithm
        )

    return result


# Traceback (OSError)
The full traceback is:
Traceback (most recent call last):
File "/home/orion/ansible/lib/ansible/executor/task_executor.py", line 155, in run
res = self._execute()
File "/home/orion/ansible/lib/ansible/executor/task_executor.py", line 599, in _execute
self._task.post_validate(templar=templar)
File "/home/orion/ansible/lib/ansible/playbook/task.py", line 299, in post_validate
super(Task, self).post_validate(templar)
File "/home/orion/ansible/lib/ansible/playbook/base.py", line 431, in post_validate
value = templar.template(getattr(self, name))
File "/home/orion/ansible/lib/ansible/template/__init__.py", line 747, in template
d[k] = self.template(
File "/home/orion/ansible/lib/ansible/template/__init__.py", line 701, in template
result = self.do_template(
File "/home/orion/ansible/lib/ansible/template/__init__.py", line 966, in do_template
res = j2_concat(rf)
File "<template>", line 12, in root
File "/home/orion/ansible/lib/ansible/plugins/filter/core.py", line 270, in get_encrypted_password
return passlib_or_crypt(password, hashtype, salt=salt, salt_size=salt_size, rounds=rounds)
File "/home/orion/ansible/lib/ansible/utils/encrypt.py", line 193, in passlib_or_crypt
return CryptHash(algorithm).hash(secret, salt=salt, salt_size=salt_size, rounds=rounds)
File "/home/orion/ansible/lib/ansible/utils/encrypt.py", line 90, in hash
return self._hash(secret, salt, rounds)
File "/home/orion/ansible/lib/ansible/utils/encrypt.py", line 109, in _hash
result = crypt.crypt(secret, saltstring)
File "/usr/lib64/python3.9/crypt.py", line 82, in crypt
return _crypt.crypt(word, salt)
OSError: [Errno 22] Invalid argument
fatal: [pfsense-test]: FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""
}

# Fixed code
def _hash(self, secret, salt, rounds):
    if rounds is None:
        saltstring = "$%s$%s" % (self.algo_data.crypt_id, salt)
    else:
        saltstring = "$%s$rounds=%d$%s" % (self.algo_data.crypt_id, rounds, salt)

    # crypt.crypt on Python < 3.9 returns None if it cannot parse saltstring
    # On Python >= 3.9, it throws OSError.
    try:
        result = crypt.crypt(secret, saltstring)
        orig_exc = None
    except OSError as e:
        result = None
        orig_exc = e

    # None as result would be interpreted by the some modules (user module)
    # as no password at all.
    if not result:
        raise AnsibleError(
            "crypt.crypt does not support '%s' algorithm" % self.algorithm,
            orig_exc=orig_exc,
        )

    return result
# Buggy code
def _tarfile_extract(tar, member):
    tar_obj = tar.extractfile(member)
    yield tar_obj
    tar_obj.close()


# Traceback (KeyError)
Exception, this is probably a bug: "filename 'tests/unit/modules/placebo_recordings/aws_direct_connect_link_aggregation_group/nonexistent_lag_status' not found"
the full traceback was:
Traceback (most recent call last):
File "/home/bcoca/work/ansible/bin/ansible-galaxy", line 123, in <module>
exit_code = cli.run()
File "/home/bcoca/work/ansible/lib/ansible/cli/galaxy.py", line 490, in run
context.CLIARGS['func']()
File "/home/bcoca/work/ansible/lib/ansible/cli/galaxy.py", line 1057, in execute_install
self._execute_install_collection(collection_requirements, collection_path)
File "/home/bcoca/work/ansible/lib/ansible/cli/galaxy.py", line 1079, in _execute_install_collection
no_deps, force, force_with_deps, allow_pre_release=allow_pre_release)
File "/home/bcoca/work/ansible/lib/ansible/galaxy/collection.py", line 675, in install_collections
collection.install(output_path, b_temp_path)
File "/home/bcoca/work/ansible/lib/ansible/galaxy/collection.py", line 250, in install
self.install_artifact(b_collection_path, b_temp_path)
File "/home/bcoca/work/ansible/lib/ansible/galaxy/collection.py", line 275, in install_artifact
_extract_tar_dir(collection_tar, file_name, b_collection_path)
File "/home/bcoca/work/ansible/lib/ansible/galaxy/collection.py", line 1387, in _extract_tar_dir
tar_member = tar.getmember(to_native(dirname, errors='surrogate_or_strict'))
File "/usr/lib/python3.7/tarfile.py", line 1752, in getmember
raise KeyError("filename %r not found" % name)
KeyError: "filename 'tests/unit/modules/placebo_recordings/aws_direct_connect_link_aggregation_group/nonexistent_lag_status' not found"

# Fixed code
def _tarfile_extract(tar, member):
    tar_obj = tar.extractfile(member)
    yield member, tar_obj
    tar_obj.close()
# Buggy code
def reset_stat(tarinfo):
    existing_is_exec = tarinfo.mode & stat.S_IXUSR
    tarinfo.mode = 0o0755 if existing_is_exec or tarinfo.isdir() else 0o0644
    tarinfo.uid = tarinfo.gid = 0
    tarinfo.uname = tarinfo.gname = ""
    return tarinfo


# Traceback (KeyError)
Exception, this is probably a bug: "filename 'tests/unit/modules/placebo_recordings/aws_direct_connect_link_aggregation_group/nonexistent_lag_status' not found"
the full traceback was:
Traceback (most recent call last):
File "/home/bcoca/work/ansible/bin/ansible-galaxy", line 123, in <module>
exit_code = cli.run()
File "/home/bcoca/work/ansible/lib/ansible/cli/galaxy.py", line 490, in run
context.CLIARGS['func']()
File "/home/bcoca/work/ansible/lib/ansible/cli/galaxy.py", line 1057, in execute_install
self._execute_install_collection(collection_requirements, collection_path)
File "/home/bcoca/work/ansible/lib/ansible/cli/galaxy.py", line 1079, in _execute_install_collection
no_deps, force, force_with_deps, allow_pre_release=allow_pre_release)
File "/home/bcoca/work/ansible/lib/ansible/galaxy/collection.py", line 675, in install_collections
collection.install(output_path, b_temp_path)
File "/home/bcoca/work/ansible/lib/ansible/galaxy/collection.py", line 250, in install
self.install_artifact(b_collection_path, b_temp_path)
File "/home/bcoca/work/ansible/lib/ansible/galaxy/collection.py", line 275, in install_artifact
_extract_tar_dir(collection_tar, file_name, b_collection_path)
File "/home/bcoca/work/ansible/lib/ansible/galaxy/collection.py", line 1387, in _extract_tar_dir
tar_member = tar.getmember(to_native(dirname, errors='surrogate_or_strict'))
File "/usr/lib/python3.7/tarfile.py", line 1752, in getmember
raise KeyError("filename %r not found" % name)
KeyError: "filename 'tests/unit/modules/placebo_recordings/aws_direct_connect_link_aggregation_group/nonexistent_lag_status' not found"

# Fixed code
def reset_stat(tarinfo):
    if tarinfo.type != tarfile.SYMTYPE:
        existing_is_exec = tarinfo.mode & stat.S_IXUSR
        tarinfo.mode = 0o0755 if existing_is_exec or tarinfo.isdir() else 0o0644
    tarinfo.uid = tarinfo.gid = 0
    tarinfo.uname = tarinfo.gname = ""

    return tarinfo
# Buggy code
def jdump(text):
    display.display(json.dumps(text, sort_keys=True, indent=4))


# Traceback (TypeError)
ansible-doc 2.9.7.post0
config file = None
configured module search path = ['/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /ansible/lib/ansible
executable location = /ansible/bin/ansible-doc
python version = 3.8.2 (default, Apr  8 2020, 14:31:25) [GCC 9.3.0]
No config file found; using defaults
/ansible/lib/ansible/cli/doc.py:219: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
doc_data['return'] = yaml.load(doc_data['return'])
ERROR! Unexpected Exception, this is probably a bug: Object of type datetime is not JSON serializable
the full traceback was:

Traceback (most recent call last):
File "/ansible/bin/ansible-doc", line 123, in <module>
exit_code = cli.run()
File "/ansible/lib/ansible/cli/doc.py", line 223, in run
jdump(plugin_docs)
File "/ansible/lib/ansible/cli/doc.py", line 36, in jdump
display.display(json.dumps(text, sort_keys=True, indent=4))
File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
return cls(
File "/usr/lib/python3.8/json/encoder.py", line 201, in encode
chunks = list(chunks)
File "/usr/lib/python3.8/json/encoder.py", line 431, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
[Previous line repeated 1 more time]
File "/usr/lib/python3.8/json/encoder.py", line 325, in _iterencode_list
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 438, in _iterencode
o = _default(o)
File "/usr/lib/python3.8/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type datetime is not JSON serializable

# Fixed code
def jdump(text):
    try:
        display.display(
            json.dumps(text, cls=AnsibleJSONEncoder, sort_keys=True, indent=4)
        )
    except TypeError as e:
        raise AnsibleError(
            "We could not convert all the documentation into JSON as there was a conversion issue: %s"
            % to_native(e)
        )
# Buggy code
def print_paths(finder):
    """Returns a string suitable for printing of the search path"""

    # Uses a list to get the order right
    ret = []
    for i in finder._get_paths(subdirs=False):
        if i not in ret:
            ret.append(i)
    return os.pathsep.join(ret)


# Traceback (TypeError)
ansible-doc 2.9.7.post0
config file = None
configured module search path = ['/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /ansible/lib/ansible
executable location = /ansible/bin/ansible-doc
python version = 3.8.2 (default, Apr  8 2020, 14:31:25) [GCC 9.3.0]
No config file found; using defaults
/ansible/lib/ansible/cli/doc.py:219: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
doc_data['return'] = yaml.load(doc_data['return'])
ERROR! Unexpected Exception, this is probably a bug: Object of type datetime is not JSON serializable
the full traceback was:

Traceback (most recent call last):
File "/ansible/bin/ansible-doc", line 123, in <module>
exit_code = cli.run()
File "/ansible/lib/ansible/cli/doc.py", line 223, in run
jdump(plugin_docs)
File "/ansible/lib/ansible/cli/doc.py", line 36, in jdump
display.display(json.dumps(text, sort_keys=True, indent=4))
File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
return cls(
File "/usr/lib/python3.8/json/encoder.py", line 201, in encode
chunks = list(chunks)
File "/usr/lib/python3.8/json/encoder.py", line 431, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
[Previous line repeated 1 more time]
File "/usr/lib/python3.8/json/encoder.py", line 325, in _iterencode_list
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 438, in _iterencode
o = _default(o)
File "/usr/lib/python3.8/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type datetime is not JSON serializable

# Fixed code
def print_paths(finder):
    """Returns a string suitable for printing of the search path"""

    # Uses a list to get the order right
    ret = []
    for i in finder._get_paths(subdirs=False):
        i = to_text(i, errors="surrogate_or_strict")
        if i not in ret:
            ret.append(i)
    return os.pathsep.join(ret)
# Buggy code
def is_collection_path(path):
    """
    Verify that a path meets min requirements to be a collection
    :param path: byte-string path to evaluate for collection containment
    :return: boolean signifying 'collectionness'
    """

    is_coll = False
    if os.path.isdir(path):
        for flag in FLAG_FILES:
            if os.path.exists(os.path.join(path, flag)):
                is_coll = True
                break

    return is_coll


# Traceback (TypeError)
ansible-doc 2.9.7.post0
config file = None
configured module search path = ['/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /ansible/lib/ansible
executable location = /ansible/bin/ansible-doc
python version = 3.8.2 (default, Apr  8 2020, 14:31:25) [GCC 9.3.0]
No config file found; using defaults
/ansible/lib/ansible/cli/doc.py:219: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
doc_data['return'] = yaml.load(doc_data['return'])
ERROR! Unexpected Exception, this is probably a bug: Object of type datetime is not JSON serializable
the full traceback was:

Traceback (most recent call last):
File "/ansible/bin/ansible-doc", line 123, in <module>
exit_code = cli.run()
File "/ansible/lib/ansible/cli/doc.py", line 223, in run
jdump(plugin_docs)
File "/ansible/lib/ansible/cli/doc.py", line 36, in jdump
display.display(json.dumps(text, sort_keys=True, indent=4))
File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
return cls(
File "/usr/lib/python3.8/json/encoder.py", line 201, in encode
chunks = list(chunks)
File "/usr/lib/python3.8/json/encoder.py", line 431, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
[Previous line repeated 1 more time]
File "/usr/lib/python3.8/json/encoder.py", line 325, in _iterencode_list
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 438, in _iterencode
o = _default(o)
File "/usr/lib/python3.8/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type datetime is not JSON serializable

# Fixed code
def is_collection_path(path):
    """
    Verify that a path meets min requirements to be a collection
    :param path: byte-string path to evaluate for collection containment
    :return: boolean signifying 'collectionness'
    """

    is_coll = False
    b_path = to_bytes(path)
    if os.path.isdir(b_path):
        for b_flag in B_FLAG_FILES:
            if os.path.exists(os.path.join(b_path, b_flag)):
                is_coll = True
                break

    return is_coll
# Buggy code
def checkID(module, params):
    data = urlencode(params)
    full_uri = API_BASE + API_ACTIONS["status"] + data
    req, info = fetch_url(module, full_uri)
    result = req.read()
    jsonresult = json.loads(result)
    req.close()
    return jsonresult


# Traceback (nTypeError)
FAILED - RETRYING: Monitor - paused (291 retries left).Result was: {
"attempts": 10,
"changed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 114, in <module>\n  File \"<stdin>\", line 106, in _ansiballz_main\n  File \"<stdin>\", line 49, in invoke_module\n  File \"/usr/lib/python3.5/imp.py\", line 234, in load_module\n    return load_sourc
e(name, filename, file)\n  File \"/usr/lib/python3.5/imp.py\", line 170, in load_source\n    module = _exec(spec, sys.modules[name])\n  File \"<frozen importlib._bootstrap>\", line 626, in _exec\n  File \"<frozen importlib._bootstrap_external>\", line 665, in exec_module\n  File \"<
frozen importlib._bootstrap>\", line 222, in _call_with_frames_removed\n  File \"/tmp/ansible_uptimerobot_payload_gp2xmpdx/__main__.py\", line 151, in <module>\n  File \"/tmp/ansible_uptimerobot_payload_gp2xmpdx/__main__.py\", line 131, in main\n  File \"/tmp/ansible_uptimerobot_pay
load_gp2xmpdx/__main__.py\", line 83, in checkID\n  File \"/usr/lib/python3.5/json/__init__.py\", line 312, in loads\n    s.__class__.__name__))\nTypeError: the JSON object must be str, not 'bytes'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1,
"retries": 301
}

# Fixed code
def checkID(module, params):
    data = urlencode(params)
    full_uri = API_BASE + API_ACTIONS["status"] + data
    req, info = fetch_url(module, full_uri)
    result = to_text(req.read())
    jsonresult = json.loads(result)
    req.close()
    return jsonresult
# Buggy code
def startMonitor(module, params):
    params["monitorStatus"] = 1
    data = urlencode(params)
    full_uri = API_BASE + API_ACTIONS["editMonitor"] + data
    req, info = fetch_url(module, full_uri)
    result = req.read()
    jsonresult = json.loads(result)
    req.close()
    return jsonresult["stat"]


# Traceback (nTypeError)
FAILED - RETRYING: Monitor - paused (291 retries left).Result was: {
"attempts": 10,
"changed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 114, in <module>\n  File \"<stdin>\", line 106, in _ansiballz_main\n  File \"<stdin>\", line 49, in invoke_module\n  File \"/usr/lib/python3.5/imp.py\", line 234, in load_module\n    return load_sourc
e(name, filename, file)\n  File \"/usr/lib/python3.5/imp.py\", line 170, in load_source\n    module = _exec(spec, sys.modules[name])\n  File \"<frozen importlib._bootstrap>\", line 626, in _exec\n  File \"<frozen importlib._bootstrap_external>\", line 665, in exec_module\n  File \"<
frozen importlib._bootstrap>\", line 222, in _call_with_frames_removed\n  File \"/tmp/ansible_uptimerobot_payload_gp2xmpdx/__main__.py\", line 151, in <module>\n  File \"/tmp/ansible_uptimerobot_payload_gp2xmpdx/__main__.py\", line 131, in main\n  File \"/tmp/ansible_uptimerobot_pay
load_gp2xmpdx/__main__.py\", line 83, in checkID\n  File \"/usr/lib/python3.5/json/__init__.py\", line 312, in loads\n    s.__class__.__name__))\nTypeError: the JSON object must be str, not 'bytes'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1,
"retries": 301
}

# Fixed code
def startMonitor(module, params):
    params["monitorStatus"] = 1
    data = urlencode(params)
    full_uri = API_BASE + API_ACTIONS["editMonitor"] + data
    req, info = fetch_url(module, full_uri)
    result = to_text(req.read())
    jsonresult = json.loads(result)
    req.close()
    return jsonresult["stat"]
# Buggy code
def pauseMonitor(module, params):
    params["monitorStatus"] = 0
    data = urlencode(params)
    full_uri = API_BASE + API_ACTIONS["editMonitor"] + data
    req, info = fetch_url(module, full_uri)
    result = req.read()
    jsonresult = json.loads(result)
    req.close()
    return jsonresult["stat"]


# Traceback (nTypeError)
FAILED - RETRYING: Monitor - paused (291 retries left).Result was: {
"attempts": 10,
"changed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 114, in <module>\n  File \"<stdin>\", line 106, in _ansiballz_main\n  File \"<stdin>\", line 49, in invoke_module\n  File \"/usr/lib/python3.5/imp.py\", line 234, in load_module\n    return load_sourc
e(name, filename, file)\n  File \"/usr/lib/python3.5/imp.py\", line 170, in load_source\n    module = _exec(spec, sys.modules[name])\n  File \"<frozen importlib._bootstrap>\", line 626, in _exec\n  File \"<frozen importlib._bootstrap_external>\", line 665, in exec_module\n  File \"<
frozen importlib._bootstrap>\", line 222, in _call_with_frames_removed\n  File \"/tmp/ansible_uptimerobot_payload_gp2xmpdx/__main__.py\", line 151, in <module>\n  File \"/tmp/ansible_uptimerobot_payload_gp2xmpdx/__main__.py\", line 131, in main\n  File \"/tmp/ansible_uptimerobot_pay
load_gp2xmpdx/__main__.py\", line 83, in checkID\n  File \"/usr/lib/python3.5/json/__init__.py\", line 312, in loads\n    s.__class__.__name__))\nTypeError: the JSON object must be str, not 'bytes'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1,
"retries": 301
}

# Fixed code
def pauseMonitor(module, params):
    params["monitorStatus"] = 0
    data = urlencode(params)
    full_uri = API_BASE + API_ACTIONS["editMonitor"] + data
    req, info = fetch_url(module, full_uri)
    result = to_text(req.read())
    jsonresult = json.loads(result)
    req.close()
    return jsonresult["stat"]
# Buggy code
def _rabbit_version(self):
    status = self._exec(["status"], True, False, False)

    version_match = re.search('{rabbit,".*","(?P<version>.*)"}', status)
    if version_match:
        return Version(version_match.group("version"))

    return None


# Traceback (ValueError)
ansible-playbook -i rabbitmq configure-rabbitmq-debug.yml -b --private-key master.key -u master -vvv
[...]
The full traceback is:
Traceback (most recent call last):
File "/home/clouddevmaster/.ansible/tmp/ansible-tmp-1579794428.83-164555296831546/AnsiballZ_rabbitmq_policy.py", line 102, in <module>
_ansiballz_main()
File "/home/clouddevmaster/.ansible/tmp/ansible-tmp-1579794428.83-164555296831546/AnsiballZ_rabbitmq_policy.py", line 94, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/clouddevmaster/.ansible/tmp/ansible-tmp-1579794428.83-164555296831546/AnsiballZ_rabbitmq_policy.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible.modules.messaging.rabbitmq.rabbitmq_policy', init_globals=None, run_name='__main__', alter_sys=True)
File "/usr/lib/python2.7/runpy.py", line 188, in run_module
fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/tmp/ansible_rabbitmq_policy_payload_OEqAxO/ansible_rabbitmq_policy_payload.zip/ansible/modules/messaging/rabbitmq/rabbitmq_policy.py", line 241, in <module>
File "/tmp/ansible_rabbitmq_policy_payload_OEqAxO/ansible_rabbitmq_policy_payload.zip/ansible/modules/messaging/rabbitmq/rabbitmq_policy.py", line 230, in main
File "/tmp/ansible_rabbitmq_policy_payload_OEqAxO/ansible_rabbitmq_policy_payload.zip/ansible/modules/messaging/rabbitmq/rabbitmq_policy.py", line 154, in has_modifications
File "/tmp/ansible_rabbitmq_policy_payload_OEqAxO/ansible_rabbitmq_policy_payload.zip/ansible/modules/messaging/rabbitmq/rabbitmq_policy.py", line 154, in <genexpr>
File "/tmp/ansible_rabbitmq_policy_payload_OEqAxO/ansible_rabbitmq_policy_payload.zip/ansible/modules/messaging/rabbitmq/rabbitmq_policy.py", line 191, in _policy_check
File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

# Fixed code
def _rabbit_version(self):
    status = self._exec(["status"], True, False, False)

    # 3.7.x erlang style output
    version_match = re.search('{rabbit,".*","(?P<version>.*)"}', status)
    if version_match:
        return Version(version_match.group("version"))

    # 3.8.x style ouput
    version_match = re.search("RabbitMQ version: (?P<version>.*)", status)
    if version_match:
        return Version(version_match.group("version"))

    return None
# Buggy code
def __init__(self, rule_type, rule_control, rule_path, rule_args=None):
    self._control = None
    self._args = None
    self.rule_type = rule_type
    self.rule_control = rule_control

    self.rule_path = rule_path
    self.rule_args = rule_args


# Traceback (AttributeError)
TASK [delete last line] ************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'prev'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1579109163.9766297-72407548392226/AnsiballZ_pamd.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1579109163.9766297-72407548392226/AnsiballZ_pamd.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1579109163.9766297-72407548392226/AnsiballZ_pamd.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.system.pamd', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.5/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.5/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib/python3.5/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_pamd_payload_8ay1zjt8/ansible_pamd_payload.zip/ansible/modules/system/pamd.py\", line 879, in <module>\n  File \"/tmp/ansible_pamd_payload_8ay1zjt8/ansible_pamd_payload.zip/ansible/modules/system/pamd.py\", line 845, in main\n  File \"/tmp/ansible_pamd_payload_8ay1zjt8/ansible_pamd_payload.zip/ansible/modules/system/pamd.py\", line 483, in remove\nAttributeError: 'NoneType' object has no attribute 'prev'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

# Fixed code
def __init__(self, rule_type, rule_control, rule_path, rule_args=None):
    self.prev = None
    self.next = None
    self._control = None
    self._args = None
    self.rule_type = rule_type
    self.rule_control = rule_control

    self.rule_path = rule_path
    self.rule_args = rule_args
# Buggy code
def remove(self, rule_type, rule_control, rule_path):
    current_line = self._head
    changed = 0

    while current_line is not None:
        if current_line.matches(rule_type, rule_control, rule_path):
            if current_line.prev is not None:
                current_line.prev.next = current_line.next
                current_line.next.prev = current_line.prev
            else:
                self._head = current_line.next
                current_line.next.prev = None
            changed += 1

        current_line = current_line.next
    return changed


# Traceback (AttributeError)
TASK [delete last line] ************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'prev'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1579109163.9766297-72407548392226/AnsiballZ_pamd.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1579109163.9766297-72407548392226/AnsiballZ_pamd.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1579109163.9766297-72407548392226/AnsiballZ_pamd.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.system.pamd', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.5/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.5/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib/python3.5/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_pamd_payload_8ay1zjt8/ansible_pamd_payload.zip/ansible/modules/system/pamd.py\", line 879, in <module>\n  File \"/tmp/ansible_pamd_payload_8ay1zjt8/ansible_pamd_payload.zip/ansible/modules/system/pamd.py\", line 845, in main\n  File \"/tmp/ansible_pamd_payload_8ay1zjt8/ansible_pamd_payload.zip/ansible/modules/system/pamd.py\", line 483, in remove\nAttributeError: 'NoneType' object has no attribute 'prev'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

# Fixed code
def remove(self, rule_type, rule_control, rule_path):
    current_line = self._head
    changed = 0

    while current_line is not None:
        if current_line.matches(rule_type, rule_control, rule_path):
            if current_line.prev is not None:
                current_line.prev.next = current_line.next
                if current_line.next is not None:
                    current_line.next.prev = current_line.prev
            else:
                self._head = current_line.next
                current_line.next.prev = None
            changed += 1

        current_line = current_line.next
    return changed
# Buggy code
def __init__(self, module, zbx):
    self._module = module
    self._zapi = zbx


# Traceback (KeyError)
TASK [ansible-role-zabbix_web : add zabbix hosts] ******************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'inventory_mode'
failed: [zabbix_web-centos-latest] (item=Example server 1) => {"ansible_loop_var": "item", "changed": false, "item": {"description": "Example server 1 description", "groups": ["Linux servers"], "interface_dns": "server1.example.com", "interface_ip": "192.168.127.127", "link_templates": ["Template OS Linux by Zabbix agent"], "name": "Example server 1", "visible_name": "Example server 1 name"}, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1574832740.9065554-150815383322675/AnsiballZ_zabbix_host.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1574832740.9065554-150815383322675/AnsiballZ_zabbix_host.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1574832740.9065554-150815383322675/AnsiballZ_zabbix_host.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.monitoring.zabbix.zabbix_host', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_zabbix_host_payload_xl5geyrr/ansible_zabbix_host_payload.zip/ansible/modules/monitoring/zabbix/zabbix_host.py\", line 902, in <module>\n  File \"/tmp/ansible_zabbix_host_payload_xl5geyrr/ansible_zabbix_host_payload.zip/ansible/modules/monitoring/zabbix/zabbix_host.py\", line 862, in main\n  File \"/tmp/ansible_zabbix_host_payload_xl5geyrr/ansible_zabbix_host_payload.zip/ansible/modules/monitoring/zabbix/zabbix_host.py\", line 546, in check_all_properties\nKeyError: 'inventory_mode'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

# Fixed code
def __init__(self, module, zbx):
    self._module = module
    self._zapi = zbx
    self._zbx_api_version = zbx.api_version()[:5]