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

Issue:
'copy' module logs despite no_log: true
##### Issue Type:

Bug Report
##### Ansible Version:

ansible 1.6 (devel a482e1583d) last updated 2014/04/29 01:53:48 (GMT +800)
##### Environment:

Ubuntu 12.04.4
##### Summary:

'copy' module logs on the remote despite no_log: true. This is not the case for other modules (service, command, shell). I would submit a patch, except that I'm still figuring out the source.
##### Steps To Reproduce:

Create a play with a copy task, and set no_log: true. Run the play, and you'll see that the copy task is still logged on the remote.
##### Expected Results:

No log on the remote for the copy task.
##### Actual Results:

The copy task is logged on the remote.



Discussion:

Resolving patch:
diff --git a/lib/ansible/runner/action_plugins/copy.py b/lib/ansible/runner/action_plugins/copy.py
--- a/lib/ansible/runner/action_plugins/copy.py
+++ b/lib/ansible/runner/action_plugins/copy.py
@@ -240,6 +240,10 @@ def run(self, conn, tmp_path, module_name, module_args, inject, complex_args=Non
                 # we pass dest only to make sure it includes trailing slash in case of recursive copy
                 module_args_tmp = "%s src=%s dest=%s original_basename=%s" % (module_args,
                                   pipes.quote(tmp_src), pipes.quote(dest), pipes.quote(source_rel))
+
+                if self.runner.no_log:
+                    module_args_tmp = "%s NO_LOG=True" % module_args_tmp
+
                 module_return = self.runner._execute_module(conn, tmp_path, 'copy', module_args_tmp, inject=inject, complex_args=complex_args, delete_remote_tmp=delete_remote_tmp)
                 module_executed = True
 


Test patch:
Repository: ansible/ansible

Issue:
synchronize module: basedir references inventory instead of playbook
##### Issue Type:

Bug Report
##### Ansible Version:

Bug exists in -devel and in 1.6.0 and 1.6.1
Still works in 1.5.5

bisect: 2492c2714a8dfe5dc8de083580a5dcafd61ddb47 is the first bad commit
##### Environment:

Ubuntu 12.04
##### Summary:

The synchronize module uses the playbook basedir as base reference for local paths.
Now, it looks for inventory dir as it's basepath, which breaks playbooks with relative paths.

According to 2492c2714a8dfe5dc8de083580a5dcafd61ddb47 (@jimi-c 's commit Fixes #5307 set relative paths to the files dir for roles and the inventory dir for non-role tasks) this is intended behaviour, though I fail to see why the inventory should be the base dir, and not the playbook?
##### Steps To Reproduce:

This action lives in a playbook plays/cbb.yml and we have dirs plays/files/cbb/jms/...

```
action: synchronize src=files/cbb/jms/ dest=/opt/jboss/server/all/deploy-hasingleton/jms/
```

Note: This is part of a plain playbook _without_ roles.
##### Expected Results:

```
ok: [cbb] => {"changed": false, "cmd": "rsync --delay-updates -FF --compress --timeout=10 --archive --rsh 'ssh  -o StrictHostKeyChecking=no' --out-format='<<CHANGED>>%i %n%L' files/cbb/jms/ root@cbb:/opt/jboss/server/all/deploy-hasingleton/jms/", "msg": "", "rc": 0}
```
##### Actual Results:

```
failed: [cbb] => {"cmd": "rsync --delay-updates -FF --compress --archive --rsh 'ssh  -o StrictHostKeyChecking=no' --out-format='<<CHANGED>>%i %n%L' /home/serge/src/acd/ansible-data/inventory/files/cbb/jms/ root@cbb:/opt/jboss/server/all/deploy-hasingleton/jms/", "failed": true, "rc": 23}
rsync: change_dir "/home/serge/src/acd/ansible-data/inventory/files/cbb/jms" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.9]
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/runner/action_plugins/synchronize.py b/lib/ansible/runner/action_plugins/synchronize.py
--- a/lib/ansible/runner/action_plugins/synchronize.py
+++ b/lib/ansible/runner/action_plugins/synchronize.py
@@ -38,10 +38,6 @@ def _get_absolute_path(self, path=None):
                     # make sure the dwim'd path ends in a trailing "/"
                     # if the original path did
                     path += '/'
-            elif 'inventory_dir' in self.inject['vars']:
-                # non-roles
-                abs_dir = os.path.abspath(self.inject['vars']['inventory_dir'])
-                path = os.path.join(abs_dir, path)
 
         return path
 


Test patch:
Repository: ansible/ansible

Issue:
script module drops stdout if it contains any non-printable characters
##### Issue Type: Bug Report
##### Ansible Version: ansible 1.7 (devel 6b70ee23ab) last updated 2014/05/21 19:24:28 (GMT -700)
##### Environment: OS X 10.9 to Ubuntu 12.04
##### Summary:

When using the script module, stdout gets dropped (replaced with '') if it contains non-printable characters.  They should be stripped instead.
##### Steps To Reproduce:

``` bash
    $ cat script.sh
    echo -e \\a critical information

    $ ansible -i $target, -m script -a script.sh $target
```
##### Expected Results:

``` bash
$ ansible -i $target, -m script -a script.sh $target
$target | success >> {
    "changed": true,
    "rc": 0,
    "stderr": "",
    "stdout": " critical information\r\n"
}
```
##### Actual Results:

``` bash
    $ cat script.sh
    echo -e \\a critical information

    $ ansible -i $target, -m script -a script.sh $target
    $target | success >> {
        "changed": true,
        "rc": 0,
        "stderr": "",
        "stdout": ""
    }
```

I believe the problem lies in the following line (879 in lib/ansible/runner/**init**.py):

``` python
                    if not string_functions.isprintable(data['stdout']):
                                            data['stdout'] = ''
```

The correct action is probably to clean the string instead.  I'll whip up a pull request, but please review thoroughly.



Discussion:

Resolving patch:
diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py
--- a/lib/ansible/runner/__init__.py
+++ b/lib/ansible/runner/__init__.py
@@ -877,7 +877,7 @@ def _executor_internal_inner(self, host, module_name, module_args, inject, port,
             if hasattr(sys.stdout, "isatty"):
                 if "stdout" in data and sys.stdout.isatty():
                     if not string_functions.isprintable(data['stdout']):
-                        data['stdout'] = ''
+                        data['stdout'] = ''.join(c for c in data['stdout'] if string_functions.isprintable(c))
 
             if 'item' in inject:
                 result.result['item'] = inject['item']


Test patch:
Repository: ansible/ansible

Issue:
roles_path should allow user environment variables
I tried: 

roles_path     = $HOME/Roles

but received, for example:

ERROR: cannot find role in /home/doej/posix/code/gitlab.com/acme-devops/ansible/roles/external_roles/common/group-by or /home/doej/posix/code/gitlab.com/acme-devops/ansible/external_roles/common/group-by or /home/doej/posix/code/gitlab.com/acme-devops/ansible/$HOME/Roles/external_roles/common/group-by

I definitely have a role (with known good tasks dir) in '''$HOME/Roles/external_roles/common/group-by''', but there seems to be a bug because it's prefacing my "roles_path" with the current playbook working dir.

Please let me know if I can help in any way.  Perhaps, environment variables are not intended for use in this fashion.

Thanks,
Joshua



Discussion:
@josh-at-knoesis please indicate which version of ansible you are using.

@jctanner 

Sorry about that.  I am running the master branch, which I cloned to the machine about three hours ago.  v1.4

@josh-at-knoesis

roles_path isn't shell expanded

```
103 DEFAULT_ROLES_PATH        = get_config(p, DEFAULTS, 'roles_path',       'ANSIBLE_ROLES_PATH',       None)
104 DEFAULT_REMOTE_TMP        = shell_expand_path(get_config(p, DEFAULTS, 'remote_tmp',       'ANSIBLE_REMOTE_TEMP',      '$HOME/.ansible/tmp'))
```

My work around has been to set ANSIBLE_ROLES_PATH

+1.  This is inconsistent in the ansible.cfg file.  

Reclassifying this as a bug report -- seems like an easy fix should someone wish to send a pull request :)


Resolving patch:
diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py
--- a/lib/ansible/constants.py
+++ b/lib/ansible/constants.py
@@ -102,7 +102,7 @@ def shell_expand_path(path):
 # configurable things
 DEFAULT_HOST_LIST         = shell_expand_path(get_config(p, DEFAULTS, 'hostfile', 'ANSIBLE_HOSTS', '/etc/ansible/hosts'))
 DEFAULT_MODULE_PATH       = get_config(p, DEFAULTS, 'library',          'ANSIBLE_LIBRARY',          DIST_MODULE_PATH)
-DEFAULT_ROLES_PATH        = get_config(p, DEFAULTS, 'roles_path',       'ANSIBLE_ROLES_PATH',       '/etc/ansible/roles')
+DEFAULT_ROLES_PATH        = shell_expand_path(get_config(p, DEFAULTS, 'roles_path',       'ANSIBLE_ROLES_PATH',       '/etc/ansible/roles'))
 DEFAULT_REMOTE_TMP        = shell_expand_path(get_config(p, DEFAULTS, 'remote_tmp',       'ANSIBLE_REMOTE_TEMP',      '$HOME/.ansible/tmp'))
 DEFAULT_MODULE_NAME       = get_config(p, DEFAULTS, 'module_name',      None,                       'command')
 DEFAULT_PATTERN           = get_config(p, DEFAULTS, 'pattern',          None,                       '*')


Test patch:
Repository: ansible/ansible

Issue:
Gathering facts fails on Funtoo Linux
##### Issue Type:

Bug Report
##### Ansible Version:

ansible-playbook 1.7 (devel 122fff970f) last updated 2014/06/22 00:10:25 (GMT +200)
##### Environment:

Funtoo Linux
##### Summary:

When gathering facts about a system running Funtoo Linux, ansible stumbles over an existing but empty /etc/os-release and tries to receive Debian release informations from it. For this purpose, ansible tries to split the content (None) leading to the following exception:

```
invalid output was: Traceback (most recent call last):
  File "/home/s0x/.ansible/tmp/ansible-tmp-1403389585.69-111007185005190/setup", line 3748, in <module>
    main()
  File "/home/s0x/.ansible/tmp/ansible-tmp-1403389585.69-111007185005190/setup", line 137, in main
    data = run_setup(module)
  File "/home/s0x/.ansible/tmp/ansible-tmp-1403389585.69-111007185005190/setup", line 81, in run_setup
    facts = ansible_facts(module)
  File "/home/s0x/.ansible/tmp/ansible-tmp-1403389585.69-111007185005190/setup", line 3686, in ansible_facts
    facts.update(Facts().populate())
  File "/home/s0x/.ansible/tmp/ansible-tmp-1403389585.69-111007185005190/setup", line 1493, in __init__
    self.get_platform_facts()
  File "/home/s0x/.ansible/tmp/ansible-tmp-1403389585.69-111007185005190/setup", line 1536, in get_platform_facts
    self.get_distribution_facts()
  File "/home/s0x/.ansible/tmp/ansible-tmp-1403389585.69-111007185005190/setup", line 1687, in get_distribution_facts
    data = get_file_content(path).split('\n')[0]
AttributeError: 'NoneType' object has no attribute 'split'
```
##### Steps To Reproduce:

Actually, I tested it on a local playbook only so far, though it shouldn't make any difference on a remote machine.
- Create a playbook using local connection

```
- name: Run some local tasks
  hosts: localhost
  connection: local
  tasks:
  - name: Some task
    action: debug
```
- Run it: `ansible-playbook local.yaml`
##### Expected Results:

The playbook should be executed without any error.
##### Actual Results:

Gathering facts will fail with the error shown above.



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
@@ -266,7 +266,7 @@ def get_distribution_facts(self):
             self.facts['distribution_release'] = dist[2] or 'NA'
             # Try to handle the exceptions now ...
             for (path, name) in Facts.OSDIST_DICT.items():
-                if os.path.exists(path):
+                if os.path.exists(path) and os.path.getsize(path) > 0:
                     if self.facts['distribution'] == 'Fedora':
                         pass
                     elif name == 'RedHat':


Test patch:
Repository: ansible/ansible

Issue:
ansible-playbook fails at 'GATHERING FACTS'
##### Issue Type:

Bug Report
##### Ansible Version:

`ansible 1.7 (brew_json d3cbc0ac52) last updated 2014/06/23 02:25:36 (GMT -400)`
##### Environment:

OS X 10.9.3 --> OS X 10.9.3 (via a local connection)
##### Summary:

`ansible-playbook` fails at `GATHERING FACTS`
##### Steps To Reproduce:

Run: 
`ansible-playbook -i ~/.ansible.d/inventories/osx ~/.ansible.d/dotfiles.yml --connection=local`

With playbook:

```
# file: dotfiles.yml

---
- hosts: dotfiles
  sudo: yes
  sudo_user: "{{ dan.user.name }}"
  roles:
    - dotfiles
```
##### Expected Results:

`GATHERING FACTS` returns with no error. 
##### Actual Results:

`GATHERING FACTS` returns with error:

```
GATHERING FACTS ***************************************************************
fatal: [127.0.0.1] => Traceback (most recent call last):
  File "/Users/dan/src/ansible/lib/ansible/runner/__init__.py", line 526, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File "/Users/dan/src/ansible/lib/ansible/runner/__init__.py", line 628, in _executor_internal
    return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
  File "/Users/dan/src/ansible/lib/ansible/runner/__init__.py", line 833, in _executor_internal_inner
    result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
  File "/Users/dan/src/ansible/lib/ansible/runner/action_plugins/normal.py", line 57, in run
    return self.runner._execute_module(conn, tmp, module_name, module_args, inject=inject, complex_args=complex_args)
  File "/Users/dan/src/ansible/lib/ansible/runner/__init__.py", line 427, in _execute_module
    self._remote_chmod(conn, 'a+r', remote_module_path)
TypeError: _remote_chmod() takes at least 5 arguments (4 given)


TASK: [dotfiles | dan | mkdir -p dotfiles.dan.directories] ********************
FATAL: no hosts matched or all hosts have already failed -- aborting
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py
--- a/lib/ansible/runner/__init__.py
+++ b/lib/ansible/runner/__init__.py
@@ -424,7 +424,7 @@ def _execute_module(self, conn, tmp, module_name, args,
 
         if "tmp" in tmp and ((self.sudo and self.sudo_user != 'root') or (self.su and self.su_user != 'root')):
             # deal with possible umask issues once sudo'ed to other user
-            self._remote_chmod(conn, 'a+r', remote_module_path)
+            self._remote_chmod(conn, 'a+r', remote_module_path, tmp)
 
         cmd = ""
         in_data = None
@@ -452,7 +452,7 @@ def _execute_module(self, conn, tmp, module_name, args,
 
             if (self.sudo and self.sudo_user != 'root') or (self.su and self.su_user != 'root'):
                 # deal with possible umask issues once sudo'ed to other user
-                self._remote_chmod(conn, 'a+r', argsfile)
+                self._remote_chmod(conn, 'a+r', argsfile, tmp)
 
             if async_jid is None:
                 cmd = "%s %s" % (remote_module_path, argsfile)


Test patch:
Repository: ansible/ansible

Issue:
group_by is reading group_vars/key_group only if such key_gorup is defined in inventory
Hello,
Using Ansible 1.7 latest. found issue using group_by.
play fragment : 
- group_by: key={{ ansible-distribution }}
- group_vars/CentOS is exists
- some variable is defined in group_vars/CentOS
  When inventory does not have such dynamic group, ansible does not try to load any info from group_vars/CentOS , and playbook can not use dynamicaly loaded variables.

When inventory file has such dynamic groups ( without hosts added ) defined, variable has correct value from corresponding key_group variable file.

I've checked _ansible-playbook_ run with _strace_ and noticed that _group_vars_ directory is accessed only for files that correspond to all groups defined in inventory file

On Ansible 1.6.2 group_by loads group_vars/files correctly , without requiring defining such groups in inventory. 

Maybe it related to some changes in the way ansible loading group_vars files



Discussion:
This will probably be a bug related to the inventory refactor, which indeed changes the loading of group_vars. I will look into this.

Thanks for filing a ticket! I am the friendly GitHub Ansibot. I see you did not fill out your issue description based on our new issue template. Please copy the contents of this [template](https://raw2.github.com/ansible/ansible/devel/examples/issues/ISSUE_TEMPLATE.md) and **paste it into the description** of your ticket. 

Our system will automatically close tickets that do not have an issue template filled out within 7 days. Please note that due to large interest in Ansible, humans may not comment on your ticket if you ask them questions. Don't worry, you're still in the queue and the robots are looking after you.


Resolving patch:
diff --git a/lib/ansible/runner/action_plugins/group_by.py b/lib/ansible/runner/action_plugins/group_by.py
--- a/lib/ansible/runner/action_plugins/group_by.py
+++ b/lib/ansible/runner/action_plugins/group_by.py
@@ -93,6 +93,7 @@ def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **
             if not inv_group:
                 inv_group = ansible.inventory.Group(name=group)
                 inventory.add_group(inv_group)
+                inv_group.vars = inventory.get_group_variables(group, update_cached=False, vault_password=inventory._vault_password)
             for host in hosts:
                 if host in self.runner.inventory._vars_per_host:
                     del self.runner.inventory._vars_per_host[host]


Test patch:
Repository: ansible/ansible

Issue:
Using $HOME in ansible.cfg [defaults] hostfile = doesn't work
##### Issue Type:

Bug Report
##### Ansible Version:

ansible 1.5
##### Environment:

Ubuntu Precise
##### Summary:

I tried setting

hostfile = $HOME/.ansible/hosts
and it didn't work at all; I got 'ERROR: Unable to find an inventory file, specify one with -i ?'. Changing it to hostfile = /home/pjz/.ansible/hosts fixed it, but was clearly suboptimal; why is environment substitution done in some cases (remote_tmp defaults to $HOME/.ansible/tmp) but not others? 
##### Steps To Reproduce:

In ansible.cfg, set 

```
hostfile = $HOME/.ansible/hosts
```

Then put a host definition there and try using it with, for example, `ansible all -m ping`
##### Expected Results:

I expect to see the usual ping output
##### Actual Results:

```
ERROR: Unable to find an inventory file, specify one with -i ?
```



Discussion:
Basically this is expecting an os.path.expandvars to be executed here around the inventory path.

This seems reasonable though there may have been problems checking earlier.

Seems like an easy patch if this is something you would like to work on!

Well, so the larger question is whether other paths (all paths?) in the ansible.cfg should be wrapped in os.path.expandvars? 

Problem is still there in ansible 1.7 (devel 8a6cfa1a23). The example ansible.cfg uses $HOME so I thought I use it to set the hostfile to "hostfile = $HOME/whatever". But it doesn't work. It does work with ~/whatever (thanks to rob in #ansible on IRC for the tip.
If it's not fixed maybe it should be changed in the example (and in the docs).


Resolving patch:
diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py
--- a/lib/ansible/constants.py
+++ b/lib/ansible/constants.py
@@ -79,7 +79,7 @@ def shell_expand_path(path):
     ''' shell_expand_path is needed as os.path.expanduser does not work
         when path is None, which is the default for ANSIBLE_PRIVATE_KEY_FILE '''
     if path:
-        path = os.path.expanduser(path)
+        path = os.path.expandvars(os.path.expanduser(path))
     return path
 
 p = load_config_file()


Test patch:
Repository: ansible/ansible

Issue:
would like better error message when disk is full
##### Issue Type:

Bug Report
##### Ansible Version:

ansible 1.5.4
##### Environment:

From: Centos 5/6
To: Centos 5/6
##### Summary:

When ansible tries to run a command in a machine with a full disk it returns a misleading message.
##### Steps To Reproduce:

Full a disk of target machine (using DD or any other way).  Run ansible to do something on the target machine. You will get the message.
##### Expected Results:

The error message should be something like this
mkdir: cannot create directory `$HOME/.ansible/tmp/ansible-tmp-1406727561.92-124710193092100': No space left on device
##### Actual Results:

Message:
"Authentication or permission failure.  In some cases, you may have been able to authenticate and did not have permissions on the remote directory".

Full stack trace:
13:39:20 TASK: [generic | checking for the existence of the service FOO] ***\* 
13:39:22 fatal: [host] => Authentication or permission failure.  In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in "/tmp". Failed command was: mkdir -p $HOME/.ansible/tmp/ansible-tmp-1406727561.92-124710193092100 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1406727561.92-124710193092100 && echo $HOME/.ansible/tmp/ansible-tmp-1406727561.92-124710193092100, exited with result 1
13:39:22



Discussion:
We're not aware that's the actual result in this case right now, but we can check to see if that comes back in the string I'm guessing.


Resolving patch:
diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py
--- a/lib/ansible/runner/__init__.py
+++ b/lib/ansible/runner/__init__.py
@@ -1090,6 +1090,8 @@ def _make_tmp_path(self, conn):
                     output = 'SSH encountered an unknown error. The output was:\n%s' % (result['stdout']+result['stderr'])
                 else:
                     output = 'SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue'
+            elif 'No space left on device' in result['stderr']:
+                output = result['stderr']
             else:
                 output = 'Authentication or permission failure.  In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in "/tmp". Failed command was: %s, exited with result %d' % (cmd, result['rc'])
             if 'stdout' in result and result['stdout'] != '':


Test patch:
Repository: ansible/ansible

Issue:
ansible-galaxy should not need roles directory to exist
Commit aa46fcf09 introduces a check to ensure that `roles_path` exists. 

However, previously, if roles_path did not exist, it just created the directories anyway. 
https://github.com/ansible/ansible/blob/devel/bin/ansible-galaxy#L547
On that basis I'm not sure that the check for whether the directory exists is in the right place (it's nice to just blow away the roles directory entirely sometimes and reinstall from rolesfile)

I would like to understand the reason for this commit (it doesn't seem to be linked to an issue or PR)

cc @jimi-c 



Discussion:

Resolving patch:
diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py
--- a/lib/ansible/utils/__init__.py
+++ b/lib/ansible/utils/__init__.py
@@ -387,15 +387,12 @@ def role_spec_parse(role_spec):
   
     role_spec = role_spec.strip()
     role_version = ''
+    default_role_versions = dict(git='master', hg='tip')
     if role_spec == "" or role_spec.startswith("#"):
         return (None, None, None, None)
 
     tokens = [s.strip() for s in role_spec.split(',')]
     
-    if not tokens[0].endswith('.tar.gz'): 
-        # pick a reasonable default branch
-        role_version = 'master'
-
     # assume https://github.com URLs are git+https:// URLs and not
     # tarballs unless they end in '.zip'
     if 'github.com/' in tokens[0] and not tokens[0].startswith("git+") and not tokens[0].endswith('.tar.gz'):
@@ -412,6 +409,8 @@ def role_spec_parse(role_spec):
         role_name = tokens[2]
     else:
         role_name = repo_url_to_role_name(tokens[0])
+    if scm and not role_version:
+        role_version = default_role_versions.get(scm, '')
     return dict(scm=scm, src=role_url, version=role_version, name=role_name)
 
 


Test patch: