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

Issue:
[v2] NameError: global name 'vars_copy' is not defined
**Ansible Version**

```
ansible 2.0.0 (devel 3d1255d190) last updated 2015/11/19 08:14:50 (GMT +300)
  lib/ansible/modules/core: (detached HEAD b1c0249045) last updated 2015/11/18 11:45:09 (GMT +300)
  lib/ansible/modules/extras: (detached HEAD 7da1f8d4ca) last updated 2015/11/18 11:45:09 (GMT +300)
```

**Summary**

My test playbook fails with this traceback:

```
TASK [common : generate locales] ***********************************************
task path: /home/mg/src/deployments/provisioning/roles/common/tasks/locales.yml:7
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/home/mg/src/ansible/lib/ansible/executor/process/worker.py", line 135, in run
    shared_loader_obj,
  File "/home/mg/src/ansible/lib/ansible/executor/task_executor.py", line 87, in run
    items = self._get_loop_items()
  File "/home/mg/src/ansible/lib/ansible/executor/task_executor.py", line 191, in _get_loop_items
    templar=templar).run(terms=loop_terms, variables=vars_copy)
NameError: global name 'vars_copy' is not defined

fatal: [precise]: FAILED! => {"failed": true, "stdout": ""}
```

The task in question looks like this:

``` yaml
- name: generate locales
  locale_gen: name={{ item }} state=present
  with_items:
    - en_US.UTF-8
    - lt_LT.UTF-8
  tags: locales
```



Discussion:
This bug was introduced in 3d1255d19009aa084fd2635917916fd9396ea898.

3d1255d19009aa084fd2635917916fd9396ea898 is the commit responsible.

("Fixes #13113, breaks #13213" :-)

```
$ pyflakes lib/ansible/executor/task_executor.py
lib/ansible/executor/task_executor.py:191: undefined name 'vars_copy'
lib/ansible/executor/task_executor.py:611: local variable 'res' is assigned to but never used
```


Resolving patch:
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py
--- a/lib/ansible/executor/task_executor.py
+++ b/lib/ansible/executor/task_executor.py
@@ -188,7 +188,7 @@ def _get_loop_items(self):
                         else:
                             raise
                 items = self._shared_loader_obj.lookup_loader.get(self._task.loop, loader=self._loader,
-                        templar=templar).run(terms=loop_terms, variables=vars_copy)
+                        templar=templar).run(terms=loop_terms, variables=self._job_vars)
             else:
                 raise AnsibleError("Unexpected failure in finding the lookup named '%s' in the available lookup plugins" % self._task.loop)
 


Test patch:
Repository: ansible/ansible

Issue:
host_vars do not get fully loaded when using 'inventory' directory and --limit
##### Issue Type:
- Bug Report
- Bugfix Pull Request
##### Ansible Version:
- 1.9.4
##### Ansible Configuration:

```
[defaults]
inventory=inventory
```
##### Environment:

```
./inventory/g
./host_vars/h1
./host_vars/h2
./playbook.yml
```
##### Summary:

host_vars are not loaded when using inventory directory and --limit flag
##### Steps To Reproduce:

```
#./inventory/g
h1
h2
```

```
#./host_vars/h1

---
key: h1
```

```
#./host_vars/h2

---
key: h2
```

```
#./playbook.yml

---

- name: test host_vars includes
  gather_facts: no
  hosts: all
  tasks:
    - debug: var=hostvars['h1'].key
    - debug: var=hostvars['h2'].key
```

```
ansible-playbook playbook.yml -l h1
```
##### Expected Results:

```
PLAY [test host_vars includes] ************************************************

TASK: [debug var=hostvars['h1'].key] ******************************************
ok: [h1] => {
    "var": {
        "hostvars['h1'].key": "h1"
    }
}

TASK: [debug var=hostvars['h2'].key] ******************************************
ok: [h1] => {
    "var": {
        "hostvars['h2'].key": "h2"
    }
}

PLAY RECAP ********************************************************************
h1                         : ok=2    changed=0    unreachable=0    failed=0
```
##### Actual Results:

```
PLAY [test host_vars includes] ************************************************

TASK: [debug var=hostvars['h1'].key] ******************************************
ok: [h1] => {
    "var": {
        "hostvars['h1'].key": "h1"
    }
}

TASK: [debug var=hostvars['h2'].key] ******************************************
ok: [h1] => {
    "var": {
        "hostvars['h2'].key": "{{hostvars['h2'].key}}"
    }
}

PLAY RECAP ********************************************************************
h1                         : ok=2    changed=0    unreachable=0    failed=0
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py
--- a/lib/ansible/inventory/__init__.py
+++ b/lib/ansible/inventory/__init__.py
@@ -559,11 +559,20 @@ def is_file(self):
             return False
         return os.path.exists(self.host_list)
 
+    def is_dir(self):
+        """ did inventory come from a directory? """
+        if not isinstance(self.host_list, basestring):
+            return False
+        return os.path.isdir(self.host_list)
+
     def basedir(self):
         """ if inventory came from a file, what's the directory? """
         if not self.is_file():
             return None
-        dname = os.path.dirname(self.host_list)
+        if self.is_dir():
+            dname = os.path.dirname(os.path.dirname(self.host_list))
+        else:
+            dname = os.path.dirname(self.host_list)
         if dname is None or dname == '' or dname == '.':
             cwd = os.getcwd()
             return os.path.abspath(cwd) 


Test patch:
Repository: ansible/ansible

Issue:
Can't get python traceback from exception thrown in callback plugin
As part of #13712 , I was trying to track down the source of a python exception in the `default.py` stdout callback plugin. Unfortunately, this effort was hindered by the apparent inability to get more than the exception and the file that it came from (no line number or traceback). Even when running with `-vvv`, this is the most I could get (which is exactly what I get without any `-v` option):

```
 [WARNING]: Error when using <bound method CallbackModule.v2_on_file_diff of </home/agaffney/dev/ansible/lib/ansible/plugins/callback/default.CallbackModule object at
0x760c34f0>>: 'TaskResult' object has no attribute 'get'
```



Discussion:
check if PR above fixes this for you.


Resolving patch:
diff --git a/lib/ansible/executor/task_queue_manager.py b/lib/ansible/executor/task_queue_manager.py
--- a/lib/ansible/executor/task_queue_manager.py
+++ b/lib/ansible/executor/task_queue_manager.py
@@ -290,8 +290,13 @@ def send_callback(self, method_name, *args, **kwargs):
                     try:
                         method(*args, **kwargs)
                     except Exception as e:
+                        import traceback
+                        orig_tb = traceback.format_exc()
                         try:
                             v1_method = method.replace('v2_','')
                             v1_method(*args, **kwargs)
                         except Exception:
-                            display.warning('Error when using %s: %s' % (method, str(e)))
+                            if display.verbosity >= 3:
+                                display.warning(orig_tb, formatted=True)
+                            else:
+                                display.warning('Error when using %s: %s' % (method, str(e)))
diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py
--- a/lib/ansible/utils/display.py
+++ b/lib/ansible/utils/display.py
@@ -202,10 +202,15 @@ def deprecated(self, msg, version=None, removed=False):
             self.display(new_msg.strip(), color=C.COLOR_DEPRECATE, stderr=True)
             self._deprecations[new_msg] = 1
 
-    def warning(self, msg):
-        new_msg = "\n[WARNING]: %s" % msg
-        wrapped = textwrap.wrap(new_msg, self.columns)
-        new_msg = "\n".join(wrapped) + "\n"
+    def warning(self, msg, formatted=False):
+
+        if not formatted:
+            new_msg = "\n[WARNING]: %s" % msg
+            wrapped = textwrap.wrap(new_msg, self.columns)
+            new_msg = "\n".join(wrapped) + "\n"
+        else:
+            new_msg = "\n[WARNING]: \n%s" % msg
+
         if new_msg not in self._warns:
             self.display(new_msg, color=C.COLOR_WARN, stderr=True)
             self._warns[new_msg] = 1


Test patch:
Repository: ansible/ansible

Issue:
Allow to display play arguments during run
##### Issue Type: Feature Idea
##### Ansible Version: ansible 2.0.0.2
##### Ansible Configuration:
##### Environment: N/A
##### Summary: It would be useful to be able to configure Ansible to display play arguments while running.
##### Steps To Reproduce: Run a playbook with plays that don't have a name:
##### Expected Results:

It would be great to get the pre-2.0 behaviour with output like "TASK [service name=httpd state=started]".
This should probably be a config option because it was disabled due to security considerations (since the argument-spec no_log isn't available at this point).
##### Actual Results:

Output like "TASK [service]".



Discussion:

Resolving patch:
diff --git a/lib/ansible/plugins/callback/default.py b/lib/ansible/plugins/callback/default.py
--- a/lib/ansible/plugins/callback/default.py
+++ b/lib/ansible/plugins/callback/default.py
@@ -113,7 +113,19 @@ def v2_playbook_on_no_hosts_remaining(self):
         self._display.banner("NO MORE HOSTS LEFT")
 
     def v2_playbook_on_task_start(self, task, is_conditional):
-        self._display.banner("TASK [%s]" % task.get_name().strip())
+        args = ''
+        # args can be specified as no_log in several places: in the task or in
+        # the argument spec.  We can check whether the task is no_log but the
+        # argument spec can't be because that is only run on the target
+        # machine and we haven't run it thereyet at this time.
+        #
+        # So we give people a config option to affect display of the args so
+        # that they can secure this if they feel that their stdout is insecure
+        # (shoulder surfing, logging stdout straight to a file, etc).
+        if not task.no_log and C.DISPLAY_ARGS_TO_STDOUT:
+            args = ', '.join(('%s=%s' % a for a in task.args.items()))
+            args = ' %s' % args
+        self._display.banner("TASK [%s%s]" % (task.get_name().strip(), args))
         if self._display.verbosity > 2:
             path = task.get_path()
             if path:


Test patch:
Repository: ansible/ansible

Issue:
ansible-galaxy init creates file with trailing whitespace
##### Issue Type:

<!--- Please pick one and delete the rest: -->
- Bug Report
##### Ansible Version:

```
ansible 2.0.1.0
  config file = 
  configured module search path = Default w/o overrides

```
##### Ansible Configuration:

None
##### Environment:

N/A
##### Summary:

When creating a default empty role using `ansible-galaxy init rolename` the resulting `meta/main.yml` file contains trailing whitespace that fails `ansible-lint` testing. 
##### Steps To Reproduce:

```
pip install ansible-lint
ansible-galaxy init testrole
ansible-lint testrole/meta/main.yml
```
##### Expected Results:

Expect to have a file without trailing whitespace.
##### Actual Results:

```
[ANSIBLE0002] Trailing whitespace
/home/ubuntu/CloudFormations/roles/MicrosoftAD/meta/main.yml:3
  description: 

[ANSIBLE0002] Trailing whitespace
/home/ubuntu/CloudFormations/roles/MicrosoftAD/meta/main.yml:5


[ANSIBLE0002] Trailing whitespace
/home/ubuntu/CloudFormations/roles/MicrosoftAD/meta/main.yml:9


[ANSIBLE0002] Trailing whitespace
/home/ubuntu/CloudFormations/roles/MicrosoftAD/meta/main.yml:18


[ANSIBLE0002] Trailing whitespace
/home/ubuntu/CloudFormations/roles/MicrosoftAD/meta/main.yml:28


[ANSIBLE0002] Trailing whitespace
/home/ubuntu/CloudFormations/roles/MicrosoftAD/meta/main.yml:157
```



Discussion:
ansible-lint is not an official spec nor project

I agree. I do think having trailing whitespace in the default `ansible-galaxy init` is a bad thing and falls under the ansible project.

If you point me in the direction of the skeleton for the `ansible-galaxy init` command I'll happily submit a PR resolving this. @bcoca 

https://github.com/ansible/ansible/search?utf8=✓&q=execute_init&type=Code

So I followed the rabbit hole down to https://github.com/ansible/ansible/blob/06fa841516fadf4454d8aa05609786a7b9f14b3b/lib/ansible/galaxy/__init__.py#L66 and I can't seem to find the `metadata_template.j2` Jinja2 template. The extra whitespace is most likely in that template based on the code so far.

Does anyone know where that is? A search of this repository didn't return any file by that name.

Scratch that. Searching on GitHub is flaky I guess.
https://github.com/ansible/ansible/blob/06fa841516fadf4454d8aa05609786a7b9f14b3b/lib/ansible/galaxy/data/metadata_template.j2


Resolving patch:
diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py
--- a/lib/ansible/cli/galaxy.py
+++ b/lib/ansible/cli/galaxy.py
@@ -251,6 +251,7 @@ def execute_init(self):
 
                 inject = dict(
                     author = 'your name',
+                    description = 'your description',
                     company = 'your company (optional)',
                     license = 'license (GPLv2, CC-BY, etc)',
                     issue_tracker_url = 'http://example.com/issue/tracker',


Test patch:
Repository: ansible/ansible

Issue:
Update packaging/arch/PKGBUILD
Uploaded new version to AUR and bumped version.



Discussion:
I am not an arch user, but can you help me understand why you bumped the version _down_ ?

In fact the version is bumped up (20130109 -> 20130123), so the package version got reseted down to 1.
It was set to 2 because I probably messed up or forgot something in the first package file for the 20130109 version.

Works for me, thanks!


Resolving patch:
diff --git a/lib/ansible/module_utils/ec2.py b/lib/ansible/module_utils/ec2.py
--- a/lib/ansible/module_utils/ec2.py
+++ b/lib/ansible/module_utils/ec2.py
@@ -85,10 +85,6 @@ def ec2_argument_spec():
     return spec
 
 
-def boto_supports_profile_name():
-    return hasattr(boto.ec2.EC2Connection, 'profile_name')
-
-
 def get_aws_connection_info(module, boto3=False):
 
     # Check module args for credentials, then check environment vars
@@ -172,15 +168,11 @@ def get_aws_connection_info(module, boto3=False):
                            aws_secret_access_key=secret_key,
                            security_token=security_token)
 
-        # profile_name only works as a key in boto >= 2.24
-        # so only set profile_name if passed as an argument
+        # only set profile_name if passed as an argument
         if profile_name:
-            if not boto_supports_profile_name():
-                module.fail_json("boto does not support profile_name before 2.24")
             boto_params['profile_name'] = profile_name
 
-        if HAS_LOOSE_VERSION and LooseVersion(boto.Version) >= LooseVersion("2.6.0"):
-            boto_params['validate_certs'] = validate_certs
+        boto_params['validate_certs'] = validate_certs
 
     for param, value in boto_params.items():
         if isinstance(value, str):


Test patch:
Repository: ansible/ansible

Issue:
incomplete docstring in ansible.executor.task_executor.TaskExecutor
##### Issue Type:
- Documentation Report
##### Ansible Version:

```
2.1.0
```
##### Summary:

The docstring of the run method in ansible.executor.task_executor.TaskExecutor is incomplete:

```
    def run(self):
        '''
        The main executor entrypoint, where we determine if the specified
        task requires looping and either runs the task with
        '''
```



Discussion:
As far as I can see, there are two ways to run a task in the above `run` method, either we have a list of items and we should run the task using `self._run_loops`, which in turn call `self._execute`, or, we just run the task directly using `self._execute`. Hope this helps.

The source code is [here](https://github.com/ansible/ansible/blob/devel/lib/ansible/executor/task_executor.py#L75). I did some check, it has been here since the v2 switch in ce3ef7f


Resolving patch:
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py
--- a/lib/ansible/executor/task_executor.py
+++ b/lib/ansible/executor/task_executor.py
@@ -75,7 +75,9 @@ def __init__(self, host, task, job_vars, play_context, new_stdin, loader, shared
     def run(self):
         '''
         The main executor entrypoint, where we determine if the specified
-        task requires looping and either runs the task with
+        task requires looping and either runs the task with self._run_loop()
+        or self._execute(). After that, the returned results are parsed and
+        returned as a dict.
         '''
 
         display.debug("in run()")


Test patch:
Repository: ansible/ansible

Issue:
net_template.py: j2 include search path issue
##### ISSUE TYPE
- Bug Report
##### ANSIBLE VERSION

```
air$ ansible-playbook --version
ansible-playbook 2.1.0
  config file =
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

```
ops_template:
  src: main.j2
```

and here is the sample main.j2

```
{% include [ 'included.j2' ] %}
```

You can also take a look at the actual [OpenSwitch switch role](https://github.com/keinohguchi/ops-switch-role).
##### OS / ENVIRONMENT

Tested on ArchLinux
##### SUMMARY

net_template.py doesn't prepare the J2 search path, which prevents `include` statement inside j2 file.
##### STEPS TO REPRODUCE

ansible-playbook [site.yaml](https://github.com/keinohguchi/dc-on-docker/blob/master/site.yaml)
##### EXPECTED RESULTS

Parse the j2 file, which locates under role's template directory.
##### ACTUAL RESULTS

net_template.py can't find the internal j2 files.



Discussion:

Resolving patch:
diff --git a/lib/ansible/plugins/action/net_template.py b/lib/ansible/plugins/action/net_template.py
--- a/lib/ansible/plugins/action/net_template.py
+++ b/lib/ansible/plugins/action/net_template.py
@@ -93,6 +93,17 @@ def _handle_template(self):
         except IOError:
             return dict(failed=True, msg='unable to load src file')
 
+        # Create a template search path in the following order:
+        # [working_path, self_role_path, dependent_role_paths, dirname(source)]
+        searchpath = [working_path]
+        if self._task._role is not None:
+            searchpath.append(self._task._role._role_path)
+            dep_chain = self._task._block.get_dep_chain()
+            if dep_chain is not None:
+                for role in dep_chain:
+                    searchpath.append(role._role_path)
+        searchpath.append(os.path.dirname(source))
+        self._templar.environment.loader.searchpath = searchpath
         self._task.args['src'] = self._templar.template(template_data)
 
 


Test patch:
Repository: ansible/ansible

Issue:
Synchronize does not use playbook directory in 2.1
##### Issue Type:

<!--- Please pick one and delete the rest: -->
- Bug Report
##### Ansible Version:

```
ansible 2.1.0
```
##### Summary:

I have been using synchronize the following way (update-config.yml):

```
synchronize:
      src: config/
      dest: /directory/config
      delete: yes
      recursive: yes
```

and called the playbook with

```
ansible-playbook directory/update-config.yml
```

This worked fine in ansible 1.9.2, but in 2.1, it tries to resolve config/ from the directory I am in, not the directory the playbook is in, meaning it looks for `config/` instead of `directory/config/` and does not find anything (or in other scenarios it might just find the wrong stuff).



Discussion:
Can you verify this is an issue in 2.0 here to pinpoint the issue? There's a lot of changes to this module and action plugin between 1.9.2 and devel, the in-progress work towards v2.1. 

I did a `git clone git://github.com/ansible/ansible.git --recursive` 2 days ago, before I reported the issue, so it should be the absolutely newest version.

It should also be easy to reproduce. If you need any more information or if there is anything to test, I will happily try it out.

I believe this was an intentional change that happened globally because current working directory is insecure.  If you are in /var/tmp when you run the playbook, another user could have put a different config file into place.

@bcoca could you let me know if my supposition above is correct?  Or should synchronize be looking for those files in the current working directory?

bcoca pointed out that I misread the report.  It's now looking in the cwd instead of in the playbook basedir and so it's now wrong.  Taking a look.


Resolving patch:
diff --git a/lib/ansible/plugins/action/synchronize.py b/lib/ansible/plugins/action/synchronize.py
--- a/lib/ansible/plugins/action/synchronize.py
+++ b/lib/ansible/plugins/action/synchronize.py
@@ -30,18 +30,17 @@
 class ActionModule(ActionBase):
 
     def _get_absolute_path(self, path):
-        if self._task._role is not None:
-            original_path = path
+        original_path = path
 
-            if self._task._role is not None:
-                path = self._loader.path_dwim_relative(self._task._role._role_path, 'files', path)
-            else:
-                path = self._loader.path_dwim_relative(self._loader.get_basedir(), 'files', path)
+        if self._task._role is not None:
+            path = self._loader.path_dwim_relative(self._task._role._role_path, 'files', path)
+        else:
+            path = self._loader.path_dwim_relative(self._loader.get_basedir(), 'files', path)
 
-            if original_path and original_path[-1] == '/' and path[-1] != '/':
-                # make sure the dwim'd path ends in a trailing "/"
-                # if the original path did
-                path += '/'
+        if original_path and original_path[-1] == '/' and path[-1] != '/':
+            # make sure the dwim'd path ends in a trailing "/"
+            # if the original path did
+            path += '/'
 
         return path
 


Test patch: