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

Issue:
Tags in array cause traceback
##### Issue Type:

Bug Report
##### Ansible Version:

ansible 1.6
##### Environment:

Debian Wheezy
##### Summary:

Bug seems similar to https://github.com/ansible/ansible/issues/4524
##### Steps To Reproduce:
##### Expected Results:
##### Actual Results:

```
Traceback (most recent call last):
  File "/usr/bin/ansible-playbook", line 307, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/usr/bin/ansible-playbook", line 247, in main
    pb.run()
  File "/usr/lib/pymodules/python2.7/ansible/playbook/__init__.py", line 248, in run
    play = Play(self, play_ds, play_basedir, included_roles=included_roles, vault_password=self.vault_password)
  File "/usr/lib/pymodules/python2.7/ansible/playbook/play.py", line 85, in __init__
    ds = self._load_roles(self.roles, ds)
  File "/usr/lib/pymodules/python2.7/ansible/playbook/play.py", line 358, in _load_roles
    roles = self._build_role_dependencies(roles, [], self.vars)
  File "/usr/lib/pymodules/python2.7/ansible/playbook/play.py", line 307, in _build_role_dependencies
    self._build_role_dependencies([dep], dep_stack, passed_vars=dep_vars, level=level+1)
  File "/usr/lib/pymodules/python2.7/ansible/playbook/play.py", line 241, in _build_role_dependencies
    passed_vars['tags'] = __merge_tags(role_vars)
  File "/usr/lib/pymodules/python2.7/ansible/playbook/play.py", line 239, in __merge_tags
    return list(set(old_tags + new_tags))
TypeError: cannot concatenate 'str' and 'list' objects
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py
--- a/lib/ansible/playbook/play.py
+++ b/lib/ansible/playbook/play.py
@@ -236,7 +236,7 @@ def __merge_tags(var_obj):
                             new_tags = var_obj.get('tags', [])
                             if isinstance(new_tags, basestring):
                                 new_tags = [new_tags, ]
-                            return list(set(old_tags + new_tags))
+                            return list(set(old_tags).union(set(new_tags)))
 
                         passed_vars['tags'] = __merge_tags(role_vars)
                         passed_vars['tags'] = __merge_tags(dep_vars)
@@ -249,7 +249,7 @@ def __merge_tags(var_obj):
                                 included_dep_vars = included_role_dep[2]
                                 if included_dep_name == dep:
                                     if "tags" in included_dep_vars:
-                                        included_dep_vars["tags"] = list(set(included_dep_vars["tags"] + passed_vars["tags"]))
+                                        included_dep_vars["tags"] = list(set(included_dep_vars["tags"]).union(set(passed_vars["tags"])))
                                     else:
                                         included_dep_vars["tags"] = passed_vars["tags"][:]
 


Test patch:
Repository: ansible/ansible

Issue:
Space in one variable breaks others
##### Issue Type:

Bug Report
##### Ansible Version:

ansible 1.5
##### Environment:

Arch Linux managing Centos 6
##### Summary:

When I accidentally use a space instead of an underscore, all the variables in the command are ignored and each character is treated literally.
##### Steps To Reproduce:

``` YAML

---

- hosts: all
  vars:
    - test: "test1"
    - test_var: "test2"

  tasks:
    - command: echo {{ test }}{{ test var }}
```
##### Expected Results:

I think there are two possible results that could improve things:
1. The play errors out, explaining that there should not be spaces in variables
2. The play continues and evaluates all but the mucked up variable correctly. Something like this: `TASK: [command echo test{{test var}}]`

Either way would make it easy for me to see the problem. As it is, it took me a while to notice what the problem was (mostly because the line was on the last line of the editor so it wasn't easy to see that it was a space instead of an underscore).
##### Actual Results:

``` bash
[default] Running provisioner: ansible...

PLAY [vagrant] **************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [192.168.111.222]

TASK: [command echo {{test}}{{test var}}] ************************************* 
changed: [192.168.111.222]

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



Discussion:

Resolving patch:
diff --git a/lib/ansible/utils/template.py b/lib/ansible/utils/template.py
--- a/lib/ansible/utils/template.py
+++ b/lib/ansible/utils/template.py
@@ -316,6 +316,8 @@ def my_finalize(thing):
         except Exception, e:
             if 'recursion' in str(e):
                 raise errors.AnsibleError("recursive loop detected in template string: %s" % data)
+            elif isinstance(e, TemplateSyntaxError):
+                raise errors.AnsibleError("there was an error in the template: %s" % data)
             else:
                 return data
 


Test patch:
Repository: ansible/ansible

Issue:
want to be able to use a variable for the value of ignore_errors
AFAICT it's impossible to use a **variable** for _ignore_errors_ 
### Given

```
vars:
    ignore_err: no
```
### Solution Attempts

Interpreted as a string, so always true:

```
ignore_errors: $ignore_err
```

Dito:

```
ignore_errors: {{ ignore_err }}
```

Illegal YAML syntax:

```
ignore_errors: {{ ignore_err | bool }}
```

String again...:

```
ignore_errors: "{{ ignore_err | bool }}"
```

Maybe I'm stupid, but I can't see how to do this. I had to duplicate the task with one ignore_errors: yes and one no and control it with a when...



Discussion:
This is probably just because this variable is not being templated, which is a pretty easy thing to add.


Resolving patch:
diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py
--- a/lib/ansible/playbook/__init__.py
+++ b/lib/ansible/playbook/__init__.py
@@ -402,6 +402,10 @@ def _run_task(self, play, task, is_handler):
             ansible.callbacks.set_task(self.runner_callbacks, None)
             return True
 
+        # template ignore_errors
+        cond = template(play.basedir, task.ignore_errors, task.module_vars, expand_lists=False)
+        task.ignore_errors =  utils.check_conditional(cond , play.basedir, task.module_vars, fail_on_undefined=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR)
+
         # load up an appropriate ansible runner to run the task in parallel
         results = self._run_task_internal(task)
 


Test patch:
Repository: ansible/ansible

Issue:
role_name variable
It would be nice to be able test against roles as variables.  I would like to have a template where I can test against what roles a particular playbook is including.

Particularly in the iptables space. Being able to say open ports 80,443 because I included httpd role. Or any other grouping of ports based on inclusion of a role would be awesome.



Discussion:
Proposal would be add a "role_names" array that works like group_names.

+1 `role_names` would be perfect for the exact reasons mentioned.

+1 `role_names` would also be useful with configuring monitoring.

+1, it'll be very helpful. 

I have a hunch this may lead to tightly coupled roles, especially the usage with Galaxy roles may be problematic. On the other hand, this is probably the most obvious way how to keep roles generic enough for more heterogenous infrastructure—the custom written roles, that is.
:+1:


Resolving patch:
diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py
--- a/lib/ansible/playbook/play.py
+++ b/lib/ansible/playbook/play.py
@@ -134,6 +134,7 @@ def __init__(self, playbook, ds, basedir, vault_password=None):
                                       '("su", "su_user") cannot be used together')
 
         load_vars = {}
+        load_vars['role_names'] = ds.get('role_names',[])
         load_vars['playbook_dir'] = self.basedir
         if self.playbook.inventory.basedir() is not None:
             load_vars['inventory_dir'] = self.playbook.inventory.basedir()
@@ -356,6 +357,7 @@ def _load_roles(self, roles, ds):
         new_tasks.append(dict(meta='flush_handlers'))
 
         roles = self._build_role_dependencies(roles, [], self.vars)
+        role_names = []
 
         for (role,role_path,role_vars,default_vars) in roles:
             # special vars must be extracted from the dict to the included tasks
@@ -388,6 +390,7 @@ def _load_roles(self, roles, ds):
             else:
                 role_name = role
 
+            role_names.append(role_name)
             if os.path.isfile(task):
                 nt = dict(include=pipes.quote(task), vars=role_vars, default_vars=default_vars, role_name=role_name)
                 for k in special_keys:
@@ -434,6 +437,7 @@ def _load_roles(self, roles, ds):
         ds['tasks'] = new_tasks
         ds['handlers'] = new_handlers
         ds['vars_files'] = new_vars_files
+        ds['role_names'] = role_names
 
         self.default_vars = self._load_role_defaults(defaults_files)
 


Test patch:
Repository: ansible/ansible

Issue:
Modules that accept hostkeys do not create $HOME/.ssh
##### Issue Type:

Bug Report / Feature Idea
##### Ansible Version:

ansible-1.5.3 (and ansible devel)
##### Environment:

RHEL-6.4, RHEL-6.5, Centos-6.4, Ubuntu-12.04, Ubuntu-14.04.
##### Summary:

When performing a git clone, using ssh credentials, the clone will fail if performed by a new user who does not have a $HOME/.ssh directory.  Should modules that accept hostkeys (e.g. `git`) also be responsible for creating `$HOME/.ssh`?
##### Steps To Reproduce:
1. Create a new user account

```
# useradd -p '' -m some_user
```
1. As recently created user, clone a git repository

```
# sudo su - some_user
# ansible all -i local, -c local -m git -a 'dest=/tmp/my_project  repo="git@github.com:ansible/ansible-examples.git" accept_hostkey=true'
```
##### Expected Results:

```
local | success >> {
    "after": "38b327ecff3cff6c2530e44d4b888d7ee0c3b3f7", 
    "before": null, 
    "changed": true
}
```
##### Actual Results:

```
local | FAILED >> {
    "failed": true, 
    "msg": "/home/some_user/.ssh/ does not exist"
}
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/module_utils/known_hosts.py b/lib/ansible/module_utils/known_hosts.py
--- a/lib/ansible/module_utils/known_hosts.py
+++ b/lib/ansible/module_utils/known_hosts.py
@@ -30,7 +30,7 @@
 from hashlib import sha1
 HASHED_KEY_MAGIC = "|1|"
 
-def add_git_host_key(module, url, accept_hostkey=True):
+def add_git_host_key(module, url, accept_hostkey=True, create_dir=True):
 
     """ idempotently add a git url hostkey """
 
@@ -40,7 +40,7 @@ def add_git_host_key(module, url, accept_hostkey=True):
         known_host = check_hostkey(module, fqdn)
         if not known_host:
             if accept_hostkey:
-                rc, out, err = add_host_key(module, fqdn)
+                rc, out, err = add_host_key(module, fqdn, create_dir=create_dir)
                 if rc != 0:
                     module.fail_json(msg="failed to add %s hostkey: %s" % (fqdn, out + err))
             else:
@@ -120,7 +120,7 @@ def not_in_host_file(self, host):
     return True
 
 
-def add_host_key(module, fqdn, key_type="rsa"):
+def add_host_key(module, fqdn, key_type="rsa", create_dir=False):
 
     """ use ssh-keyscan to add the hostkey """
 
@@ -136,7 +136,15 @@ def add_host_key(module, fqdn, key_type="rsa"):
     user_ssh_dir = os.path.expanduser(user_ssh_dir)
 
     if not os.path.exists(user_ssh_dir):
-        module.fail_json(msg="%s does not exist" % user_ssh_dir)
+        if create_dir:
+            try:
+                os.makedirs(user_ssh_dir, 0700)
+            except:
+                module.fail_json(msg="failed to create host key directory: %s" % user_ssh_dir)
+        else:
+            module.fail_json(msg="%s does not exist" % user_ssh_dir)
+    elif not os.path.isdir(user_ssh_dir):
+        module.fail_json(msg="%s is not a directory" % user_ssh_dir)
 
     this_cmd = "%s -t %s %s" % (keyscan_cmd, key_type, fqdn)
 


Test patch:
Repository: ansible/ansible

Issue:
Missing default in vars_prompt when default is False or no
##### Issue Type:

Bug Report
##### Ansible Version:

ansible 1.6 (devel 632eb18333) last updated 2014/04/18 11:44:32 (GMT -700)
##### Environment:

Mac OSX 10.9.2
##### Summary:

If you put a default value in a vars_prompt of False, you will not get a default value.

See discussion here:  [https://groups.google.com/d/msg/ansible-project/oc1_zE-FnyI/ppZ-Zeq_r5EJ]
##### Steps To Reproduce:

Use this playbook:

```

---
- name: Default values of prompts
  hosts: localhost
  gather_facts: no
  vars_prompt:
    - name: yes_val_from_prompt
      prompt: Test for boolean value - enter yes or no
      default: yes
      private: no
    # Bug?  Why does the default value not get printed?
    - name: no_val_from_prompt
      prompt: Test for boolean value - enter yes or no
      default: no
      private: no
    - name: yes_string_val_from_prompt
      prompt: Test for boolean value - enter yes or no
      default: "yes"
      private: no
    # Bug?  Why does the default value not get printed?
    - name: no_string_val_from_prompt
      prompt: Test for boolean value - enter yes or no
      default: "no"
      private: no
  tasks:
    - debug: var=yes_val_from_prompt
    - debug: var=no_val_from_prompt
    - debug: var=yes_string_val_from_prompt
    - debug: var=no_string_val_from_prompt
```
##### Expected Results:

```
Test for boolean value - enter yes or no [True]:  
Test for boolean value - enter yes or no: [False]:
Test for boolean value - enter yes or no [yes]:  
Test for boolean value - enter yes or no [no]:  
```
##### Actual Results:

```
Test for boolean value - enter yes or no [True]:  
Test for boolean value - enter yes or no:      <======= Missing default
Test for boolean value - enter yes or no [yes]:  
Test for boolean value - enter yes or no [no]:  
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.py
--- a/lib/ansible/callbacks.py
+++ b/lib/ansible/callbacks.py
@@ -643,7 +643,7 @@ def on_task_start(self, name, is_conditional):
 
     def on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None):
 
-        if prompt and default:
+        if prompt and default is not None:
             msg = "%s [%s]: " % (prompt, default)
         elif prompt:
             msg = "%s: " % prompt


Test patch:
Repository: ansible/ansible

Issue:
Not getting proper mtu on FreeBSD 10
##### Issue Type: Bug Report
##### Ansible Version: ansible 1.4.4
##### Environment: Running from OS X 10.8 (via home-brew) to FreeBSD 10.0-RELEASE
##### Summary:

setup module not picking up proper mtu from FreeBSD ifconfig
##### Steps To Reproduce:
1. Run 'setup' module against FreeBSD 10.0-RELEASE machine
2. Look at ansible_lo0.mtu or any other interface
3. Compare to ifconfig output for the selected interface. See difference.
##### Expected Results:

ansible_vmx0.mtu should equal tue actual mtu from ifconfig
##### Actual Results:

ansible_<iface>.mtu == 0



Discussion:
This also shows broken on devel(1.5) for both FreeBSD 9 and 10.

so this currently  uses a generic function for BSDs, parses the text output from "ifconfig -a" and takes the 4rd word as mtu.

```
rc, out, err = module.run_command([ifconfig_path, '-a'])
for line in out.split('\n'):
    words = line.split()

....

 current_if['mtu'] = words[3]
```

Has this changed since FreeBSD 8? (I used to run 8 and this worked)  I don't currently have any FreeBSD so a patch or just even output from 'ifconfig -a' should be helpful for fixing this.

It has changed from:

```
re0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
```

to:

```
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
```


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
@@ -1748,8 +1748,9 @@ def get_interfaces_info(self, ifconfig_path):
     def parse_interface_line(self, words):
         device = words[0][0:-1]
         current_if = {'device': device, 'ipv4': [], 'ipv6': [], 'type': 'unknown'}
-        current_if['flags'] = self.get_options(words[1])
-        current_if['mtu'] = words[3]
+        current_if['flags']  = self.get_options(words[1])
+        current_if['metric'] = words[3]
+        current_if['mtu'] = words[5]
         current_if['macaddress'] = 'unknown'    # will be overwritten later
         return current_if
 


Test patch:
Repository: ansible/ansible

Issue:
openbsd interfaces detection
##### Issue Type: Bug Report
##### Ansible Version: 1.5.4
##### Environment: OpenBSD
##### Summary: Error in interface list
##### Steps To Reproduce: ansible -m setup
##### Expected Results: list of interfaces, among other facts
##### Actual Results: list of interfaces plus some out-of-nowhere nic

Here is a sample patch for system/setup (get_interfaces_info from GenericBsdIfconfigNetwork):

1735 was:
if re.match('^\S', line) and len(words) > 3:
1735 becomes:
if words[0] == 'pass':
   continue
elif re.match('^\S', line) and len(words) > 3:

Regards.



Discussion:
Could you send us a pull request with the above fix contained there? That way you'll get credit for the fix. Also add 'Fixes #7093' on a line by itself in the commit message and it will auto-close this if/when we merge that PR in. Thanks!


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
@@ -1721,7 +1721,9 @@ def get_interfaces_info(self, ifconfig_path):
             if line:
                 words = line.split()
 
-                if re.match('^\S', line) and len(words) > 3:
+                if words[0] == 'pass':
+                    continue
+                elif re.match('^\S', line) and len(words) > 3:
                     current_if = self.parse_interface_line(words)
                     interfaces[ current_if['device'] ] = current_if
                 elif words[0].startswith('options='):


Test patch:
Repository: ansible/ansible

Issue:
File doesn't create sub-directories with the same permissions as the top level directory
##### Issue Type:

“Bug Report”
##### Ansible Version:

ansible 1.5.4
##### Environment:

Ubuntu 14.04
##### Summary:

The file module doesn't create sub-directories with the same permissions as the top level directory. 
##### Steps To Reproduce:

``` yml
- name: Configure the instance
  hosts: myhosts
  user: ec2-user
  sudo: true
  gather_facts: true
  tasks:
    - name: Create project directory
      file:
        path: "/home/ec2-user/apps/myapp"
        owner: ec2-user
        group: ec2-user
        state: directory
```
##### Expected Results:

The `apps` directory should have the same owner and group as the `myapp` directory.
##### Actual Results:

The `apps` directory is owned by root.



Discussion:

Resolving patch:
diff --git a/lib/ansible/utils/module_docs_fragments/files.py b/lib/ansible/utils/module_docs_fragments/files.py
--- a/lib/ansible/utils/module_docs_fragments/files.py
+++ b/lib/ansible/utils/module_docs_fragments/files.py
@@ -30,14 +30,14 @@ class ModuleDocFragment(object):
   state:
     description:
       - If C(directory), all immediate subdirectories will be created if they
-        do not exist. If C(file), the file will NOT be created if it does not
-        exist, see the M(copy) or M(template) module if you want that behavior.
-        If C(link), the symbolic link will be created or changed. Use C(hard)
-        for hardlinks. If C(absent), directories will be recursively deleted,
-        and files or symlinks will be unlinked. If C(touch) (new in 1.4), an empty file will
-        be created if the c(path) does not exist, while an existing file or
-        directory will receive updated file access and modification times (similar
-        to the way `touch` works from the command line).
+        do not exist, since 1.7 they will be created with the supplied permissions.
+        If C(file), the file will NOT be created if it does not exist, see the M(copy)
+        or M(template) module if you want that behavior.  If C(link), the symbolic
+        link will be created or changed. Use C(hard) for hardlinks. If C(absent),
+        directories will be recursively deleted, and files or symlinks will be unlinked.
+        If C(touch) (new in 1.4), an empty file will be created if the c(path) does not
+        exist, while an existing file or directory will receive updated file access and
+        modification times (similar to the way `touch` works from the command line).
     required: false
     default: file
     choices: [ file, link, directory, hard, touch, absent ]


Test patch:
Repository: ansible/ansible

Issue:
setup module fails on older OpenSuSE (<12?)
##### Issue Type:

Bug Report
##### Ansible Version:

ansible 1.5.3
##### Environment:

OpenSuSE 10-13
##### Summary:

setup module failes on older OpenSuSE versions. Reason: /etc/SuSE-release has only 2 lines instead of 3 as assumed by get_distribution_facts(). The missing line is "CODENAME".
##### Steps To Reproduce:

Get any SuSE distrib, and strip "CODENAME" from /etc/SuSE-release if present. 
##### Expected Results:

No error.
##### Actual Results:

fatal Error: IndexError: list index out of range
line 330, in get_distribution_facts
  self.facts['distribution_release'] = data[2].split('=')[1].strip() 

Fix: check if data[2] exists before assigning.

Note (FYI): the current (13.1) OpenSuSE has this in SuSE-release:"/etc/SuSE-release is deprecated and will be removed in the future, use /etc/os-release instead"



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
@@ -303,7 +303,9 @@ def get_distribution_facts(self):
                         self.facts['distribution_release'] = ora_prefix + data
                     elif name == 'SuSE':
                         data = get_file_content(path).splitlines()
-                        self.facts['distribution_release'] = data[2].split('=')[1].strip()
+                        for line in data:
+                            if '=' in line:
+                            	self.facts['distribution_release'] = line.split('=')[1].strip()
                     elif name == 'Debian':
                         data = get_file_content(path).split('\n')[0]
                         release = re.search("PRETTY_NAME.+ \(?([^ ]+?)\)?\"", data)


Test patch: