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

Issue:
ANSIBLE_VERBOSITY environment variable cannot be used to control verbosity
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
core

##### ANSIBLE VERSION
```
2.2.1
2.1.0
2.3.0
```

##### CONFIGURATION
```
ANSIBLE_VERBOSITY=vvv
```

##### OS / ENVIRONMENT
N/S

##### SUMMARY
I was surprised to find out that there is no way to control ansible verbosity level via an environment variable. There are environment variables for even the weirdest things like `ANSIBLE_COLOR_DEBUG` but somehow none for verbosity.

The closes relative is the `ANSIBLE_DEBUG` variable but this one is enabling an extremely verbose mode, one that makes it useless for most use cases.

We also got a recommendation for [implementing this inside a custom callback](http://stackoverflow.com/questions/42510032/how-to-change-ansible-verbosity-level-without-changing-the-command-line-argument) but this would not work for several reasons:

* we call multiple ansible playbooks and some of they may already have custom callbacks
* this is the kind of feature that is supposed to be part of the core.

We need an implementation that allows use to specify different verbosity levels that do correspond to: `None`, `-v`, `-vv`, `-vvv` and `-vvvv`.


Discussion:

Resolving patch:
diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py
--- a/lib/ansible/cli/__init__.py
+++ b/lib/ansible/cli/__init__.py
@@ -287,7 +287,7 @@ def base_parser(usage="", output_opts=False, runas_opts=False, meta_opts=False,
 
         # base opts
         parser = SortedOptParser(usage, version=CLI.version("%prog"))
-        parser.add_option('-v','--verbose', dest='verbosity', default=0, action="count",
+        parser.add_option('-v','--verbose', dest='verbosity', default=C.DEFAULT_VERBOSITY, action="count",
             help="verbose mode (-vvv for more, -vvvv to enable connection debugging)")
 
         if inventory_opts:
diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py
--- a/lib/ansible/constants.py
+++ b/lib/ansible/constants.py
@@ -195,6 +195,7 @@ def load_config_file():
 
 #### GENERALLY CONFIGURABLE THINGS ####
 DEFAULT_DEBUG             = get_config(p, DEFAULTS, 'debug',            'ANSIBLE_DEBUG',            False, value_type='boolean')
+DEFAULT_VERBOSITY         = get_config(p, DEFAULTS, 'verbosity',        'ANSIBLE_VERBOSITY',        0, value_type='integer')
 DEFAULT_HOST_LIST         = get_config(p, DEFAULTS,'inventory', 'ANSIBLE_INVENTORY', DEPRECATED_HOST_LIST, value_type='path')
 DEFAULT_ROLES_PATH        = get_config(p, DEFAULTS, 'roles_path',       'ANSIBLE_ROLES_PATH',       '/etc/ansible/roles', value_type='pathlist', expand_relative_paths=True)
 DEFAULT_REMOTE_TMP        = get_config(p, DEFAULTS, 'remote_tmp',       'ANSIBLE_REMOTE_TEMP',      '~/.ansible/tmp')


Test patch:
Repository: ansible/ansible

Issue:
win_chocolatey: No means of upgrading all existing packages
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Feature Idea

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
win_chocolatey

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
v2.3

##### SUMMARY
<!--- Explain the problem briefly -->

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->
There is a shortcoming in the current win_chocolatey module. There is no means of updating all existing chocolatey packages, like the yum-equivalent:
```yaml
- win_chocolatey:
    name: *
    state: latest
```
I think this is essential to have (and a lot more efficient than looping over a predefined list).


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

Resolving patch:
diff --git a/lib/ansible/modules/windows/win_chocolatey.py b/lib/ansible/modules/windows/win_chocolatey.py
--- a/lib/ansible/modules/windows/win_chocolatey.py
+++ b/lib/ansible/modules/windows/win_chocolatey.py
@@ -106,19 +106,25 @@
   # Install git
   win_chocolatey:
     name: git
+    state: present
+
+  # Upgrade installed packages
+  win_chocolatey:
+    name: all
+    state: latest
 
   # Install notepadplusplus version 6.6
   win_chocolatey:
     name: notepadplusplus.install
     version: '6.6'
 
-  # Uninstall git
+  # Install git from specified repository
   win_chocolatey:
     name: git
-    state: absent
+    source: https://someserver/api/v2/
 
-  # Install git from specified repository
+  # Uninstall git
   win_chocolatey:
     name: git
-    source: https://someserver/api/v2/
+    state: absent
 '''


Test patch:
Repository: ansible/ansible

Issue:
aix_inittab: RETURN needs documenting
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
aix_inittabt

##### SUMMARY
@molekuul It appeared that the `RETURN` block wasn't formatted correctly in the original PR https://github.com/ansible/ansible/pull/21511 this wasn't spotted by our CI tests (which I'll look into)

This caused the production of webdocs to fail, so I removed it in https://github.com/ansible/ansible/commit/1d2349872ade6b877bee6cdad586cce78d3a159f#diff-230f216d211a01e63630e56a737d6865

Could you please add it again, details on how to format the `RETURN` block can be found at http://docs.ansible.com/ansible/dev_guide/developing_modules_documenting.html#return-block

Thanks in advance


Discussion:
@gundalow , 

How do I handle this Bug? 
Must I repair this bug in my own fork, and than request a new pull request? or must this be handled in the original pull request?

Kind regards,

Joris Weijters
@molekuul As the original PR has been merged just create a fresh PR from `devel`

Resolving patch:
diff --git a/lib/ansible/modules/system/aix_inittab.py b/lib/ansible/modules/system/aix_inittab.py
--- a/lib/ansible/modules/system/aix_inittab.py
+++ b/lib/ansible/modules/system/aix_inittab.py
@@ -113,7 +113,21 @@
 '''
 
 RETURN = '''
-
+name:
+    description: name of the adjusted inittab entry
+    returned: always
+    type: string
+    sample: startmyservice
+mgs:
+    description: action done with the inittab entry
+    returned: changed
+    type: string
+    sample: changed inittab entry startmyservice
+changed:
+    description: whether the inittab changed or not
+    return: always
+    type: boolean
+    sample: true
 '''
 
 # Import necessary libraries


Test patch:
Repository: ansible/ansible

Issue:
s3 module doesn't work with rgw=true and a dot in a bucket name

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
s3 module

##### ANSIBLE VERSION
```
ansible 2.3.0
  config file =
  configured module search path = Default w/o overrides
```

##### OS / ENVIRONMENT
N/A

##### SUMMARY
If `rgw: true` is set in the s3 module and you also use a bucket name containing a `.`, an exception is thrown resulting in the following error message:
```
"msg": "Failed to connect to S3: connect_s3() got multiple values for keyword argument 'calling_format'"
```




Discussion:
The problem is here: https://github.com/ansible/ansible/blob/c6849a34647eb8c2c92cc0659de769eeee8fce4c/lib/ansible/modules/cloud/amazon/s3.py#L720-L721

When a bucket name contains a `.`, aws_connect_kwargs already contains an entry for `calling_format` which was set here: https://github.com/ansible/ansible/blob/c6849a34647eb8c2c92cc0659de769eeee8fce4c/lib/ansible/modules/cloud/amazon/s3.py#L530

Should be an easy fix - I'll submit a PR shortly. 

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/s3.py b/lib/ansible/modules/cloud/amazon/s3.py
--- a/lib/ansible/modules/cloud/amazon/s3.py
+++ b/lib/ansible/modules/cloud/amazon/s3.py
@@ -713,6 +713,13 @@ def main():
 def get_s3_connection(aws_connect_kwargs, location, rgw, s3_url):
     if s3_url and rgw:
         rgw = urlparse(s3_url)
+        # ensure none of the named arguments we will pass to boto.connect_s3
+        # are already present in aws_connect_kwargs
+        for kw in ['is_secure', 'host', 'port', 'calling_format']:
+            try:
+                del aws_connect_kwargs[kw]
+            except KeyError:
+                pass
         s3 = boto.connect_s3(
             is_secure=rgw.scheme == 'https',
             host=rgw.hostname,
@@ -722,6 +729,13 @@ def get_s3_connection(aws_connect_kwargs, location, rgw, s3_url):
         )
     elif is_fakes3(s3_url):
         fakes3 = urlparse(s3_url)
+        # ensure none of the named arguments we will pass to S3Connection
+        # are already present in aws_connect_kwargs
+        for kw in ['is_secure', 'host', 'port', 'calling_format']:
+            try:
+                del aws_connect_kwargs[kw]
+            except KeyError:
+                pass
         s3 = S3Connection(
             is_secure=fakes3.scheme == 'fakes3s',
             host=fakes3.hostname,


Test patch:
Repository: ansible/ansible

Issue:
Remove warning "argument authorize has been deprecated"
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
eos_banner

##### ANSIBLE VERSION
```
029ccf9aa0cd490224bfcf403ed94bc397e3af63
```

##### SUMMARY
In 2.3 using `authorise: yes` is the correct way to go into privileged mode on `eos` and `ios`.
Though we throw a warning that's it's a deprecated option, most likely as it's its in 

##### STEPS TO REPRODUCE
```yaml
- name: setup - remove motd
  eos_banner:
    banner: motd
    state: absent
    authorize: yes
```


##### EXPECTED RESULTS

##### ACTUAL RESULTS
```
 [WARNING]: argument authorize has been deprecated and will be removed in a future version

```



Discussion:
cc @privateip @Qalthos
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
assigning as Nate is out and this doesn't need device deep-dive expertise

Resolving patch:
diff --git a/lib/ansible/module_utils/eos.py b/lib/ansible/module_utils/eos.py
--- a/lib/ansible/module_utils/eos.py
+++ b/lib/ansible/module_utils/eos.py
@@ -61,7 +61,7 @@
 def check_args(module, warnings):
     provider = module.params['provider'] or {}
     for key in eos_argument_spec:
-        if key not in ['provider', 'transport'] and module.params[key]:
+        if key not in ['provider', 'transport', 'authorize'] and module.params[key]:
             warnings.append('argument %s has been deprecated and will be '
                     'removed in a future version' % key)
 
diff --git a/lib/ansible/module_utils/ios.py b/lib/ansible/module_utils/ios.py
--- a/lib/ansible/module_utils/ios.py
+++ b/lib/ansible/module_utils/ios.py
@@ -46,7 +46,7 @@
 def check_args(module, warnings):
     provider = module.params['provider'] or {}
     for key in ios_argument_spec:
-        if key != 'provider' and module.params[key]:
+        if key not in ['provider', 'authorize'] and module.params[key]:
             warnings.append('argument %s has been deprecated and will be '
                     'removed in a future version' % key)
 


Test patch:
Repository: ansible/ansible

Issue:
Unformatted PyPI page
Hello!

https://pypi.python.org/pypi/ansible looks like this, which looks a bit unprofessional:
![screenshot](https://cloud.githubusercontent.com/assets/159967/11303705/e6dbe908-8fac-11e5-9cd2-d83386890570.png)

If you convert the markup to ReStructuredText, it'll be rendered properly.  You can use pandoc for that.

Many projects use the same text for their GitHub README.rst and for their PyPI pages, by having the setup.py reuse the same text:

``` python
import setuptools

with open('README.rst') as f:
    long_description = f.read()

setup(
    ...,
    long_description=long_description,
    ...)
```

I'm not saying you should do that, but maybe it'll make your life easier?



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -158,6 +158,17 @@ def run(self):
         with open(os.path.join(extra_requirements_dir, extra_requirements_filename)) as extra_requirements_file:
             extra_requirements[filename_match.group(1)] = extra_requirements_file.read().splitlines()
 
+try:
+    with open('README.rst', 'r') as readme_file:
+        longdesc = readme_file.read()
+except (IOError, OSError):
+    longdesc = ('Ansible is a radically simple IT automation system. It handles'
+                ' configuration-management, application deployment, cloud provisioning, ad-hoc'
+                ' task-execution, and multinode orchestration - including trivializing things like'
+                ' zero-downtime rolling updates with load balancers.\n'
+                '\n'
+                'Read the documentation and more at https://ansible.com/'
+                )
 
 setup(
     # Use the distutils SDist so that symlinks are not expanded
@@ -172,6 +183,7 @@ def run(self):
     name='ansible',
     version=__version__,
     description='Radically simple IT automation',
+    long_description=longdesc,
     author=__author__,
     author_email='info@ansible.com',
     url='https://ansible.com/',


Test patch:
Repository: ansible/ansible

Issue:
UnboudLocalError: local variable 'f' referenced before assignment
Version: 1.9 but also devel as the file handling code does not changed.
Server/Client OS: Ubuntu

This is not a duplicate of #2618. When defining a caching path for the jsonfile caching plugin that is not writable by Ansible. Ansible fails with the following message:

```
fatal: [my-host] => Traceback (most recent call last):
  File "/home/david/.pip/ansible/lib/ansible/runner/__init__.py", line 586, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File "/home/david/.pip/ansible/lib/ansible/runner/__init__.py", line 668, in _executor_internal
    inject = self.get_inject_vars(host)
  File "/home/david/.pip/ansible/lib/ansible/runner/__init__.py", line 611, in get_inject_vars
    combined_cache = self.get_combined_cache()
  File "/home/david/.pip/ansible/lib/ansible/runner/__init__.py", line 606, in get_combined_cache
    combined_cache = self.setup_cache.copy()
  File "/home/david/.pip/ansible/lib/ansible/cache/__init__.py", line 54, in copy
    return dict([(k, v) for (k, v) in self.iteritems()])
  File "/usr/lib/python2.7/_abcoll.py", line 406, in iteritems
    yield (key, self[key])
  File "/home/david/.pip/ansible/lib/ansible/cache/__init__.py", line 35, in __getitem__
    return self._plugin.get(key)
  File "/home/david/.pip/ansible/lib/ansible/cache/jsonfile.py", line 69, in get
    f.close()
UnboundLocalError: local variable 'f' referenced before assignment
```



Discussion:
Do you have any update on this please? Thanks for your time.

Resolving patch:
diff --git a/lib/ansible/plugins/cache/base.py b/lib/ansible/plugins/cache/base.py
--- a/lib/ansible/plugins/cache/base.py
+++ b/lib/ansible/plugins/cache/base.py
@@ -91,8 +91,11 @@ def __init__(self, *args, **kwargs):
             try:
                 os.makedirs(self._cache_dir)
             except (OSError,IOError) as e:
-                display.warning("error in '%s' cache plugin while trying to create cache dir %s : %s" % (self.plugin_name, self._cache_dir, to_bytes(e)))
-                return None
+                raise AnsibleError("error in '%s' cache plugin while trying to create cache dir %s : %s" % (self.plugin_name, self._cache_dir, to_bytes(e)))
+        else:
+            for x in (os.R_OK, os.W_OK, os.X_OK):
+                if not os.access(self._cache_dir, x):
+                    raise AnsibleError("error in '%s' cache, configured path (%s) does not have necessary permissions (rwx), disabling plugin" % (self.plugin_name, self._cache_dir))
 
     def get(self, key):
         """ This checks the in memory cache first as the fact was not expired at 'gather time'
@@ -146,7 +149,7 @@ def has_expired(self, key):
                 return False
             else:
                 display.warning("error in '%s' cache plugin while trying to stat %s : %s" % (self.plugin_name, cachefile, to_bytes(e)))
-                pass
+                return False
 
         if time.time() - st.st_mtime <= self._timeout:
             return False


Test patch:
Repository: ansible/ansible

Issue:
tag attribute in ec2_snapshot_facts module should be dict instead of list
##### ISSUE TYPE
 - Documentation Report

##### COMPONENT NAME
ansible-modules-extras/cloud/amazon/ec2_snapshot_facts.py

##### ANSIBLE VERSION
```
$ ansible --version
ansible 2.2.1.0
  config file = /home/psd/.ansible.cfg
  configured module search path = ['/home/psd/.ansible/library']
```

##### CONFIGURATION
N/A. Not configuration-specific

##### OS / ENVIRONMENT
N/A

##### SUMMARY
The returned snapshots dict have a tag attribute, it was already [converted to dict in the code](https://github.com/ansible/ansible-modules-extras/blob/devel/cloud/amazon/ec2_snapshot_facts.py#L196)

So the expected tag attr in this module is a dict, not a list(which is the return value type in boto3)

##### STEPS TO REPRODUCE
get snapshot_facts, we have an example output in the next section:

##### ACTUAL RESULTS

```
        {
            "description": "",
            "encrypted": false,
            "owner_id": "omitted",
            "progress": "100%",
            "snapshot_id": "snap-omitted",
            "start_time": "2017-03-08T03:52:29+00:00",
            "state": "completed",
            "tags": {
                "Name": "some name",
                "creator": "cron on some machine",
                "frequency": "hourly"
            },
            "volume_id": "vol-omitted",
            "volume_size": 40
        }
```
As you can see, the tags attr is a dict.


Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/ec2_snapshot_facts.py b/lib/ansible/modules/cloud/amazon/ec2_snapshot_facts.py
--- a/lib/ansible/modules/cloud/amazon/ec2_snapshot_facts.py
+++ b/lib/ansible/modules/cloud/amazon/ec2_snapshot_facts.py
@@ -141,7 +141,7 @@
     sample: 033440102211
 tags:
     description: Any tags assigned to the snapshot.
-    type: list
+    type: dict
     sample: "{ 'my_tag_key': 'my_tag_value' }"
 encrypted:
     description: Indicates whether the snapshot is encrypted.


Test patch:
Repository: ansible/ansible

Issue:
Bug report module_utils/basic.py is_executable does not check file type
**Ansible Version:** 2.0.0 but probably all
**Ansible Configuration:** default
**Environment:** I think it will behave the same in all I guess. But tested on Mac and Ubuntu 14.04 with python_virtual env 

**Summary:**
if a module using [get_bin_path](https://github.com/ansible/ansible/blob/4de4d59d7a91aafa8127e6d48b303ea0abcc204b/lib/ansible/module_utils/basic.py#L1504)  i.e. [composer](https://github.com/ansible/ansible-modules-extras/blob/devel/packaging/language/composer.py#L155-L156)  it will check the path for a binary using [is_executable](https://github.com/ansible/ansible/blob/4de4d59d7a91aafa8127e6d48b303ea0abcc204b/lib/ansible/module_utils/basic.py#L492-L496)

if a directory has the same name as the binary and happens to be in the path and first matched it will try to use it. Directory has executable permission set on them. 

This issue was discovered in codeship as they are using loads of things in the path.

**Potential fix:**
 Check if file is not a directory 



Discussion:

Resolving patch:
diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py
--- a/lib/ansible/module_utils/basic.py
+++ b/lib/ansible/module_utils/basic.py
@@ -1892,7 +1892,7 @@ def get_bin_path(self, arg, required=False, opt_dirs=[]):
             if not d:
                 continue
             path = os.path.join(d, arg)
-            if os.path.exists(path) and is_executable(path):
+            if os.path.exists(path) and not os.path.isdir(path) and is_executable(path):
                 bin_path = path
                 break
         if required and bin_path is None:


Test patch:
Repository: ansible/ansible

Issue:
Fixes  #3352 Make default ANSIBLE_REMOTE_PORT None
The ansible remote port should be None, not 22. Having a default value
of 22 means that -o Port will be appended to the ssh connection all of
the time. This is incorrect when one would like to use something like
an ssh configuration file that calls out a port other than 22.

Part of this change requires that we check that the value is not None
before trying to coerce it into an integer or float.

This is related to https://github.com/ansible/ansible/issues/3352



Discussion:
agree

Merged, thanks!


Resolving patch:
diff --git a/lib/ansible/modules/cloud/docker/docker_network.py b/lib/ansible/modules/cloud/docker/docker_network.py
--- a/lib/ansible/modules/cloud/docker/docker_network.py
+++ b/lib/ansible/modules/cloud/docker/docker_network.py
@@ -217,12 +217,14 @@ def __init__(self, client):
             self.absent()
 
     def get_existing_network(self):
-        networks = self.client.networks()
-        network = None
-        for n in networks:
-            if n['Name'] == self.parameters.network_name:
-                network = n
-        return network
+        networks = self.client.networks(names=[self.parameters.network_name])
+        # check if a user is trying to find network by its Id
+        if not networks:
+            networks = self.client.networks(ids=[self.parameters.network_name])
+        if not networks:
+            return None
+        else:
+            return networks[0]
 
     def has_different_config(self, net):
         '''


Test patch: