gurudesh/pytracebugs huggingface dataset:
# Buggy code
def __init__(self, name=None):
    self.depth = 0
    self.name = name
    self.hosts = []
    self._hosts = set()
    self.vars = {}
    self.child_groups = []
    self.parent_groups = []
    self._hosts_cache = None
    self.priority = 1


# Traceback (AttributeError)
$ ansible-playbook playbook.yml -i inventory

PLAY [host1] *************************************************************************************************************************************************

TASK [apply role whatever over list of items] ****************************************************************************************************************
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib64/python2.7/threading.py", line 804, in __bootstrap_inner
self.run()
File "/usr/lib64/python2.7/threading.py", line 757, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/will/src/ansible/lib/ansible/plugins/strategy/__init__.py", line 84, in results_thread_main
result = strategy._final_q.get()
File "/usr/lib64/python2.7/multiprocessing/queues.py", line 117, in get
res = self._recv()
File "/home/will/src/ansible/lib/ansible/inventory/host.py", line 37, in __setstate__
return self.deserialize(data)
File "/home/will/src/ansible/lib/ansible/inventory/host.py", line 82, in deserialize
g.deserialize(group_data)
File "/home/will/src/ansible/lib/ansible/inventory/group.py", line 77, in deserialize
self._hosts = set(self.hosts)
File "/home/will/src/ansible/lib/ansible/inventory/host.py", line 48, in __hash__
return hash(self.name)
AttributeError: 'Host' object has no attribute 'name'

# Fixed code
def __init__(self, name=None):
    self.depth = 0
    self.name = name
    self.hosts = []
    self._hosts = None
    self.vars = {}
    self.child_groups = []
    self.parent_groups = []
    self._hosts_cache = None
    self.priority = 1
# Buggy code
def deserialize(self, data):
    self.__init__()
    self.name = data.get("name")
    self.vars = data.get("vars", dict())
    self.depth = data.get("depth", 0)
    self.hosts = data.get("hosts", {})

    self._hosts = set(self.hosts)

    parent_groups = data.get("parent_groups", [])
    for parent_data in parent_groups:
        g = Group()
        g.deserialize(parent_data)
        self.parent_groups.append(g)


# Traceback (AttributeError)
$ ansible-playbook playbook.yml -i inventory

PLAY [host1] *************************************************************************************************************************************************

TASK [apply role whatever over list of items] ****************************************************************************************************************
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib64/python2.7/threading.py", line 804, in __bootstrap_inner
self.run()
File "/usr/lib64/python2.7/threading.py", line 757, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/will/src/ansible/lib/ansible/plugins/strategy/__init__.py", line 84, in results_thread_main
result = strategy._final_q.get()
File "/usr/lib64/python2.7/multiprocessing/queues.py", line 117, in get
res = self._recv()
File "/home/will/src/ansible/lib/ansible/inventory/host.py", line 37, in __setstate__
return self.deserialize(data)
File "/home/will/src/ansible/lib/ansible/inventory/host.py", line 82, in deserialize
g.deserialize(group_data)
File "/home/will/src/ansible/lib/ansible/inventory/group.py", line 77, in deserialize
self._hosts = set(self.hosts)
File "/home/will/src/ansible/lib/ansible/inventory/host.py", line 48, in __hash__
return hash(self.name)
AttributeError: 'Host' object has no attribute 'name'

# Fixed code
def deserialize(self, data):
    self.__init__()
    self.name = data.get("name")
    self.vars = data.get("vars", dict())
    self.depth = data.get("depth", 0)
    self.hosts = data.get("hosts", [])
    self._hosts = None

    parent_groups = data.get("parent_groups", [])
    for parent_data in parent_groups:
        g = Group()
        g.deserialize(parent_data)
        self.parent_groups.append(g)
# Buggy code
def add_host(self, host):
    if host.name not in self._hosts:
        self.hosts.append(host)
        self._hosts.add(host.name)
        host.add_group(self)
        self.clear_hosts_cache()


# Traceback (AttributeError)
$ ansible-playbook playbook.yml -i inventory

PLAY [host1] *************************************************************************************************************************************************

TASK [apply role whatever over list of items] ****************************************************************************************************************
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib64/python2.7/threading.py", line 804, in __bootstrap_inner
self.run()
File "/usr/lib64/python2.7/threading.py", line 757, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/will/src/ansible/lib/ansible/plugins/strategy/__init__.py", line 84, in results_thread_main
result = strategy._final_q.get()
File "/usr/lib64/python2.7/multiprocessing/queues.py", line 117, in get
res = self._recv()
File "/home/will/src/ansible/lib/ansible/inventory/host.py", line 37, in __setstate__
return self.deserialize(data)
File "/home/will/src/ansible/lib/ansible/inventory/host.py", line 82, in deserialize
g.deserialize(group_data)
File "/home/will/src/ansible/lib/ansible/inventory/group.py", line 77, in deserialize
self._hosts = set(self.hosts)
File "/home/will/src/ansible/lib/ansible/inventory/host.py", line 48, in __hash__
return hash(self.name)
AttributeError: 'Host' object has no attribute 'name'

# Fixed code
def add_host(self, host):
    if host.name not in self.host_names:
        self.hosts.append(host)
        self._hosts.add(host.name)
        host.add_group(self)
        self.clear_hosts_cache()
# Buggy code
def remove_host(self, host):
    if host.name in self._hosts:
        self.hosts.remove(host)
        self._hosts.remove(host.name)
        host.remove_group(self)
        self.clear_hosts_cache()


# Traceback (AttributeError)
$ ansible-playbook playbook.yml -i inventory

PLAY [host1] *************************************************************************************************************************************************

TASK [apply role whatever over list of items] ****************************************************************************************************************
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib64/python2.7/threading.py", line 804, in __bootstrap_inner
self.run()
File "/usr/lib64/python2.7/threading.py", line 757, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/will/src/ansible/lib/ansible/plugins/strategy/__init__.py", line 84, in results_thread_main
result = strategy._final_q.get()
File "/usr/lib64/python2.7/multiprocessing/queues.py", line 117, in get
res = self._recv()
File "/home/will/src/ansible/lib/ansible/inventory/host.py", line 37, in __setstate__
return self.deserialize(data)
File "/home/will/src/ansible/lib/ansible/inventory/host.py", line 82, in deserialize
g.deserialize(group_data)
File "/home/will/src/ansible/lib/ansible/inventory/group.py", line 77, in deserialize
self._hosts = set(self.hosts)
File "/home/will/src/ansible/lib/ansible/inventory/host.py", line 48, in __hash__
return hash(self.name)
AttributeError: 'Host' object has no attribute 'name'

# Fixed code
def remove_host(self, host):
    if host.name in self.host_names:
        self.hosts.remove(host)
        self._hosts.remove(host.name)
        host.remove_group(self)
        self.clear_hosts_cache()
# Buggy code
def __init__(
    self,
    module,
    name,
    client,
    schedule_expression=None,
    event_pattern=None,
    description=None,
    role_arn=None,
):
    self.name = name
    self.client = client
    self.changed = False
    self.schedule_expression = schedule_expression
    self.event_pattern = event_pattern
    self.description = description
    self.role_arn = role_arn


# Traceback (NameError)
The full traceback is:
Traceback (most recent call last):
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 427, in <module>
main()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 415, in main
cwe_rule_manager.ensure_present()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 267, in ensure_present
rule_description = self.rule.describe()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 145, in describe
except botocore.exceptions.ClientError as e:
NameError: global name 'botocore' is not defined

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 427, in <module>\n    main()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 415, in main\n    cwe_rule_manager.ensure_present()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 267, in ensure_present\n    rule_description = self.rule.describe()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 145, in describe\n    except botocore.exceptions.ClientError as e:\nNameError: global name 'botocore' is not defined\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def __init__(
    self,
    module,
    name,
    client,
    schedule_expression=None,
    event_pattern=None,
    description=None,
    role_arn=None,
):
    self.name = name
    self.client = client
    self.changed = False
    self.schedule_expression = schedule_expression
    self.event_pattern = event_pattern
    self.description = description
    self.role_arn = role_arn
    self.module = module
# Buggy code
def describe(self):
    """Returns the existing details of the rule in AWS"""
    try:
        rule_info = self.client.describe_rule(Name=self.name)
    except botocore.exceptions.ClientError as e:
        error_code = e.response.get("Error", {}).get("Code")
        if error_code == "ResourceNotFoundException":
            return {}
        raise
    return self._snakify(rule_info)


# Traceback (NameError)
The full traceback is:
Traceback (most recent call last):
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 427, in <module>
main()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 415, in main
cwe_rule_manager.ensure_present()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 267, in ensure_present
rule_description = self.rule.describe()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 145, in describe
except botocore.exceptions.ClientError as e:
NameError: global name 'botocore' is not defined

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 427, in <module>\n    main()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 415, in main\n    cwe_rule_manager.ensure_present()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 267, in ensure_present\n    rule_description = self.rule.describe()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 145, in describe\n    except botocore.exceptions.ClientError as e:\nNameError: global name 'botocore' is not defined\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def describe(self):
    """Returns the existing details of the rule in AWS"""
    try:
        rule_info = self.client.describe_rule(Name=self.name)
    except botocore.exceptions.ClientError as e:
        error_code = e.response.get("Error", {}).get("Code")
        if error_code == "ResourceNotFoundException":
            return {}
        self.module.fail_json_aws(e, msg="Could not describe rule %s" % self.name)
    except botocore.exceptions.BotoCoreError as e:
        self.module.fail_json_aws(e, msg="Could not describe rule %s" % self.name)
    return self._snakify(rule_info)
# Buggy code
def put(self, enabled=True):
    """Creates or updates the rule in AWS"""
    request = {
        "Name": self.name,
        "State": "ENABLED" if enabled else "DISABLED",
    }
    if self.schedule_expression:
        request["ScheduleExpression"] = self.schedule_expression
    if self.event_pattern:
        request["EventPattern"] = self.event_pattern
    if self.description:
        request["Description"] = self.description
    if self.role_arn:
        request["RoleArn"] = self.role_arn
    response = self.client.put_rule(**request)
    self.changed = True
    return response


# Traceback (NameError)
The full traceback is:
Traceback (most recent call last):
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 427, in <module>
main()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 415, in main
cwe_rule_manager.ensure_present()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 267, in ensure_present
rule_description = self.rule.describe()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 145, in describe
except botocore.exceptions.ClientError as e:
NameError: global name 'botocore' is not defined

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 427, in <module>\n    main()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 415, in main\n    cwe_rule_manager.ensure_present()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 267, in ensure_present\n    rule_description = self.rule.describe()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 145, in describe\n    except botocore.exceptions.ClientError as e:\nNameError: global name 'botocore' is not defined\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def put(self, enabled=True):
    """Creates or updates the rule in AWS"""
    request = {
        "Name": self.name,
        "State": "ENABLED" if enabled else "DISABLED",
    }
    if self.schedule_expression:
        request["ScheduleExpression"] = self.schedule_expression
    if self.event_pattern:
        request["EventPattern"] = self.event_pattern
    if self.description:
        request["Description"] = self.description
    if self.role_arn:
        request["RoleArn"] = self.role_arn
    try:
        response = self.client.put_rule(**request)
    except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
        self.module.fail_json_aws(e, msg="Could not create/update rule %s" % self.name)
    self.changed = True
    return response
# Buggy code
def delete(self):
    """Deletes the rule in AWS"""
    self.remove_all_targets()
    response = self.client.delete_rule(Name=self.name)
    self.changed = True
    return response


# Traceback (NameError)
The full traceback is:
Traceback (most recent call last):
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 427, in <module>
main()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 415, in main
cwe_rule_manager.ensure_present()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 267, in ensure_present
rule_description = self.rule.describe()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 145, in describe
except botocore.exceptions.ClientError as e:
NameError: global name 'botocore' is not defined

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 427, in <module>\n    main()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 415, in main\n    cwe_rule_manager.ensure_present()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 267, in ensure_present\n    rule_description = self.rule.describe()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 145, in describe\n    except botocore.exceptions.ClientError as e:\nNameError: global name 'botocore' is not defined\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def delete(self):
    """Deletes the rule in AWS"""
    self.remove_all_targets()

    try:
        response = self.client.delete_rule(Name=self.name)
    except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
        self.module.fail_json_aws(e, msg="Could not delete rule %s" % self.name)
    self.changed = True
    return response
# Buggy code
def enable(self):
    """Enables the rule in AWS"""
    response = self.client.enable_rule(Name=self.name)
    self.changed = True
    return response


# Traceback (NameError)
The full traceback is:
Traceback (most recent call last):
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 427, in <module>
main()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 415, in main
cwe_rule_manager.ensure_present()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 267, in ensure_present
rule_description = self.rule.describe()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 145, in describe
except botocore.exceptions.ClientError as e:
NameError: global name 'botocore' is not defined

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 427, in <module>\n    main()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 415, in main\n    cwe_rule_manager.ensure_present()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 267, in ensure_present\n    rule_description = self.rule.describe()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 145, in describe\n    except botocore.exceptions.ClientError as e:\nNameError: global name 'botocore' is not defined\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def enable(self):
    """Enables the rule in AWS"""
    try:
        response = self.client.enable_rule(Name=self.name)
    except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
        self.module.fail_json_aws(e, msg="Could not enable rule %s" % self.name)
    self.changed = True
    return response
# Buggy code
def disable(self):
    """Disables the rule in AWS"""
    response = self.client.disable_rule(Name=self.name)
    self.changed = True
    return response


# Traceback (NameError)
The full traceback is:
Traceback (most recent call last):
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 427, in <module>
main()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 415, in main
cwe_rule_manager.ensure_present()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 267, in ensure_present
rule_description = self.rule.describe()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 145, in describe
except botocore.exceptions.ClientError as e:
NameError: global name 'botocore' is not defined

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 427, in <module>\n    main()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 415, in main\n    cwe_rule_manager.ensure_present()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 267, in ensure_present\n    rule_description = self.rule.describe()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 145, in describe\n    except botocore.exceptions.ClientError as e:\nNameError: global name 'botocore' is not defined\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def disable(self):
    """Disables the rule in AWS"""
    try:
        response = self.client.disable_rule(Name=self.name)
    except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
        self.module.fail_json_aws(e, msg="Could not disable rule %s" % self.name)
    self.changed = True
    return response
# Buggy code
def list_targets(self):
    """Lists the existing targets for the rule in AWS"""
    try:
        targets = self.client.list_targets_by_rule(Rule=self.name)
    except botocore.exceptions.ClientError as e:
        error_code = e.response.get("Error", {}).get("Code")
        if error_code == "ResourceNotFoundException":
            return []
        raise
    return self._snakify(targets)["targets"]


# Traceback (NameError)
The full traceback is:
Traceback (most recent call last):
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 427, in <module>
main()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 415, in main
cwe_rule_manager.ensure_present()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 267, in ensure_present
rule_description = self.rule.describe()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 145, in describe
except botocore.exceptions.ClientError as e:
NameError: global name 'botocore' is not defined

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 427, in <module>\n    main()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 415, in main\n    cwe_rule_manager.ensure_present()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 267, in ensure_present\n    rule_description = self.rule.describe()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 145, in describe\n    except botocore.exceptions.ClientError as e:\nNameError: global name 'botocore' is not defined\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def list_targets(self):
    """Lists the existing targets for the rule in AWS"""
    try:
        targets = self.client.list_targets_by_rule(Rule=self.name)
    except botocore.exceptions.ClientError as e:
        error_code = e.response.get("Error", {}).get("Code")
        if error_code == "ResourceNotFoundException":
            return []
        self.module.fail_json_aws(
            e, msg="Could not find target for rule %s" % self.name
        )
    except botocore.exceptions.BotoCoreError as e:
        self.module.fail_json_aws(
            e, msg="Could not find target for rule %s" % self.name
        )
    return self._snakify(targets)["targets"]
# Buggy code
def put_targets(self, targets):
    """Creates or updates the provided targets on the rule in AWS"""
    if not targets:
        return
    request = {
        "Rule": self.name,
        "Targets": self._targets_request(targets),
    }
    response = self.client.put_targets(**request)
    self.changed = True
    return response


# Traceback (NameError)
The full traceback is:
Traceback (most recent call last):
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 427, in <module>
main()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 415, in main
cwe_rule_manager.ensure_present()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 267, in ensure_present
rule_description = self.rule.describe()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 145, in describe
except botocore.exceptions.ClientError as e:
NameError: global name 'botocore' is not defined

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 427, in <module>\n    main()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 415, in main\n    cwe_rule_manager.ensure_present()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 267, in ensure_present\n    rule_description = self.rule.describe()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 145, in describe\n    except botocore.exceptions.ClientError as e:\nNameError: global name 'botocore' is not defined\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def put_targets(self, targets):
    """Creates or updates the provided targets on the rule in AWS"""
    if not targets:
        return
    request = {
        "Rule": self.name,
        "Targets": self._targets_request(targets),
    }
    try:
        response = self.client.put_targets(**request)
    except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
        self.module.fail_json_aws(
            e, msg="Could not create/update rule targets for rule %s" % self.name
        )
    self.changed = True
    return response
# Buggy code
def remove_targets(self, target_ids):
    """Removes the provided targets from the rule in AWS"""
    if not target_ids:
        return
    request = {"Rule": self.name, "Ids": target_ids}
    response = self.client.remove_targets(**request)
    self.changed = True
    return response


# Traceback (NameError)
The full traceback is:
Traceback (most recent call last):
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 427, in <module>
main()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 415, in main
cwe_rule_manager.ensure_present()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 267, in ensure_present
rule_description = self.rule.describe()
File "/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py", line 145, in describe
except botocore.exceptions.ClientError as e:
NameError: global name 'botocore' is not defined

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 427, in <module>\n    main()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 415, in main\n    cwe_rule_manager.ensure_present()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 267, in ensure_present\n    rule_description = self.rule.describe()\n  File \"/var/folders/2d/bq5mpnnn38b06hwfr4ck8q1w9nfwpk/T/ansible_Zao6N2/ansible_module_cloudwatchevent_rule.py\", line 145, in describe\n    except botocore.exceptions.ClientError as e:\nNameError: global name 'botocore' is not defined\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def remove_targets(self, target_ids):
    """Removes the provided targets from the rule in AWS"""
    if not target_ids:
        return
    request = {"Rule": self.name, "Ids": target_ids}
    try:
        response = self.client.remove_targets(**request)
    except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
        self.module.fail_json_aws(
            e, msg="Could not remove rule targets from rule %s" % self.name
        )
    self.changed = True
    return response
# Buggy code
def map_config_to_obj(module):
    output = run_commands(module, ["show banner %s" % module.params["banner"]])
    obj = {"banner": module.params["banner"], "state": "absent"}
    if output:
        if module.params["transport"] == "cli":
            obj["text"] = output[0]
        else:
            # On EAPI we need to extract the banner text from dict key
            # 'loginBanner'
            if module.params["banner"] == "login":
                banner_response_key = "loginBanner"
            else:
                banner_response_key = "motd"
            if isinstance(output[0], dict) and banner_response_key in output[0].keys():
                obj["text"] = output[0][banner_response_key].strip("\n")
        obj["state"] = "present"
    return obj


# Traceback (AttributeError)
The full traceback is:
Traceback (most recent call last):
File "/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible__CH5Gb/ansible_module_eos_banner.py", line 197, in <module>
main()
File "/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible__CH5Gb/ansible_module_eos_banner.py", line 183, in main
commands = map_obj_to_commands((want, have), module)
File "/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible__CH5Gb/ansible_module_eos_banner.py", line 115, in map_obj_to_commands
have_text = have['text'].get('loginBanner') or have['text'].get('motd')
AttributeError: 'unicode' object has no attribute 'get'

fatal: [veos01]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible__CH5Gb/ansible_module_eos_banner.py\", line 197, in <module>\n    main()\n  File \"/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible__CH5Gb/ansible_module_eos_banner.py\", line 183, in main\n    commands = map_obj_to_commands((want, have), module)\n  File \"/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible__CH5Gb/ansible_module_eos_banner.py\", line 115, in map_obj_to_commands\n    have_text = have['text'].get('loginBanner') or have['text'].get('motd')\nAttributeError: 'unicode' object has no attribute 'get'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def map_config_to_obj(module):
    output = run_commands(module, ["show banner %s" % module.params["banner"]])
    obj = {"banner": module.params["banner"], "state": "absent"}
    if output:
        if module.params["transport"] == "cli":
            obj["text"] = output[0]
        else:
            # On EAPI we need to extract the banner text from dict key
            # 'loginBanner'
            if module.params["banner"] == "login":
                banner_response_key = "loginBanner"
            else:
                banner_response_key = "motd"
            if isinstance(output[0], dict) and banner_response_key in output[0].keys():
                obj["text"] = output[0]
        obj["state"] = "present"
    return obj
# Buggy code
def prompt(msg, private=False):
    prompt_string = to_bytes(msg, encoding=Display._output_encoding())
    if sys.version_info >= (3,):
        # Convert back into text on python3.  We do this double conversion
        # to get rid of characters that are illegal in the user's locale
        prompt_string = to_text(prompt_string)

    if private:
        return getpass.getpass(msg)
    else:
        return input(prompt_string)


# Traceback (UnicodeEncodeError)
ERROR! Unexpected Exception: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128)
the full traceback was:

Traceback (most recent call last):
File "/usr/bin/ansible-playbook", line 109, in <module>
exit_code = cli.run()
File "/usr/lib/python2.7/site-packages/ansible/cli/playbook.py", line 154, in run
results = pbex.run()
File "/usr/lib/python2.7/site-packages/ansible/executor/playbook_executor.py", line 119, in run
play.vars[vname] = display.do_var_prompt(vname, private, prompt, encrypt, confirm, salt_size, salt, default)
File "/usr/lib/python2.7/site-packages/ansible/utils/display.py", line 304, in do_var_prompt
result = do_prompt(msg, private)
File "/usr/lib/python2.7/site-packages/ansible/utils/display.py", line 278, in prompt
return getpass.getpass(msg)
File "/usr/lib64/python2.7/getpass.py", line 71, in unix_getpass
passwd = _raw_input(prompt, stream, input=input)
File "/usr/lib64/python2.7/getpass.py", line 128, in _raw_input
prompt = str(prompt)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128)

# Fixed code
def prompt(msg, private=False):
    prompt_string = to_bytes(msg, encoding=Display._output_encoding())
    if sys.version_info >= (3,):
        # Convert back into text on python3.  We do this double conversion
        # to get rid of characters that are illegal in the user's locale
        prompt_string = to_text(prompt_string)

    if private:
        return getpass.getpass(prompt_string)
    else:
        return input(prompt_string)
# Buggy code
def map_config_to_obj(module):
    obj = []

    rc, out, err = exec_command(module, "show ip static route")
    match = re.search(r".*Static local RIB for default\s*(.*)$", out, re.DOTALL)

    if match and match.group(1):
        for r in match.group(1).splitlines():
            splitted_line = r.split()

            cidr = ip_network(to_text(splitted_line[1]))
            prefix = str(cidr.network_address)
            mask = str(cidr.netmask)
            next_hop = splitted_line[4]
            admin_distance = splitted_line[2][1]

            obj.append(
                {
                    "prefix": prefix,
                    "mask": mask,
                    "next_hop": next_hop,
                    "admin_distance": admin_distance,
                }
            )

    return obj


# Traceback (ValueError)
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_VSnrSv/ansible_module_ios_static_route.py", line 235, in <module>
main()
File "/tmp/ansible_VSnrSv/ansible_module_ios_static_route.py", line 221, in main
have = map_config_to_obj(module)
File "/tmp/ansible_VSnrSv/ansible_module_ios_static_route.py", line 140, in map_config_to_obj
cidr = ip_network(to_text(splitted_line[1]))
File "/usr/lib/python2.7/site-packages/ipaddress.py", line 204, in ip_network
address)
ValueError: u'[1/0]' does not appear to be an IPv4 or IPv6 network

fatal: [student1-rtr1.net-ws.redhatgov.io]: FAILED! => {
"ansible_facts": {
"network_os": "ios"
},
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_VSnrSv/ansible_module_ios_static_route.py\", line 235, in <module>\n    main()\n  File \"/tmp/ansible_VSnrSv/ansible_module_ios_static_route.py\", line 221, in main\n    have = map_config_to_obj(module)\n  File \"/tmp/ansible_VSnrSv/ansible_module_ios_static_route.py\", line 140, in map_config_to_obj\n    cidr = ip_network(to_text(splitted_line[1]))\n  File \"/usr/lib/python2.7/site-packages/ipaddress.py\", line 204, in ip_network\n    address)\nValueError: u'[1/0]' does not appear to be an IPv4 or IPv6 network\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def map_config_to_obj(module):
    obj = []

    rc, out, err = exec_command(module, "show ip static route")
    match = re.search(r".*Static local RIB for default\s*(.*)$", out, re.DOTALL)

    if match and match.group(1):
        for r in match.group(1).splitlines():
            splitted_line = r.split()

            code = splitted_line[0]

            if code != "M":
                continue

            cidr = ip_network(to_text(splitted_line[1]))
            prefix = str(cidr.network_address)
            mask = str(cidr.netmask)
            next_hop = splitted_line[4]
            admin_distance = splitted_line[2][1]

            obj.append(
                {
                    "prefix": prefix,
                    "mask": mask,
                    "next_hop": next_hop,
                    "admin_distance": admin_distance,
                }
            )

    return obj
# Buggy code
def parse_power_supply_info(self, data):
    data = data["powersup"]["TABLE_psinfo"]["ROW_psinfo"]
    objects = list(self.transform_iterable(data, self.POWERSUP_MAP))
    return objects


# Traceback (KeyError)
he full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_GDri4V/ansible_module_nxos_facts.py", line 520, in <module>
main()
File "/tmp/ansible_GDri4V/ansible_module_nxos_facts.py", line 503, in main
inst.populate()
File "/tmp/ansible_GDri4V/ansible_module_nxos_facts.py", line 403, in populate
self.facts['_power_supply_info'] = self.parse_power_supply_info(data)
File "/tmp/ansible_GDri4V/ansible_module_nxos_facts.py", line 434, in parse_power_supply_info
data = data['powersup']['TABLE_psinfo']['ROW_psinfo']
KeyError: 'TABLE_psinfo'

# Fixed code
def parse_power_supply_info(self, data):
    if data.get("powersup").get("TABLE_psinfo_n3k"):
        data = data["powersup"]["TABLE_psinfo_n3k"]["ROW_psinfo_n3k"]
    else:
        data = data["powersup"]["TABLE_psinfo"]["ROW_psinfo"]
    objects = list(self.transform_iterable(data, self.POWERSUP_MAP))
    return objects
# Buggy code
def read_sysctl_file(self):
    lines = []
    if os.path.isfile(self.sysctl_file):
        try:
            f = open(self.sysctl_file, "r")
            lines = f.readlines()
            f.close()
        except IOError as e:
            self.module.fail_json(
                msg="Failed to open %s: %s" % (self.sysctl_file, str(e))
            )

    for line in lines:
        line = line.strip()
        self.file_lines.append(line)

        # don't split empty lines or comments
        if not line or line.startswith(("#", ";")):
            continue

        k, v = line.split("=", 1)
        k = k.strip()
        v = v.strip()
        self.file_values[k] = v.strip()


# Traceback (nValueError)
failed: [testhost1] (item={u'name': u'net.ipv4.tcp_sack', u'value': u'0'}) => {
"failed": true,
"item": {
"name": "net.ipv4.tcp_sack",
"value": "0"
},
"module_stderr": "Shared connection to testhost1 closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 397, in <module>\r\n    main()\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 391, in main\r\n    result = SysctlModule(module)\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 142, in __init__\r\n    self.process()\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 162, in process\r\n    self.read_sysctl_file()\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 323, in read_sysctl_file\r\n    k, v = line.split('=',1)\r\nValueError: need more than 1 value to unpack\r\n",
"msg": "MODULE FAILURE",
"rc": 1
}

# Fixed code
def read_sysctl_file(self):
    lines = []
    if os.path.isfile(self.sysctl_file):
        try:
            with open(self.sysctl_file, "r") as read_file:
                lines = read_file.readlines()
        except IOError as e:
            self.module.fail_json(
                msg="Failed to open %s: %s" % (self.sysctl_file, to_native(e))
            )

    for line in lines:
        line = line.strip()
        self.file_lines.append(line)

        # don't split empty lines or comments or line without equal sign
        if not line or line.startswith(("#", ";")) or "=" not in line:
            continue

        k, v = line.split("=", 1)
        k = k.strip()
        v = v.strip()
        self.file_values[k] = v.strip()
# Buggy code
def fix_lines(self):
    checked = []
    self.fixed_lines = []
    for line in self.file_lines:
        if not line.strip() or line.strip().startswith(("#", ";")):
            self.fixed_lines.append(line)
            continue
        tmpline = line.strip()
        k, v = tmpline.split("=", 1)
        k = k.strip()
        v = v.strip()
        if k not in checked:
            checked.append(k)
            if k == self.args["name"]:
                if self.args["state"] == "present":
                    new_line = "%s=%s\n" % (k, self.args["value"])
                    self.fixed_lines.append(new_line)
            else:
                new_line = "%s=%s\n" % (k, v)
                self.fixed_lines.append(new_line)

    if self.args["name"] not in checked and self.args["state"] == "present":
        new_line = "%s=%s\n" % (self.args["name"], self.args["value"])
        self.fixed_lines.append(new_line)


# Traceback (nValueError)
failed: [testhost1] (item={u'name': u'net.ipv4.tcp_sack', u'value': u'0'}) => {
"failed": true,
"item": {
"name": "net.ipv4.tcp_sack",
"value": "0"
},
"module_stderr": "Shared connection to testhost1 closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 397, in <module>\r\n    main()\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 391, in main\r\n    result = SysctlModule(module)\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 142, in __init__\r\n    self.process()\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 162, in process\r\n    self.read_sysctl_file()\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 323, in read_sysctl_file\r\n    k, v = line.split('=',1)\r\nValueError: need more than 1 value to unpack\r\n",
"msg": "MODULE FAILURE",
"rc": 1
}

# Fixed code
def fix_lines(self):
    checked = []
    self.fixed_lines = []
    for line in self.file_lines:
        if not line.strip() or line.strip().startswith(("#", ";")) or "=" not in line:
            self.fixed_lines.append(line)
            continue
        tmpline = line.strip()
        k, v = tmpline.split("=", 1)
        k = k.strip()
        v = v.strip()
        if k not in checked:
            checked.append(k)
            if k == self.args["name"]:
                if self.args["state"] == "present":
                    new_line = "%s=%s\n" % (k, self.args["value"])
                    self.fixed_lines.append(new_line)
            else:
                new_line = "%s=%s\n" % (k, v)
                self.fixed_lines.append(new_line)

    if self.args["name"] not in checked and self.args["state"] == "present":
        new_line = "%s=%s\n" % (self.args["name"], self.args["value"])
        self.fixed_lines.append(new_line)
# Buggy code
def write_sysctl(self):
    # open a tmp file
    fd, tmp_path = tempfile.mkstemp(
        ".conf", ".ansible_m_sysctl_", os.path.dirname(self.sysctl_file)
    )
    f = open(tmp_path, "w")
    try:
        for l in self.fixed_lines:
            f.write(l.strip() + "\n")
    except IOError as e:
        self.module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, str(e)))
    f.flush()
    f.close()

    # replace the real one
    self.module.atomic_move(tmp_path, self.sysctl_file)


# Traceback (nValueError)
failed: [testhost1] (item={u'name': u'net.ipv4.tcp_sack', u'value': u'0'}) => {
"failed": true,
"item": {
"name": "net.ipv4.tcp_sack",
"value": "0"
},
"module_stderr": "Shared connection to testhost1 closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 397, in <module>\r\n    main()\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 391, in main\r\n    result = SysctlModule(module)\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 142, in __init__\r\n    self.process()\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 162, in process\r\n    self.read_sysctl_file()\r\n  File \"/tmp/ansible_BLCuvV/ansible_module_sysctl.py\", line 323, in read_sysctl_file\r\n    k, v = line.split('=',1)\r\nValueError: need more than 1 value to unpack\r\n",
"msg": "MODULE FAILURE",
"rc": 1
}

# Fixed code
def write_sysctl(self):
    # open a tmp file
    fd, tmp_path = tempfile.mkstemp(
        ".conf", ".ansible_m_sysctl_", os.path.dirname(self.sysctl_file)
    )
    f = open(tmp_path, "w")
    try:
        for l in self.fixed_lines:
            f.write(l.strip() + "\n")
    except IOError as e:
        self.module.fail_json(
            msg="Failed to write to file %s: %s" % (tmp_path, to_native(e))
        )
    f.flush()
    f.close()

    # replace the real one
    self.module.atomic_move(tmp_path, self.sysctl_file)