internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: ansible/ansible

Issue:
iptables: "!" argument ignored in the source specification
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
iptables

##### ANSIBLE VERSION
```
ansible 2.3.1.0
  config file =
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
```

##### CONFIGURATION
Nothing particular

##### OS / ENVIRONMENT
CentOS Linux release 7.3.1611 (Core)

##### SUMMARY
iptables module doesn't properly handle "!" in the source specification, contradicting the documentation.

##### STEPS TO REPRODUCE
Run the following playbook to create a rule equivalent to:
`iptables -t nat -A PREROUTING ! -s 10.2.64.3 -p tcp --dport 80 -j DNAT --to 10.2.64.3:3128`

```yaml
  iptables:
    table: nat
    chain: PREROUTING
    source: ! 10.2.64.3
    protocol: tcp
    destination_port: 80
    jump: DNAT
    to_destination: 10.2.64.3:3128
```

##### EXPECTED RESULTS
```
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DNAT       tcp  -- !10-2-64-3_hostname  anywhere             tcp dpt:http to:10.2.64.3:3128
```

##### ACTUAL RESULTS
```
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DNAT       tcp  --  10-2-64-3_hostname  anywhere             tcp dpt:http to:10.2.64.3:3128
```

As you can see, the "!" is missing.


Discussion:
cc @LinusU
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/system/iptables.py b/lib/ansible/modules/system/iptables.py
--- a/lib/ansible/modules/system/iptables.py
+++ b/lib/ansible/modules/system/iptables.py
@@ -364,7 +364,10 @@ def append_param(rule, param, flag, is_list):
             append_param(rule, item, flag, False)
     else:
         if param is not None:
-            rule.extend([flag, param])
+            if param[0] == '!':
+                rule.extend(['!', flag, param[1:]])
+            else:
+                rule.extend([flag, param])
 
 
 def append_csv(rule, param, flag):


Test patch:
Repository: ansible/ansible

Issue:
Hostname module doesn't work on Red Hat Atomic Host
```
# ansible -m hostname -a "name=sample.testrelm.test" atomic  -k
SSH password:
192.168.122.34 | FAILED! => {
    "changed": false,
    "failed": true,
    "msg": "hostname module cannot be used on platform Linux (Red hat enterprise linux atomic host)"
}
```

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
modules/system/hostname.py

##### ANSIBLE VERSION
```
2.4 
```

##### CONFIGURATION
Default

##### OS / ENVIRONMENT
Control node: Red Hat Enterprise Linux Server 7
Red Hat Enterprise Linux Atomic Host 7

##### SUMMARY
User should be able to change hostname of Red Hat Atomic Host using `hostname` module.

##### STEPS TO REPRODUCE
```
ansible -m hostname -a "name=atomic001.testrelm.test" atomic
```


##### EXPECTED RESULTS
Hostname should change using `hostname` module 

##### ACTUAL RESULTS
```
# ansible -m hostname -a "name=sample.testrelm.test" atomic  -k
SSH password:
192.168.122.34 | FAILED! => {
    "changed": false,
    "failed": true,
    "msg": "hostname module cannot be used on platform Linux (Red hat enterprise linux atomic host)"
}
```

I have a working patch for this.


Discussion:
cc @alikins @saito-hideki
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/system/hostname.py b/lib/ansible/modules/system/hostname.py
--- a/lib/ansible/modules/system/hostname.py
+++ b/lib/ansible/modules/system/hostname.py
@@ -637,6 +637,11 @@ class RedHatWorkstationHostname(Hostname):
     distribution = 'Red hat enterprise linux workstation'
     strategy_class = RedHatStrategy
 
+class RedHatAtomicHostname(Hostname):
+    platform = 'Linux'
+    distribution = 'Red hat enterprise linux atomic host'
+    strategy_class = RedHatStrategy
+
 class CentOSHostname(Hostname):
     platform = 'Linux'
     distribution = 'Centos'


Test patch:
Repository: ansible/ansible

Issue:
mongodb lookup exception with python3 but python2 works well
when i use ansible under python3 with pymongo installed, an error occured:
```
fatal: [***]: FAILED! => {"failed": true, "msg": "An unhandled exception occurred while running the lookup
plugin 'mongodb'. Error was a <class 'NameError'>, original message: name 'long' is not defined"}
```

i search this with google, and find that py3 shoud use int instead of long, plz fix it, thx



Discussion:
@wsbmilk Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information. 

Here are the items we could not find in your description:
- issue type
- ansible version
- component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_missing_data --->

Resolving patch:
diff --git a/lib/ansible/plugins/lookup/mongodb.py b/lib/ansible/plugins/lookup/mongodb.py
--- a/lib/ansible/plugins/lookup/mongodb.py
+++ b/lib/ansible/plugins/lookup/mongodb.py
@@ -89,7 +89,7 @@
 
 from __future__ import (absolute_import, division, print_function)
 from __future__ import unicode_literals
-from ansible.module_utils.six import string_types
+from ansible.module_utils.six import string_types, integer_types
 import datetime
 
 __metaclass__ = type
@@ -139,7 +139,7 @@ def _convert_sort_string_to_constant(self, item):
     def convert_mongo_result_to_valid_json(self, result):
         if result is None:
             return result
-        if isinstance(result, (int, long, float, bool)):
+        if isinstance(result, integer_types + (float, bool)):
             return result
         if isinstance(result, string_types):
             return result


Test patch:
Repository: ansible/ansible

Issue:
Update docs for module set_stats to say how it is displayed
Issue Type: Documentation Report
Component name: module/set_stats
Ansible Version: 2.3

Summary:
Please update the documentation for set_stats module to say to tell the user that to display the stats collected by the set_stats module, the SHOW_CUSTOM_STATS has to be set to true by either "show_custom_stats=true" in the ansible.cfg or by setting ANSIBLE_SHOW_CUSTOM_STATS

Expected Results:
Learn from documentation how to display stats collected by set_stats

Actual Results:
Hours of investigative work in source code.



Discussion:
Thanks for digging in and find this out - I had been wondering how to get them to display too.

Resolving patch:
diff --git a/lib/ansible/modules/utilities/logic/set_stats.py b/lib/ansible/modules/utilities/logic/set_stats.py
--- a/lib/ansible/modules/utilities/logic/set_stats.py
+++ b/lib/ansible/modules/utilities/logic/set_stats.py
@@ -47,6 +47,7 @@
     default: yes
 notes:
     - This module is also supported for Windows targets.
+    - In order for custom stats to be displayed, you must set C(show_custom_stats) in C(ansible.cfg) or C(ANSIBLE_SHOW_CUSTOM_STATS) to C(true).
 version_added: "2.3"
 '''
 


Test patch:
Repository: ansible/ansible

Issue:
selinux module crashes in 2.4
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
selinux module

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/dsa/sa-ansible/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
```

##### CONFIGURATION
<!---
become: true
-->

##### OS / ENVIRONMENT
<!---
RHEL7
-->

##### SUMMARY
<!--- Explain the problem briefly -->
We are unable to use the selinux module because it crashes at startup : it looks for a no more existing function :  from ansible.module_utils.facts import get_file_lines

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
 ansible -i preprod server1 -m selinux -a "policy=targeted state=enforcing"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Module sets selinux as expected

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
 ansible -i preprod server1 -m selinux -a "policy=targeted state=enforcing"
server1 | FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "Shared connection to 10.10.10.243 closed.\r\n",
    "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_mzVAqX/ansible_module_selinux.py\", line 81, in <module>\r\n    from ansible.module_utils.facts import get_file_lines\r\nImportError: cannot import name get_file_lines\r\n",
    "msg": "MODULE FAILURE",
    "rc": 0
}
```



Discussion:
cc @goozbach
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Confirmed issue.

Resolving patch:
diff --git a/lib/ansible/modules/system/selinux.py b/lib/ansible/modules/system/selinux.py
--- a/lib/ansible/modules/system/selinux.py
+++ b/lib/ansible/modules/system/selinux.py
@@ -78,7 +78,7 @@
 except ImportError:
     HAS_SELINUX = False
 from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.facts import get_file_lines
+from ansible.module_utils.facts.utils import get_file_lines
 
 
 # getter subroutines


Test patch:
Repository: ansible/ansible

Issue:
Virtualization detection fails for UEFI VMware guests

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
module_utils/facts/virtual/linux.py

##### ANSIBLE VERSION

```
ansible 2.3.0.0
  config file = 
  configured module search path = Default w/o overrides
  python version = 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170118]
```

##### CONFIGURATION

##### OS / ENVIRONMENT
Debian 9.0

##### SUMMARY
A VMware guest booted with UEFI will report 'VMWare7,1 in the DMI product name, but ansible only looks for 'VMware Virtual Platform' which is what it reports when booted with legacy BIOS.

##### STEPS TO REPRODUCE
Create a Linux VMware VM that boots via UEFI, run `ansible -m setup`

##### EXPECTED RESULTS
`"ansible_virtualization_role": "guest"`

##### ACTUAL RESULTS
`"ansible_virtualization_role": "NA"`

The fix will just be to add an extra match in https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/facts/virtual/linux.py#L95

See http://www.kraftkennedy.com/fix-ztigather-to-work-with-uefi-in-vmware-workstation/ for what tipped me off for this error.



Discussion:

Resolving patch:
diff --git a/lib/ansible/module_utils/facts/virtual/linux.py b/lib/ansible/module_utils/facts/virtual/linux.py
--- a/lib/ansible/module_utils/facts/virtual/linux.py
+++ b/lib/ansible/module_utils/facts/virtual/linux.py
@@ -92,7 +92,7 @@ def get_virtual_facts(self):
             virtual_facts['virtualization_role'] = 'guest'
             return virtual_facts
 
-        if product_name == 'VMware Virtual Platform':
+        if product_name in ['VMware Virtual Platform', 'VMware7,1']:
             virtual_facts['virtualization_type'] = 'VMware'
             virtual_facts['virtualization_role'] = 'guest'
             return virtual_facts


Test patch:
Repository: ansible/ansible

Issue:
nxos_command :  using nxapi as transport doesn't return json output
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
- nxos_command

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (devel 10233ef3b5) last updated 2017/07/06 14:34:45 (GMT -400)
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/agents-ci/ansible/lib/ansible
  executable location = /root/agents-ci/ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
- Ansible Server : Ubuntu 14.04
- Device: Nexus9000 C9508  running 7.0(3)I6(1)

##### SUMMARY
<!--- Explain the problem briefly -->
While using transport as nxapi, it seems that cli is being used. This is observed when show commands don't return json structured output.

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
command to return structured json output by default without having to '| json' for nxapi.



Discussion:
cc @jedelman8 @GGabriele @privateip @rcarrillocruz @mikewiebe @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
The assumption that the default output for nxapi is json may be invalid, and it's more likely the same output as when using the cli. http://www.cisco.com/c/en/us/td/docs/switches/datacenter/mds9000/sw/8_1/programmability/cisco_mds9000_programmability_guide_8x/nx_api.html#concept_7CDD59B3BC714986BDB9FCAD9FBE858D

@rahushen can you review the guide and confirm our understanding, thanks!



Resolving patch:
diff --git a/lib/ansible/module_utils/nxos.py b/lib/ansible/module_utils/nxos.py
--- a/lib/ansible/module_utils/nxos.py
+++ b/lib/ansible/module_utils/nxos.py
@@ -375,11 +375,9 @@ def to_command(module, commands):
 
     commands = transform(to_list(commands))
 
-    for index, item in enumerate(commands):
+    for item in commands:
         if is_json(item['command']):
             item['output'] = 'json'
-        elif is_text(item['command']):
-            item['output'] = 'text'
 
     return commands
 


Test patch:
Repository: ansible/ansible

Issue:
Keep ansible-playbook from bombing without extra-vars
A recent change to ansible-playbook to support json extra-vars
also inadvertently broke the script when no extra-vars are
provided. Simply checking to make sure it is defined and truthy
should take care of the issue.

This appears to fix issues #3086 and #3088.



Discussion:
Merged, thanks... somehow skipped the test check on this one.  Urg.  

Thanks!


Resolving patch:
diff --git a/lib/ansible/modules/system/known_hosts.py b/lib/ansible/modules/system/known_hosts.py
--- a/lib/ansible/modules/system/known_hosts.py
+++ b/lib/ansible/modules/system/known_hosts.py
@@ -37,7 +37,7 @@
   name:
     aliases: [ 'host' ]
     description:
-      - The host to add or remove (must match a host specified in key)
+      - The host to add or remove (must match a host specified in key). It will be converted to lowercase so that ssh-keygen can find it.
     required: true
     default: null
   key:
@@ -101,7 +101,7 @@ def enforce_state(module, params):
     Add or remove key.
     """
 
-    host = params["name"]
+    host = params["name"].lower()
     key = params.get("key", None)
     port = params.get("port", None)
     path = params.get("path")


Test patch:
Repository: ansible/ansible

Issue:
cs_facts needs porting to the new facts API
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
lib/ansible/modules/cloud/cloudstack/cs_facts.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
devel
```

##### SUMMARY
Cleaning up all undefined variables so that we can enable static analysis checks to keep new undefined variables from entering the code base.  the cs_facts module has two undefined variables that are caused by the 2.4 facts rewrite and needs to be fixed.

Here's the pylint output:
```
************* Module ansible.modules.cloud.cloudstack.cs_facts
E0611:109, 0: No name 'ansible_facts' in module 'ansible.module_utils.facts' (no-name-in-module)
E0611:109, 0: No name 'module' in module 'ansible.module_utils.facts' (no-name-in-module)
```


Discussion:
@alikins are you able to look into this?  There's only a few problems left before we can enable the pylint tests.
cc @resmo
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/cloud/cloudstack/cs_facts.py b/lib/ansible/modules/cloud/cloudstack/cs_facts.py
--- a/lib/ansible/modules/cloud/cloudstack/cs_facts.py
+++ b/lib/ansible/modules/cloud/cloudstack/cs_facts.py
@@ -106,7 +106,7 @@
 import os
 from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils.urls import fetch_url
-from ansible.module_utils.facts import ansible_facts, module
+from ansible.module_utils.facts import ansible_collector, default_collectors
 
 try:
     import yaml
@@ -121,7 +121,12 @@
 class CloudStackFacts(object):
 
     def __init__(self):
-        self.facts = ansible_facts(module)
+        collector = ansible_collector.get_ansible_collector(all_collector_classes=default_collectors.collectors,
+                                                            filter_spec='default_ipv4',
+                                                            gather_subset=['!all', 'network'],
+                                                            gather_timeout=10)
+        self.facts = collector.collect(module)
+
         self.api_ip = None
         self.fact_paths = {
             'cloudstack_service_offering': 'service-offering',


Test patch:
Repository: ansible/ansible

Issue:
nxos_smu undefined variable
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE

 - Bug Report

##### COMPONENT NAME
lib/ansible/modules/network/nxos/nxos_smu.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
devel
```
##### SUMMARY
I'm fixing all undefined variables in the code base so that we can start using static analysis to prevent new undefined variables from creeping in.  For the nxos_smu module, there is an undefined variable that I don't know how to deal with:

The response variable is undefined in the module here:
https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/network/nxos/nxos_smu.py#L117

This will lead to a traceback.  It isn't obvious what response should be.  It's tempting to set it like this:
```response = load_config(module, [command])``` but looking at load_config() in the library, it seems that load_config() always returns None.  Since None is not iterable, 'failure' in None would then traceback.

Some help would be appreciated so that we can enable the undefined variables tests.


Discussion:
References: #27254 
cc @GGabriele @jedelman8 @mikewiebe @privateip @rahushen @rcarrillocruz @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/network/nxos/nxos_smu.py b/lib/ansible/modules/network/nxos/nxos_smu.py
--- a/lib/ansible/modules/network/nxos/nxos_smu.py
+++ b/lib/ansible/modules/network/nxos/nxos_smu.py
@@ -114,8 +114,6 @@ def apply_patch(module, commands):
     for command in commands:
         load_config(module, [command])
         time.sleep(5)
-        if 'failed' in response:
-            module.fail_json(msg="Operation failed!", response=response)
 
 
 def get_commands(module, pkg, file_system):


Test patch:
Repository: ansible/ansible

Issue:
Wrong statement in composer module documentation
##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Documentation Report

##### COMPONENT NAME
composer

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
2.4
```

Hi,

I'm openning this issue just to point out that the composer module's documentation states contradicting thing.
c.f. https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/packaging/language/composer.py#L115 and https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/packaging/language/composer.py#L117.
First states that this option is not enabled by default, as it makes the process longer. The second, though, states the default value is `True`.

Is there some kind of reversed logic ? Or is it a real bug in the documentation ?

Regards,
billietl


Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/packaging/language/composer.py b/lib/ansible/modules/packaging/language/composer.py
--- a/lib/ansible/modules/packaging/language/composer.py
+++ b/lib/ansible/modules/packaging/language/composer.py
@@ -112,7 +112,7 @@
         description:
             - Optimize autoloader during autoloader dump (see --optimize-autoloader).
             - Convert PSR-0/4 autoloading to classmap to get a faster autoloader.
-            - Recommended especially for production, but can take a bit of time to run so it is currently not done by default.
+            - Recommended especially for production, but can take a bit of time to run.
         required: false
         default: true
         choices: [ true, false]


Test patch: