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

Issue:
get_mount_facts does not work without lsblk
Gathering facts doesn't work without lsblk utility; ansible fails with message:

failed: [somehost] => {"cmd": "None -ln --output UUID /dev/sdb12", "failed": true, "rc": 257}



Discussion:
test the PR linked above and confirm that this fixes your issue


Resolving patch:
diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py
--- a/lib/ansible/module_utils/facts.py
+++ b/lib/ansible/module_utils/facts.py
@@ -885,13 +885,14 @@ def get_mount_facts(self):
                         size_available = statvfs_result.f_bsize * (statvfs_result.f_bavail)
                     except OSError, e:
                         continue
+
+                    uuid = 'NA'
                     lsblkPath = module.get_bin_path("lsblk")
-                    rc, out, err = module.run_command("%s -ln --output UUID %s" % (lsblkPath, fields[0]), use_unsafe_shell=True)
+                    if lsblkPath:
+                        rc, out, err = module.run_command("%s -ln --output UUID %s" % (lsblkPath, fields[0]), use_unsafe_shell=True)
 
-                    if rc == 0:
-                        uuid = out.strip()
-                    else:
-                        uuid = 'NA'
+                        if rc == 0:
+                            uuid = out.strip()
 
                     self.facts['mounts'].append(
                         {'mount': fields[1],


Test patch:
Repository: ansible/ansible

Issue:
Oracle Linux no longer detected as a Red Hat clone
##### Issue Type:

Bug Report
##### Ansible Version:

```
ansible 1.9.0.1
  configured module search path = None
```
##### Environment:

Oracle Linux Server release 7.1
##### Summary:

Oracle Linux is (mostly) built from the same SRPMs as Red Hat Enterprise Linux, so the `ansible_os_family` fact should be set to `RedHat`.  This used to work in Ansible 1.8.

I believe that this is a consequence of pull #10508.
##### Steps To Reproduce:

``` bash
ansible -m setup localhost | grep os_family
```
##### Expected Results:

```
        "ansible_os_family": "RedHat", 
```
##### Actual Results:

```
        "ansible_os_family": "Oracle Linux",
```



Discussion:
is this actually a bug? Like you said its mostly built from same SRPMs. And you can run the unbreakable kernel which is vastly different. I think current results are correct.

closing this as we do not consider it a bug but a work around Oracle misrepresentation.


Resolving patch:
diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py
--- a/lib/ansible/module_utils/facts.py
+++ b/lib/ansible/module_utils/facts.py
@@ -87,7 +87,7 @@ class Facts(object):
     _I386RE = re.compile(r'i([3456]86|86pc)')
     # For the most part, we assume that platform.dist() will tell the truth.
     # This is the fallback to handle unknowns or exceptions
-    OSDIST_LIST = ( ('/etc/oracle-release', 'Oracle Linux'),
+    OSDIST_LIST = ( ('/etc/oracle-release', 'OracleLinux'),
                     ('/etc/redhat-release', 'RedHat'),
                     ('/etc/vmware-release', 'VMwareESX'),
                     ('/etc/openwrt_release', 'OpenWrt'),
@@ -297,7 +297,7 @@ def get_distribution_facts(self):
                             # Once we determine the value is one of these distros
                             # we trust the values are always correct
                             break
-                        elif name == 'Oracle Linux':
+                        elif name == 'OracleLinux':
                             data = get_file_content(path)
                             if 'Oracle Linux' in data:
                                 self.facts['distribution'] = name


Test patch:
Repository: ansible/ansible

Issue:
stable-1.9 branch's ec2.py has an unbound error variable
This occurs in the stack trace below. Specifically, I consistently get it because a user I have does not have access to rds:DescribeDBInstances (which is a separate bug I might raise up).

```
~/ansible/plugins/inventory/ec2.py
Traceback (most recent call last):
  File "/home/jmhodges/ansible/plugins/inventory/ec2.py", line 802, in <module>
    Ec2Inventory()
  File "/home/jmhodges/ansible/plugins/inventory/ec2.py", line 156, in __init__
    self.do_api_calls_update_cache()
  File "/home/jmhodges/ansible/plugins/inventory/ec2.py", line 332, in do_api_calls_update_cache
    self.get_rds_instances_by_region(region)
  File "/home/jmhodges/ansible/plugins/inventory/ec2.py", line 389, in get_rds_instances_by_region
    self.fail_with_error(error)
UnboundLocalError: local variable 'error' referenced before assignment
```



Discussion:
Is it related to https://github.com/ansible/ansible/issues/10840 ?

In my case I had to edit ec2.ini and set

```
rds = False
```

So that the ec2.py script won't try to do anything with rds. My account wasn't signed up to Amazon RDS and this was causing the problem.

That's another problem I don't intend for this bug to address.

This was is just that anisible crashes without useful error messages because the "error" variable is unbound in some paths.


Resolving patch:
diff --git a/plugins/inventory/ec2.py b/plugins/inventory/ec2.py
--- a/plugins/inventory/ec2.py
+++ b/plugins/inventory/ec2.py
@@ -382,6 +382,7 @@ def get_rds_instances_by_region(self, region):
                 for instance in instances:
                     self.add_rds_instance(instance, region)
         except boto.exception.BotoServerError, e:
+            error = e.message
             if e.error_code == 'AuthFailure':
                 error = self.get_auth_error_message()
             if not e.reason == "Forbidden":


Test patch:
Repository: ansible/ansible

Issue:
Fact gathering gets a slightly unhelpful media type value on OS X, ending in a '>'
#### Issue Type:

Bug Report
##### Ansible Version:

charles-mba:ansible charles$ ansible --version
ansible 1.9.1
  configured module search path = None
##### Ansible Configuration:

No changes to the standard configuration.
##### Environment:

Running from OS X against OS X.
##### Summary:

When facts are obtained from an OS X system, the variable ansible_en0.media_type (and possibly other interfaces) is returned with a trailing '>' character.
##### Steps To Reproduce:
1. On OS X system: 'ansible -m setup -i hosts localhost | less'
2. find ansible_en0 in the displayed output.
##### Expected Results:

The 'media_type' field should be 'full-duplex', not 'full-duplex>'.

It looks like the output from 'networksetup -getmedia en0' isn't being truncated to report the trailing flags separator. For example:

```
osx:~ builduk$ networksetup -getmedia en0
Current: 1000baseT <full-duplex>
Active: 1000baseT <full-duplex>
```
##### Actual Results:

```
    "ansible_en0": {
        "device": "en0", 
        "flags": [
            "UP", 
            "BROADCAST", 
            "SMART", 
            "RUNNING", 
            "SIMPLEX", 
            "MULTICAST"
        ], 
        "ipv4": [
            {
                "address": "xxx", 
                "broadcast": "xxx", 
                "netmask": "xxx", 
                "network": "xxx"
            }
        ], 
        "ipv6": [
            {
                "address": "xxx%en0", 
                "prefix": "64", 
                "scope": "0x4"
            }
        ], 
        "macaddress": "xxx", 
        "media": "Unknown", 
        "media_select": "1000baseT", 
        "media_type": "full-duplex>", 
        "mtu": "1500", 
        "options": [
            "PERFORMNUD"
        ], 
        "status": "active", 
        "type": "unknown"
    }, 
```

(private informatin hidden with 'xxx')



Discussion:

Resolving patch:
diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py
--- a/lib/ansible/module_utils/facts.py
+++ b/lib/ansible/module_utils/facts.py
@@ -2163,7 +2163,7 @@ def parse_media_line(self, words, current_if, ips):
         current_if['media'] = 'Unknown' # Mac does not give us this
         current_if['media_select'] = words[1]
         if len(words) > 2:
-            current_if['media_type'] = words[2][1:]
+            current_if['media_type'] = words[2][1:-1]
         if len(words) > 3:
             current_if['media_options'] = self.get_options(words[3])
 


Test patch:
Repository: ansible/ansible

Issue:
Bug report: KeyError when trying to remove not existing entry
When running our playbook (that perfectly works with Ansible 1.6) in Ansible 1.9.1, we run into this issue: 

```
Traceback (most recent call last):
  File "/Users/bbru/Development/ansible/bin/ansible-playbook", line 324, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/Users/bbru/Development/ansible/bin/ansible-playbook", line 264, in main
    pb.run()
  File "/Users/bbru/Development/ansible/lib/ansible/playbook/__init__.py", line 310, in run
    play = Play(self, play_ds, play_basedir, vault_password=self.vault_password)
  File "/Users/bbru/Development/ansible/lib/ansible/playbook/play.py", line 194, in __init__
    self._tasks      = self._load_tasks(self._ds.get('tasks', []), load_vars)
  File "/Users/bbru/Development/ansible/lib/ansible/playbook/play.py", line 669, in _load_tasks
    loaded = self._load_tasks(data, mv, role_params, default_vars, included_become_vars, list(included_additional_conditions), original_file=include_filename, role_name=new_role)
  File "/Users/bbru/Development/ansible/lib/ansible/playbook/play.py", line 669, in _load_tasks
    loaded = self._load_tasks(data, mv, role_params, default_vars, included_become_vars, list(included_additional_conditions), original_file=include_filename, role_name=new_role)
  File "/Users/bbru/Development/ansible/lib/ansible/playbook/play.py", line 681, in _load_tasks
    role_name=role_name
  File "/Users/bbru/Development/ansible/lib/ansible/playbook/task.py", line 194, in __init__
    del ds['su']
KeyError: 'su'
```

It looks like that line 194 https://github.com/ansible/ansible/blob/f4172fb9daf27baaedd63d1f67ad072b2263d9e7/lib/ansible/playbook/task.py#L194 should be moved up to the if-block.



Discussion:

Resolving patch:
diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py
--- a/lib/ansible/playbook/task.py
+++ b/lib/ansible/playbook/task.py
@@ -189,9 +189,9 @@ def __init__(self, play, ds, module_vars=None, play_vars=None, play_file_vars=No
 
             if 'su' in ds:
                 self.become=ds['su']
+                del ds['su']
             else:
                 self.become=True
-                del ds['su']
             if 'su_user' in ds:
                 self.become_user = ds['su_user']
                 del ds['su_user']
@@ -260,7 +260,7 @@ def __init__(self, play, ds, module_vars=None, play_vars=None, play_file_vars=No
 
         self.items_lookup_plugin = ds.get('items_lookup_plugin', None)
         self.items_lookup_terms  = ds.get('items_lookup_terms', None)
-     
+
 
         self.ignore_errors = ds.get('ignore_errors', False)
         self.any_errors_fatal = ds.get('any_errors_fatal', play.any_errors_fatal)


Test patch:
Repository: ansible/ansible

Issue:
OSX media_type facts for bridge interface is wrong
##### Issue Type:

Bug Report
##### Ansible Version:

ansible --version
ansible 2.0.0
  configured module search path = /usr/share/ansible
</code>
##### Ansible Configuration:

None
##### Environment:

Management server: CentOS 6.6
Managed server: OSX
##### Summary:

Using setup module against an OSX computer, the media_type fact for the ansible_bridge0 interface shows as "ype>".
##### Steps To Reproduce:

1) From management server, run the ansible command using the setup module:
ansible mac -m setup
2) View the ansible_bridge0 fact in the output
##### Expected Results:

Based on the output of 'ifconfig -a' on the OSX machine
media: <unknown type>
So the fact should be set to:
"media_type": "unknown type"
##### Actual Results:

```
    "ansible_bridge0": {
        "device": "bridge0", 
        "flags": [
            "UP", 
            "BROADCAST", 
            "SMART", 
            "RUNNING", 
            "SIMPLEX", 
            "MULTICAST"
        ], 
        "ipv4": [], 
        "ipv6": [], 
        "macaddress": "xx:xx:xx:xx:xx:xx", 
        "media": "Unknown", 
        "media_select": "<unknown", 
        "media_type": "ype>", 
        "mtu": "1500", 
        "options": [
            "PERFORMNUD"
        ], 
        "status": "inactive", 
        "type": "unknown"
    }, 
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py
--- a/lib/ansible/module_utils/facts.py
+++ b/lib/ansible/module_utils/facts.py
@@ -2163,7 +2163,13 @@ def parse_media_line(self, words, current_if, ips):
         current_if['media'] = 'Unknown' # Mac does not give us this
         current_if['media_select'] = words[1]
         if len(words) > 2:
-            current_if['media_type'] = words[2][1:-1]
+            # MacOSX sets the media to '<unknown type>' for bridge interface
+            # and parsing splits this into two words; this if/else helps
+            if words[1] == '<unknown' and words[2] == 'type>':
+                current_if['media_select'] = 'Unknown'
+                current_if['media_type'] = 'unknown type'
+            else:
+                current_if['media_type'] = words[2][1:-1]
         if len(words) > 3:
             current_if['media_options'] = self.get_options(words[3])
 


Test patch:
Repository: ansible/ansible

Issue:
CLI become options are ultimately ignored
At this point I am not exactly sure where this is happening, however the become options provided on the CLI are ultimately ignored.

I have however determined that when `ConnectionInformation` is initiated, that the attributes are properly set via the 'set_options`method.  Immediately afterwards,`set_play`is executed and the options are set to`None`.

Commenting out the call to `set_play`, the attributes on `ConnectionInformation` remain correct, but by the time that `make_become_cmd` is executed, `self.become` has been set to `False`.

Other than `set_play` overwriting the variables when it probably shouldn't, I haven't been able to track down what else is setting `ConnectionInformation.become` to `False` before `make_become_cmd`.



Discussion:
I've made a small amount of progress.  It seems to stem from this line in the `Become` class:

```
_become              = FieldAttribute(isa='bool', default=False)
```

It appears as though this field is processed "late" and overrides an already Truthy value for `connection_info.become`.

I'm not super familiar with the new codebase yet, so I'm not sure where these `FieldAttribute`s are evaluated at.


Resolving patch:
diff --git a/lib/ansible/playbook/become.py b/lib/ansible/playbook/become.py
--- a/lib/ansible/playbook/become.py
+++ b/lib/ansible/playbook/become.py
@@ -27,7 +27,7 @@
 class Become:
 
     # Privlege escalation
-    _become              = FieldAttribute(isa='bool', default=False)
+    _become              = FieldAttribute(isa='bool')
     _become_method       = FieldAttribute(isa='string')
     _become_user         = FieldAttribute(isa='string')
     _become_pass         = FieldAttribute(isa='string')


Test patch:
Repository: ansible/ansible

Issue:
Looping of hosts in a group in a jinja2 template does not work in v2
Hi,

Have the following 
step-10/hosts

```
[web]
host1.example.org ansible_ssh_host=192.168.33.11 ansible_ssh_user=root
host2.example.org ansible_ssh_host=192.168.33.12 ansible_ssh_user=root

[haproxy]
host0.example.org ansible_ssh_host=192.168.33.10 ansible_ssh_user=root
```

step-10/haproxy.yml

```
- hosts: haproxy
  tasks:
    - name: Installs haproxy load balancer
      apt: pkg=haproxy state=installed update_cache=yes

    - name: Pushes configuration
      template: src=templates/haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg mode=0640 owner=root group=root
      notify:
        - restart haproxy

    - name: Sets default starting flag to 1
      lineinfile: dest=/etc/default/haproxy regexp="^ENABLED" line="ENABLED=1"
      notify:
        - restart haproxy 

  handlers:
    - name: restart haproxy
      service: name=haproxy state=restarted
```

Template 

```
global
    daemon
    maxconn 256

defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

listen cluster
    bind {{ ansible_eth1['ipv4']['address'] }}:80
    mode http
    stats enable
    balance roundrobin
{% for backend in groups['web'] %}
    server {{ hostvars[backend]['ansible_hostname'] }} {{ hostvars[backend]['ansible_eth1']['ipv4']['address'] }} check port 80
{% endfor %}
    option httpchk HEAD /index.php HTTP/1.0
```

Invoking the following 

```
ansible-playbook -i step-10/hosts  step-10/haproxy.yml

Error:

TASK [Pushes configuration] *****************************************************
fatal: [host0.example.org]: FAILED! => {"msg": "UndefinedError: 'list object' has no attribute 'web'", "failed": true, "changed": false}
```

Works in v1



Discussion:

Resolving patch:
diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py
--- a/lib/ansible/vars/__init__.py
+++ b/lib/ansible/vars/__init__.py
@@ -219,6 +219,7 @@ def get_vars(self, loader, play=None, host=None, task=None, use_cache=True):
             if self._inventory is not None:
                 hostvars = HostVars(vars_manager=self, inventory=self._inventory, loader=loader)
                 all_vars['hostvars'] = hostvars
+                all_vars['groups']   = self._inventory.groups_list()
 
         if task:
             if task._role:


Test patch:
Repository: ansible/ansible

Issue:
devel bug - profile_tasks.py requires CALLBACK_ constants or the display param is not passed
relates to #11625 and commit a09f623

```
$ ansible-playbook plays/test_to_json.yml -vvv
Using /Users/glynch/vagrant/ansible_foo/ansible.cfg as config file
1 plays in plays/test_to_json.yml
 [ERROR]: Unexpected Exception: __init__() takes exactly 2 arguments (1 given)

the full traceback was:

Traceback (most recent call last):
  File "/Users/glynch/dev/ansible/bin/ansible-playbook", line 77, in <module>
    sys.exit(cli.run())
  File "/Users/glynch/dev/ansible/lib/ansible/cli/playbook.py", line 162, in run
    results = pbex.run()
  File "/Users/glynch/dev/ansible/lib/ansible/executor/playbook_executor.py", line 128, in run
    self._tqm.load_callbacks()
  File "/Users/glynch/dev/ansible/lib/ansible/executor/task_queue_manager.py", line 154, in load_callbacks
    self._callback_plugins.append(callback_plugin())
TypeError: __init__() takes exactly 2 arguments (1 given)
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/plugins/callback/profile_tasks.py b/lib/ansible/plugins/callback/profile_tasks.py
--- a/lib/ansible/plugins/callback/profile_tasks.py
+++ b/lib/ansible/plugins/callback/profile_tasks.py
@@ -58,7 +58,14 @@ def tasktime():
 
 
 class CallbackModule(CallbackBase):
-
+    """
+    This callback module provides per-task timing, ongoing playbook elapsed time 
+    and ordered list of top 20 longest running tasks at end.
+    """
+    CALLBACK_VERSION = 2.0
+    CALLBACK_TYPE = 'aggregate'
+    CALLBACK_NAME = 'profile_tasks'
+ 
     def __init__(self, display):
         self.stats = {}
         self.current = None


Test patch:
Repository: ansible/ansible

Issue:
Encrypts the vault file after edition only if the contents changed
Whenever I edit a vault-protected file, it is re-encrypted even if I discard the changes or don't do any change, so git thinks that the file was actually modified. It forces me to git-checkout it to the previous version.

To avoid this issue I wrote this little patch.



Discussion:

Resolving patch:
diff --git a/lib/ansible/parsing/vault/__init__.py b/lib/ansible/parsing/vault/__init__.py
--- a/lib/ansible/parsing/vault/__init__.py
+++ b/lib/ansible/parsing/vault/__init__.py
@@ -227,6 +227,10 @@ def _edit_file_helper(self, existing_data=None, cipher=None):
         call(self._editor_shell_command(tmp_path))
         tmpdata = self.read_data(tmp_path)
 
+        # Do nothing if the content has not changed
+        if existing_data == tmpdata:
+            return
+
         # create new vault
         this_vault = VaultLib(self.password)
         if cipher:


Test patch:
Repository: ansible/ansible

Issue:
ansible play hangs on MacOSX
### Ansible Version:

```
ansible-playbook 2.0.0
  config file = /Users/shirou/tmp/ansible/ansible.cfg
  configured module search path = None
```

installed from 7eaacaf66e070106035227ea4bd2a13a41691426
### Ansible Configuration:

nothing special.
### Environment:
- Mac OS X (yosemite)
- Python 2.7.9
### Summary:

ansible-playbook command hangs up after this error.

```
Traceback (most recent call last):
  File "/Users/shirou/Works/VEnvs/ansiblev2/lib/python2.7/site-packages/ansible-2.0.0-py2.7.egg/ansible/executor/process/result.py", line 103, in run
    result = self._read_worker_result()
  File "/Users/shirou/Works/VEnvs/ansiblev2/lib/python2.7/site-packages/ansible-2.0.0-py2.7.egg/ansible/executor/process/result.py", line 75, in _read_worker_result
    if rslt_q.qsize() > 0:
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py", line 143, in qsize
    return self._maxsize - self._sem._semlock._get_value()
NotImplementedError

PLAY ***************************************************************************

TASK [debug msg=hangs] *********************************************************
```

I thinks because `Queue.qsize()` is not implemented at Mac OS X.
see https://github.com/python/cpython/blob/829b49cbd2e4b1d573470da79ca844b730120f3d/Lib/multiprocessing/queues.py#L116
### Steps To Reproduce:

run any playbook like

```
- hosts: all
  gather_facts: no
  connection: local
  tasks:
    - debug: msg="hangs"
```
### Expected Results:

play runs.
### Actual Results:

It seems play hang up.



Discussion:

Resolving patch:
diff --git a/lib/ansible/executor/process/result.py b/lib/ansible/executor/process/result.py
--- a/lib/ansible/executor/process/result.py
+++ b/lib/ansible/executor/process/result.py
@@ -72,7 +72,7 @@ def _read_worker_result(self):
                 self._cur_worker = 0
 
             try:
-                if rslt_q.qsize() > 0:
+                if not rslt_q.empty():
                     debug("worker %d has data to read" % self._cur_worker)
                     result = rslt_q.get()
                     debug("got a result from worker %d: %s" % (self._cur_worker, result))


Test patch: