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

Issue:
Cloudflare module doesn't update CNAME
Current code doesn't work as expected:
https://github.com/ansible/ansible/blob/10cd2cd1b787bff544acb52ff3ecabfa41119318/lib/ansible/modules/net_tools/cloudflare_dns.py#L578

It should be: 
if (**params['type']** == 'CNAME') and (cur_record['content'] != new_record['content']):


Discussion:
@markocelan 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:
- 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 --->
@markocelan Would you like to raise a PR to fix this? Thanks in advance.

Resolving patch:
diff --git a/lib/ansible/modules/net_tools/cloudflare_dns.py b/lib/ansible/modules/net_tools/cloudflare_dns.py
--- a/lib/ansible/modules/net_tools/cloudflare_dns.py
+++ b/lib/ansible/modules/net_tools/cloudflare_dns.py
@@ -575,7 +575,7 @@ def ensure_dns_record(self, **kwargs):
             if ('data' in new_record) and ('data' in cur_record):
                 if (cur_record['data'] > new_record['data']) - (cur_record['data'] < new_record['data']):
                     do_update = True
-            if (type == 'CNAME') and (cur_record['content'] != new_record['content']):
+            if (params['type'] == 'CNAME') and (cur_record['content'] != new_record['content']):
                 do_update = True
             if do_update:
                 if self.module.check_mode:


Test patch:
Repository: ansible/ansible

Issue:
group_by_aws_account prints IP addresses, not hostnames
##### ISSUE TYPE

 - Bug Report

##### COMPONENT NAME

contrib/inventory/ec2.py

##### ANSIBLE VERSION

```
ansible 2.4.0 (devel ffa92485b4) last updated 2017/04/19 17:16:21 (GMT -400)
  config file = /ansible/dom/ansible.cfg
  configured module search path = [u'/home/jsmift/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/jsmift/src/ansible-ansible/lib/ansible
  executable location = /home/jsmift/src/ansible-ansible/bin/ansible
  python version = 2.7.12 (default, Sep  1 2016, 22:14:00) [GCC 4.8.3 20140911 (Red Hat 4.8.3-9)]
```

##### CONFIGURATION

In ec2.ini:

```
destination_variable = private_ip_address 
vpc_destination_variable = private_ip_address 
hostname_variable = tag_Name 
/group_by_aws_account = True
```

##### OS / ENVIRONMENT

Amazon Linux AMI release 2016.09

##### SUMMARY

When you run ec2.py, with the configuration described above (which is intended/expected to use the 'Name' tag as the hostname), ec2.py creates a group with our account ID, listing our hosts by their IP address.

##### STEPS TO REPRODUCE

```
rm -rf /tmp/ansible-test
mkdir -p /tmp/ansible-test
cd /tmp/ansible-test
git clone https://github.com/ansible/ansible
cd ansible
sed -i -e 's/^destination_variable.*$/destination_variable = private_ip_address/' \
       -e 's/^vpc_destination_variable.*$/vpc_destination_variable = private_ip_address/' \
       -e 's/^#hostname_variable = tag_Name$/hostname_variable = tag_Name/' \
       -e 's/^#rds = False$/rds = False/' \
       -e 's/^group_by_aws_account.*/group_by_aws_account = True/' \
       contrib/inventory/ec2.ini
. hacking/env-setup
./contrib/inventory/ec2.py --list | jp '"<an AWS account number>"'
```

...where <AWS account number> is one of your AWS account numbers.

##### EXPECTED RESULTS

A list of the "Name" tag values of our instances.

##### ACTUAL RESULTS

A list of the IP addresses of our instances.


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

Resolving patch:
diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py
--- a/contrib/inventory/ec2.py
+++ b/contrib/inventory/ec2.py
@@ -1026,7 +1026,7 @@ def add_instance(self, instance, region):
 
         # Inventory: Group by AWS account ID
         if self.group_by_aws_account:
-            self.push(self.inventory, self.aws_account_id, dest)
+            self.push(self.inventory, self.aws_account_id, hostname)
             if self.nested_groups:
                 self.push_group(self.inventory, 'accounts', self.aws_account_id)
 


Test patch:
Repository: ansible/ansible

Issue:
Date in YAML can't work with to_nice_json

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
to_nice_json

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]

```

##### CONFIGURATION
ANSIBLE_PIPELINING(/etc/ansible/ansible.cfg) = True
DEFAULT_JINJA2_EXTENSIONS(/etc/ansible/ansible.cfg) = jinja2.ext.do,jinja2.ext.i18n

##### OS / ENVIRONMENT
Debian 9.2

##### SUMMARY
the to_nice_json function can't work with YAML date_time objects.

I have some metadata like:

    created_test0: 2017-12-01T01:01:00-08:00
    created_test1: 2010-04-16 16:32:03 -5

Both are just test variables. Both are parsed into dates and then to_nice_json chokes on them.

##### STEPS TO REPRODUCE

Create a YAML file with dates, use a jinja2 template to convert it to a json file and it will fail.

##### EXPECTED RESULTS

Returned as an ISO8601 string in JSON:

https://stackoverflow.com/questions/10286204/the-right-json-date-format

##### ACTUAL RESULTS


<!--- Paste verbatim command output between quotes below -->
```
fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError: Unexpected templating type error occurred on ({{static_yaml_data | to_nice_json}}): datetime.datetime(2017, 12, 1, 9, 1) is not JSON serializable"}

```



Discussion:
This looks like a reasonable solution:

https://gist.github.com/drmalex07/5149635e6ab807c8b21e

Resolving patch:
diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py
--- a/lib/ansible/plugins/filter/core.py
+++ b/lib/ansible/plugins/filter/core.py
@@ -35,7 +35,7 @@
 import yaml
 
 from collections import MutableMapping, MutableSequence
-from datetime import datetime
+import datetime
 from functools import partial
 from random import Random, SystemRandom, shuffle
 
@@ -69,6 +69,8 @@ class AnsibleJSONEncoder(json.JSONEncoder):
     def default(self, o):
         if isinstance(o, HostVars):
             return dict(o)
+        elif isinstance(o, (datetime.date, datetime.datetime)):
+            return o.isoformat()
         else:
             return super(AnsibleJSONEncoder, self).default(o)
 
@@ -126,7 +128,7 @@ def to_bool(a):
 
 
 def to_datetime(string, format="%Y-%m-%d %H:%M:%S"):
-    return datetime.strptime(string, format)
+    return datetime.datetime.strptime(string, format)
 
 
 def strftime(string_format, second=None):


Test patch:
Repository: ansible/ansible

Issue:
selective output does change color for failed tasks
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
callback/selective

##### ANSIBLE VERSION
```
ansible 2.4.2.0
  config file = /Users/cyril/work/vps/playbook/ansible.cfg
  configured module search path = [u'/Users/cyril/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/cyril/work/kubespray.env/lib/python2.7/site-packages/ansible
  executable location = /Users/cyril/work/kubespray.env/bin/ansible
  python version = 2.7.14 (default, Sep 25 2017, 09:54:19) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
```

##### CONFIGURATION
DEFAULT_HOST_LIST(/Users/cyril/work/vps/playbook/ansible.cfg) = [u'/Users/cyril/work/vps/playbook/hosts']
DEFAULT_REMOTE_USER(/Users/cyril/work/vps/playbook/ansible.cfg) = ansible
HOST_KEY_CHECKING(/Users/cyril/work/vps/playbook/ansible.cfg) = False

##### OS / ENVIRONMENT
N/A

##### SUMMARY
selective stdout plugin does not display the color when a task is failed.
ANSIBLE_STDOUT_CALLBACK=selective ansible-playbook debug.yml

##### STEPS TO REPRODUCE

```yaml
- hosts: "*"
  tasks:
  - name: assert
    assert:
      that:
        - inventory_hostname == 'do.not.exist'
      msg: FAIL
    tags:
      - print_action
```



##### EXPECTED RESULTS

I expect to see the msg "FAIL" in red.

```
  * host1          - changed=False -- FAIL ------------------------------------
  * host2          - changed=False -- FAIL ------------------------------------
  * host3          - changed=False -- FAIL ------------------------------------
```

It looks like it was introduced in this PR https://github.com/ansible/ansible/pull/27175 that adds a clean_copy to TaskResult that removes 'failed' and 'skipped' keys.

https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/selective.py#L183 uses those keys to detect failed/unreachable instead of using the proper callbacks.

##### ACTUAL RESULTS

same as expected, but the msg "FAIL" is green





Discussion:
Files identified in the description:
* [lib/ansible/plugins/callback/selective.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/selective.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

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

Resolving patch:
diff --git a/lib/ansible/executor/task_result.py b/lib/ansible/executor/task_result.py
--- a/lib/ansible/executor/task_result.py
+++ b/lib/ansible/executor/task_result.py
@@ -10,8 +10,8 @@
 from ansible.parsing.dataloader import DataLoader
 from ansible.vars.clean import strip_internal_keys
 
-_IGNORE = ('failed', 'skipped')
-_PRESERVE = ('attempts', 'changed', 'retries')
+_IGNORE = tuple()
+_PRESERVE = ('attempts', 'changed', 'retries', 'failed', 'unreachable', 'skipped')
 
 
 class TaskResult:


Test patch:
Repository: ansible/ansible

Issue:
aci_epg_to_domain: Module does not need to support OpenStack
_From @nilloBE on October 10, 2017 9:11_

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
aci_epg_to_domain

##### ANSIBLE VERSION
v2.5

##### SUMMARY
The module aci_epg_to_domain allows mapping an EPG to a Physical or Virtual Domain in ACI. The Virtual Domain allows the user to specify the domain type selecting VMware, Microsoft or OpenStack.

In this setting, OpenStack should be removed because the OpenStack EPGs should not be created or manipulated directly via Ansible, but instead via Neutron. 

_Copied from original issue: datacenter/aci-ansible#163_


Discussion:
_From @jmcgill298 on October 21, 2017 3:36_

@nilloBE regardless of what people should configure, does the module support invalid API requests to the APIC?
_From @nilloBE on October 21, 2017 9:19_

The module does not support invalid API requests. You can actually through this module map an EPG to an OpenStack domain, from an API perspective this is not an invalid request. But the EPG will not exists in neutron DB unless it is created by neutron, and therefore it will not be usable at all by the OpenStack workloads. With OpenStack, users must leverage neutron API which will in turn create EPGs on the ACI fabric and automatically map them to the right VMM domain.
_From @jmcgill298 on November 1, 2017 13:59_

If ACI supports something that is invalid, then I would put that on Cisco needs to remove the feature. If they are supporting it, then I would rather assume that someone is using it, or that Cisco has plans to make it useful.
@nilloBE I think the better approach here is to add notes to the documentation of the module to clarify what is expected for this specific use-case. And leave the functionality in the module.

Can you propose the exact wording for the note in the module ?
cc @brunocalogero @schunduri
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @jmcgill298 
I agree with the above proposed approach. I would suggest the following as text:
"OpenStack VMM domains must not be created using this module. The OpenStack VMM domain is created directly by the Cisco APIC Neutron plugin as part of the installation and configuration. This module can be used to query status of an OpenStack VMM domain."

Resolving patch:
diff --git a/lib/ansible/modules/network/aci/aci_epg_to_domain.py b/lib/ansible/modules/network/aci/aci_epg_to_domain.py
--- a/lib/ansible/modules/network/aci/aci_epg_to_domain.py
+++ b/lib/ansible/modules/network/aci/aci_epg_to_domain.py
@@ -24,6 +24,9 @@
 notes:
 - The C(tenant), C(ap), C(epg), and C(domain) used must exist before using this module in your playbook.
   The M(aci_tenant) M(aci_ap), M(aci_epg) M(aci_domain) modules can be used for this.
+- OpenStack VMM domains must not be created using this module. The OpenStack VMM domain is created directly
+  by the Cisco APIC Neutron plugin as part of the installation and configuration.
+  This module can be used to query status of an OpenStack VMM domain.
 options:
   allow_useg:
     description:


Test patch:
Repository: ansible/ansible

Issue:
Filter list of IP addresses on range
##### ISSUE TYPE

 - Feature Idea

##### COMPONENT NAME

`ipaddr`

##### ANSIBLE VERSION

```ansible 2.5.0 (devel 0a9489ef66) last updated 2018/01/16 12:43:50 (GMT +200)```

##### SUMMARY

Related to the resolved issue #34792 I need the ability to filter a list of IP addresses on a given IP range in order to determine the correct address to add to the in-memory inventory.

For this I propose adding this functionality to the existing `ipaddr` filter, similar to `network_in_network` but taking a list as the first parameter and a network as the second parameter and returning the filtered list of addresses.


Discussion:

Resolving patch:
diff --git a/lib/ansible/plugins/filter/ipaddr.py b/lib/ansible/plugins/filter/ipaddr.py
--- a/lib/ansible/plugins/filter/ipaddr.py
+++ b/lib/ansible/plugins/filter/ipaddr.py
@@ -900,6 +900,39 @@ def network_in_network(value, test):
         return False
 
 
+def reduce_on_network(value, network):
+    '''
+    Reduces a list of addresses to only the addresses that match a given network.
+
+    :param: value: The list of addresses to filter on.
+    :param: network: The network to validate against.
+
+    :return: The reduced list of addresses.
+    '''
+    # normalize network variable into an ipaddr
+    n = _address_normalizer(network)
+
+    # get first and last addresses as integers to compare value and test; or cathes value when case is /32
+    n_first = ipaddr(ipaddr(n, 'network') or ipaddr(n, 'address'), 'int')
+    n_last = ipaddr(ipaddr(n, 'broadcast') or ipaddr(n, 'address'), 'int')
+
+    # create an empty list to fill and return
+    r = []
+
+    for address in value:
+        # normalize address variables into an ipaddr
+        a = _address_normalizer(address)
+
+        # get first and last addresses as integers to compare value and test; or cathes value when case is /32
+        a_first = ipaddr(ipaddr(a, 'network') or ipaddr(a, 'address'), 'int')
+        a_last = ipaddr(ipaddr(a, 'broadcast') or ipaddr(a, 'address'), 'int')
+
+        if _range_checker(a_first, n_first, n_last) and _range_checker(a_last, n_first, n_last):
+            r.append(address)
+
+    return r
+
+
 # Returns the SLAAC address within a network for a given HW/MAC address.
 # Usage:
 #
@@ -1002,6 +1035,7 @@ class FilterModule(object):
         'next_nth_usable': next_nth_usable,
         'network_in_network': network_in_network,
         'network_in_usable': network_in_usable,
+        'reduce_on_network': reduce_on_network,
         'nthhost': nthhost,
         'previous_nth_usable': previous_nth_usable,
         'slaac': slaac,


Test patch:
Repository: ansible/ansible

Issue:
docker_container: Always recreates container when mac_address is used
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
docker_container

##### ANSIBLE VERSION
```
ansible 2.4.2.0
```

##### CONFIGURATION
N/A

##### OS / ENVIRONMENT
* Source Host : Debian 8
* Target Host : Debian 8
* Target docker:
```
Docker version 17.12.0-ce, build c97c6d6
```
* Target docker-py:
```
docker-py (1.10.6)
docker-pycreds (0.2.1)
```

##### SUMMARY
When mac_address is specified, ansible always recreates the container on the target host.

##### STEPS TO REPRODUCE

Run this task twice:

```yaml
        -
            docker_container:
                name: test
                image: "debian:8"
                command: "sleep infinity"
                mac_address: "02-00-00-00-00-01"
```

##### EXPECTED RESULTS
Container is created on first run, no changes made on second run.

##### ACTUAL RESULTS

Container is recreated on the second run, which is not the case if i remove mac_address configuration field.



Discussion:
Files identified in the description:
* [lib/ansible/modules/cloud/docker/docker_container.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/docker/docker_container.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @chouseknecht @cove @dusdanig @jctanner @joshuaconner @kassiansun @softzilla @zfil
[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/docker/docker_container.py b/lib/ansible/modules/cloud/docker/docker_container.py
--- a/lib/ansible/modules/cloud/docker/docker_container.py
+++ b/lib/ansible/modules/cloud/docker/docker_container.py
@@ -842,6 +842,10 @@ def __init__(self, client):
                 if network.get('links'):
                     network['links'] = self._parse_links(network['links'])
 
+        if self.mac_address:
+            # Ensure the MAC address uses colons instead of hyphens for later comparison
+            self.mac_address = self.mac_address.replace('-', ':')
+
         if self.entrypoint:
             # convert from list to str.
             self.entrypoint = ' '.join([str(x) for x in self.entrypoint])


Test patch:
Repository: ansible/ansible

Issue:
contrib/inventory/scaleway.py inventory script fail if auth.api_token missing in ini conf file
I set only `SCALEWAY_TOKEN` environment variable and inventory script fail [here](https://github.com/ansible/ansible/blob/devel/contrib/inventory/scaleway.py#L156) if `auth.api_token` missing in ini conf file.

I think that `auth.api_token` must not been required.

cc @paulRbr 
contrib/inventory/scaleway.py inventory script fail if auth.api_token missing in ini conf file
I set only `SCALEWAY_TOKEN` environment variable and inventory script fail [here](https://github.com/ansible/ansible/blob/devel/contrib/inventory/scaleway.py#L156) if `auth.api_token` missing in ini conf file.

I think that `auth.api_token` must not been required.

cc @paulRbr 


Discussion:
@harobed 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 --->
@harobed 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/contrib/inventory/scaleway.py b/contrib/inventory/scaleway.py
--- a/contrib/inventory/scaleway.py
+++ b/contrib/inventory/scaleway.py
@@ -152,8 +152,13 @@ def generate_inv_from_api(config):
     try:
         inventory['all'] = copy.deepcopy(EMPTY_GROUP)
 
-        auth_token = env_or_param(
-            'SCALEWAY_TOKEN', config.get('auth', 'api_token'))
+        if config.has_option('auth', 'api_token'):
+            auth_token = config.get('auth', 'api_token')
+        auth_token = env_or_param('SCALEWAY_TOKEN', param=auth_token)
+        if auth_token is None:
+            sys.stderr.write('ERROR: missing authentication token for Scaleway API')
+            sys.exit(1)
+
         if config.has_option('compute', 'regions'):
             regions = config.get('compute', 'regions')
             if regions == 'all':


Test patch:
Repository: ansible/ansible

Issue:
Ansible docs don't explain what "present" , "installed" etc mean 


##### ISSUE TYPE

 - Documentation Report

##### COMPONENT NAME
yum module

webdocs - http://docs.ansible.com/ansible/latest/yum_module.html

##### SUMMARY
The meaning and functionality of "present"  "installed" and other states are either not mentioned in the docs, or is hard to locate. Answers to questions in stackoverflow reveal the same https://stackoverflow.com/questions/40410270/what-is-the-difference-between-two-state-option-values-present-and-install

##### STEPS TO REPRODUCE
view http://docs.ansible.com/ansible/latest/yum_module.html

##### EXPECTED RESULTS
People should gather information about what the parameters mean from the docs
##### ACTUAL RESULTS
People resort to blog posts and stack overflow



Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py
--- a/lib/ansible/modules/packaging/os/yum.py
+++ b/lib/ansible/modules/packaging/os/yum.py
@@ -43,6 +43,9 @@
   state:
     description:
       - Whether to install (C(present) or C(installed), C(latest)), or remove (C(absent) or C(removed)) a package.
+      - C(present) and C(installed) will simply ensure that a desired package is installed.
+      - C(latest) will update the specified package if it's not of the latest available version.
+      - C(absent) and C(removed) will remove the specified package.
     choices: [ absent, installed, latest, present, removed ]
     default: present
   enablerepo:


Test patch: