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

Issue:
Add win_chocolatey proxy support
_From @ptemplier on September 23, 2016 12:33_

##### ISSUE TYPE
- Feature Pull Request
##### COMPONENT NAME

win_chocolatey
##### ANSIBLE VERSION

```
$ ansible --version
ansible 2.1.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
```
##### SUMMARY

Add win_chocolatey proxy support.
Add parameters to specify proxy url, user and password to be used when installing chocolatey and when installing package.
##### WORKAROUND

```
- name:  Check if chocolatey is installed
  win_stat: path='C:/ProgramData/chocolatey'
  register: choco_install

- name: Install Chocolatey using proxy
  raw: 'Set-ExecutionPolicy -ExecutionPolicy Unrestricted ; $wc=new-object net.webclient ; $proxy = New-Object System.Net.WebProxy("{{http_proxy_host}}:{{http_proxy_port}}", $true)  ; $wc.proxy=$proxy ; iex($wc.downloadstring("https://chocolatey.org/install.ps1"))'
  when: choco_install.stat.exists == False

- name: Chocolatey set proxy
  raw: 'choco config set proxy http://{{http_proxy_host}}:{{http_proxy_port}}'

- name: install curl
  win_chocolatey:
    name: curl
```


_Copied from original issue: ansible/ansible-modules-extras/pull/3022_


Discussion:
Cleaned up all the comments :-)
@ptemplier I think we need to add one or more maintainers for this module, because a lot of issues/PRs are stuck unreviewed (or reviewed by others).
https://github.com/ansible/ansible/pull/21476#issuecomment-282254613

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,6 +106,18 @@
     type: bool
     default: 'no'
     version_added: '2.4'
+  proxy_url:
+    description:
+      - Proxy url used to install chocolatey and the package
+    version_added: '2.4'
+  proxy_username:
+    description:
+      - Proxy username used to install chocolatey and the package
+    version_added: '2.4'
+  proxy_password:
+    description:
+      - Proxy password used to install chocolatey and the package
+    version_added: '2.4'
 notes:
 - Provide the C(version) parameter value as a string (e.g. C('6.1')), otherwise it
   is considered to be a floating-point number and depending on the locale could
@@ -115,6 +127,7 @@
 - Peter Mounce (@petemounce)
 - Pepe Barbe (@elventear)
 - Adam Keech (@smadam813)
+- Pierre Templier (@ptemplier)
 '''
 
 # TODO:
@@ -164,4 +177,11 @@
   with_items:
     - pscx
     - windirstat
+
+- name: Install curl using proxy
+  win_chocolatey:
+    name: curl
+    proxy_url: http://proxy-server:8080/
+    proxy_username: joe
+    proxy_password: p@ssw0rd
 '''


Test patch:
Repository: ansible/ansible

Issue:
broken ceph support in s3_bucket module
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
s3_bucket

##### ANSIBLE VERSION
```
ansible 2.3.0
  config file =
  configured module search path = Default w/o overrides
  python version = 3.5.2 (default, Sep 19 2016, 11:45:55) [GCC 4.9.1]
```

##### OS / ENVIRONMENT
N/A

##### SUMMARY
The s3_bucket module does not work at all with a ceph radosgw with `ceph=yes` and `state=present` (although it does work with `state=absent`). 

This is because commit 02ee3529 inadvertently made it impossible to reach the `_create_or_update_bucket_ceph` method by failing to pass `flavour` to `create_or_update_bucket`, and the `_create_or_update_bucket` method makes calls such as `get_policy` that are not supported by ceph.
broken ceph support in s3_bucket module
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
s3_bucket

##### ANSIBLE VERSION
```
ansible 2.3.0
  config file =
  configured module search path = Default w/o overrides
  python version = 3.5.2 (default, Sep 19 2016, 11:45:55) [GCC 4.9.1]
```

##### OS / ENVIRONMENT
N/A

##### SUMMARY
The s3_bucket module does not work at all with a ceph radosgw with `ceph=yes` and `state=present` (although it does work with `state=absent`). 

This is because commit 02ee3529 inadvertently made it impossible to reach the `_create_or_update_bucket_ceph` method by failing to pass `flavour` to `create_or_update_bucket`, and the `_create_or_update_bucket` method makes calls such as `get_policy` that are not supported by ceph.


Discussion:
cc @wimnat
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Can you please provide the playbook to reproduce the issue and the output?

needs_info
cc @wimnat
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Can you please provide the playbook to reproduce the issue and the output?

needs_info

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/s3_bucket.py b/lib/ansible/modules/cloud/amazon/s3_bucket.py
--- a/lib/ansible/modules/cloud/amazon/s3_bucket.py
+++ b/lib/ansible/modules/cloud/amazon/s3_bucket.py
@@ -434,7 +434,7 @@ def main():
     state = module.params.get("state")
 
     if state == 'present':
-        create_or_update_bucket(connection, module, location)
+        create_or_update_bucket(connection, module, location, flavour=flavour)
     elif state == 'absent':
         destroy_bucket(connection, module, flavour=flavour)
 


Test patch:
Repository: ansible/ansible

Issue:
docker_image task with archive_path loads an full image to a memory
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
docker_image

##### ANSIBLE VERSION
```
ansible 2.2.1.0
```

##### CONFIGURATION
<!---
N/A
-->

##### OS / ENVIRONMENT
N/A
##### SUMMARY
Executing a task of archiving docker image to tar-file completely loads it into memory before writing to HDD. It could result with out-of-memory error if image is bigger than available amount of memory.
It looks like for some reasons request goes not in a streaming way in this line https://github.com/ansible/ansible-modules-core/blob/d749ec91e513c40a50b539a7eaccf29c31dda4d4/cloud/docker/docker_image.py#L399
Maybe it is because of outdated version of requests-library or wrong usage of it?

##### STEPS TO REPRODUCE
1. Create a task like the below one.
```yaml
- delegate_to: localhost
  docker_image:
    name: "gcc" #size is ~1.5GB
    tag: latest
    pull: yes
    force: yes
    archive_path: "/tmp/gcc.tar"
```
2. Run htop to see the actual memory usage.
3. Run `ansible-playbook` for this task on a machine with 1GB memory.

##### EXPECTED RESULTS
Image is downloaded to tar archive on HDD.

##### ACTUAL RESULTS
Fatal error ```"msg": "Error writing image archive /tmp/gcc.tar - "``` error
Memory usage increases due to overflow.




Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/cloud/docker/docker_image.py b/lib/ansible/modules/cloud/docker/docker_image.py
--- a/lib/ansible/modules/cloud/docker/docker_image.py
+++ b/lib/ansible/modules/cloud/docker/docker_image.py
@@ -394,9 +394,9 @@ def archive_image(self, name, tag):
                 self.fail("Error getting image %s - %s" % (image_name, str(exc)))
 
             try:
-                image_tar = open(self.archive_path, 'w')
-                image_tar.write(image.data)
-                image_tar.close()
+                with open(self.archive_path, 'w') as fd:
+                    for chunk in image.stream(2048, decode_content=False):
+                        fd.write(chunk)
             except Exception as exc:
                 self.fail("Error writing image archive %s - %s" % (self.archive_path, str(exc)))
 


Test patch:
Repository: ansible/ansible

Issue:
syslog_json callback doesn't cast SYSLOG_PORT value from environment as integer
##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
syslog_json callback plugin

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.2.1.0
```

##### CONFIGURATION
Specifying SYSLOG_PORT environment variable to target a non-default port:
SYSLOG_PORT=1514

##### OS / ENVIRONMENT
Redhat 6 (but this should affect any UNIX platform)

##### SUMMARY
The syslog_json callback plugin allows configuration of its target port by specifying the SYSLOG_PORT environment variable; however, it doesn't cast the value it obtains from get_env as int, so specifying a port number this way results in errors  on each task and no syslog output:

Traceback (most recent call last):
  File "/usr/lib64/python2.6/logging/handlers.py", line 806, in emit
    self.socket.sendto(msg, self.address)
TypeError: an integer is required

##### STEPS TO REPRODUCE
For any playbook, specify the syslog_json callback plugin and the syslog port environment variable:

<!--- Paste example playbooks or commands between quotes below -->
```yaml
ANSIBLE_STDOUT_CALLBACK=syslog_json SYSLOG_PORT=1514 ansible-playbook playbook.yml
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
No output to stdout, JSON output directed to syslog for each task.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
Traceback (most recent call last):
  File "/usr/lib64/python2.6/logging/handlers.py", line 806, in emit
    self.socket.sendto(msg, self.address)
TypeError: an integer is required
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/plugins/callback/syslog_json.py b/lib/ansible/plugins/callback/syslog_json.py
--- a/lib/ansible/plugins/callback/syslog_json.py
+++ b/lib/ansible/plugins/callback/syslog_json.py
@@ -38,7 +38,7 @@ def __init__(self):
 
         self.handler = logging.handlers.SysLogHandler(
             address = (os.getenv('SYSLOG_SERVER','localhost'),
-                       os.getenv('SYSLOG_PORT',514)),
+                       int(os.getenv('SYSLOG_PORT',514))),
             facility= os.getenv('SYSLOG_FACILITY',logging.handlers.SysLogHandler.LOG_USER)
         )
         self.logger.addHandler(self.handler)


Test patch:
Repository: ansible/ansible

Issue:
NameError: global name 'existing' is not defined with ansible 2.3
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
- file module

##### ANSIBLE VERSION
- 2.3.0.0

##### OS / ENVIRONMENT
- CentOS 7

##### SUMMARY
1. building and installing the rpm package from stable-2.3 branch
2. use the *attributes* parameter from the file module (which as documented was added in 2.3)
3. met the error -> NameError: global name 'existing' is not defined

I checked the source code in lib/ansible/module_utils/basic.py, not sure where the var *existing* in ** line 1145: if existing.get('attr_flags','') != attributes: ** is defined




Discussion:
mistakenly removed by 237411613d03bf6dbd9d24fab0b2596ea864d01d
cc @dagwieers

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
@@ -1142,6 +1142,8 @@ def set_attributes_if_different(self, path, attributes, changed, diff=None, expa
             b_path = os.path.expanduser(os.path.expandvars(b_path))
         path = to_text(b_path, errors='surrogate_then_strict')
 
+        existing = self.get_file_attributes(b_path)
+
         if existing.get('attr_flags','') != attributes:
             attrcmd = self.get_bin_path('chattr')
             if attrcmd:


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. 
I was able to reproduce this bug. If rgw is used with a bucket name with a dot in it boto.connect_s3() is called with duplicate calling_format parameters.

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
@@ -714,6 +714,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,
@@ -723,6 +730,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:
Azure inventory fails with missing os_profile on certain machine types
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
contrib/inventory/azure_rm.py

##### ANSIBLE VERSION
```
ansible 2.2.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
```

##### CONFIGURATION
N/A

##### OS / ENVIRONMENT
N/A

##### SUMMARY
Running azure_rm.py crashes due to missing/None os_profile on certain virtual machines.

##### STEPS TO REPRODUCE
Run azure_rm.py to retrieve inventory from Azure, while having a VM set up with no os_profile
```yaml
python azure_rm.py
```

##### EXPECTED RESULTS
Inventory output by the script

##### ACTUAL RESULTS
```
Traceback (most recent call last):
  File "azure_rm.py", line 802, in <module>
    main()
  File "azure_rm.py", line 799, in main
    AzureInventory()
  File "azure_rm.py", line 442, in __init__
    self.get_inventory()
  File "azure_rm.py", line 507, in get_inventory
    self._load_machines(virtual_machines)
  File "azure_rm.py", line 541, in _load_machines
    computer_name=machine.os_profile.computer_name,
AttributeError: 'NoneType' object has no attribute 'computer_name'
```
Caused by the line:
```
computer_name=machine.os_profile.computer_name,
```
where machine.os_profile is None


Discussion:
Further error once the above is resolved (again relating to os_profile of None):
```
Traceback (most recent call last):
  File "azure_rm.py", line 802, in <module>
    main()
  File "azure_rm.py", line 799, in main
    AzureInventory()
  File "azure_rm.py", line 442, in __init__
    self.get_inventory()
  File "azure_rm.py", line 507, in get_inventory
    self._load_machines(virtual_machines)
  File "azure_rm.py", line 562, in _load_machines
    if machine.os_profile.windows_configuration is not None:
AttributeError: 'NoneType' object has no attribute 'windows_configuration'
```

Resolving patch:
diff --git a/contrib/inventory/azure_rm.py b/contrib/inventory/azure_rm.py
--- a/contrib/inventory/azure_rm.py
+++ b/contrib/inventory/azure_rm.py
@@ -538,7 +538,7 @@ def _load_machines(self, machines):
                 mac_address=None,
                 plan=(machine.plan.name if machine.plan else None),
                 virtual_machine_size=machine.hardware_profile.vm_size,
-                computer_name=machine.os_profile.computer_name,
+                computer_name=(machine.os_profile.computer_name if machine.os_profile else None),
                 provisioning_state=machine.provisioning_state,
             )
 
@@ -559,7 +559,7 @@ def _load_machines(self, machines):
                 )
 
             # Add windows details
-            if machine.os_profile.windows_configuration is not None:
+            if machine.os_profile is not None and machine.os_profile.windows_configuration is not None:
                 host_vars['windows_auto_updates_enabled'] = \
                     machine.os_profile.windows_configuration.enable_automatic_updates
                 host_vars['windows_timezone'] = machine.os_profile.windows_configuration.time_zone


Test patch:
Repository: ansible/ansible

Issue:
AWS profile for credstash lookup
##### ISSUE TYPE
 - Feature Idea

##### COMPONENT NAME
credstash lookup

##### ANSIBLE VERSION
```
ansible 2.2.1.0
  config file = /Users/alecdisharoon/.ansible.cfg
  configured module search path = Default w/o overrides
```

##### CONFIGURATION
N/A
##### OS / ENVIRONMENT
N/A
##### SUMMARY
It would be great if the credstash plugin would accept an AWS profile, the way many AWS modules do.  The credstash python library supports this, it's simply another keyword argument to pass into getSecret (as 'profile_name ', via 'get_session(**kwargs)').  
It's a pain to have to set environment variables for credstash when all other AWS-related Ansible modules allow the use of a boto profile.  
##### STEPS TO REPRODUCE
<!--- Paste example playbooks or commands between quotes below -->
```
mycoolvar: "{{ lookup('credstash', 'cred_name', region=region, profile=production) }}"
```
and
```
lappy:~ $ cat .aws/credentials
[production]
aws_access_key_id=KJLHKLJHLKJHKLJHK
aws_secret_access_key=ajkdshfkjashfkljahskldjfhasdkljfhaskljhfakd
```

##### EXPECTED RESULTS
This to be supported

##### ACTUAL RESULTS
Not actually supported.


Discussion:
needs_contributor

Resolving patch:
diff --git a/lib/ansible/plugins/lookup/credstash.py b/lib/ansible/plugins/lookup/credstash.py
--- a/lib/ansible/plugins/lookup/credstash.py
+++ b/lib/ansible/plugins/lookup/credstash.py
@@ -17,6 +17,8 @@
 from __future__ import (absolute_import, division, print_function)
 __metaclass__ = type
 
+import os
+
 from ansible.errors import AnsibleError
 from ansible.plugins.lookup import LookupBase
 
@@ -41,8 +43,14 @@ def run(self, terms, variables, **kwargs):
                 version = kwargs.pop('version', '')
                 region = kwargs.pop('region', None)
                 table = kwargs.pop('table', 'credential-store')
+                profile_name = kwargs.pop('profile_name', os.getenv('AWS_PROFILE', None))
+                aws_access_key_id = kwargs.pop('aws_access_key_id', os.getenv('AWS_ACCESS_KEY_ID', None))
+                aws_secret_access_key = kwargs.pop('aws_secret_access_key', os.getenv('AWS_SECRET_ACCESS_KEY', None))
+                aws_session_token = kwargs.pop('aws_session_token', os.getenv('AWS_SESSION_TOKEN', None))
+                kwargs_pass = {'profile_name': profile_name, 'aws_access_key_id': aws_access_key_id,
+                               'aws_secret_access_key': aws_secret_access_key, 'aws_session_token': aws_session_token}
                 val = credstash.getSecret(term, version, region, table,
-                                          context=kwargs)
+                                          context=kwargs, **kwargs_pass)
             except credstash.ItemNotFound:
                 raise AnsibleError('Key {0} not found'.format(term))
             except Exception as e:


Test patch:
Repository: ansible/ansible

Issue:
zfs bad volume block size
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
zfs

##### ANSIBLE VERSION
```
ansible 2.2.2.0
  config file = 
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

##### OS / ENVIRONMENT
N/A

##### SUMMARY
zfs bad volume block size with volblocksize property

https://github.com/ansible/ansible/blob/eb1214baad0cbe2c4b7304caebb9ae1c7dc0d8db/lib/ansible/modules/storage/zfs/zfs.py#L151
replace
```
if volblocksize:
    cmd += ['-b', 'volblocksize']
```
by 
```
if volblocksize:
   cmd += ['-b', volblocksize]
```
without simple quote to get `volblocksize` value

##### STEPS TO REPRODUCE
```
- name: Create ZFS vol ztest/myblockdevice
  zfs:
    name: "ztest/myblockdevice"
    state: present
    volsize: "10G"
    volblocksize: "512"
```

##### EXPECTED RESULTS
ok

##### ACTUAL RESULTS
failed



Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/storage/zfs/zfs.py b/lib/ansible/modules/storage/zfs/zfs.py
--- a/lib/ansible/modules/storage/zfs/zfs.py
+++ b/lib/ansible/modules/storage/zfs/zfs.py
@@ -167,7 +167,7 @@ def create(self):
         if volsize:
             cmd += ['-V', volsize]
         if volblocksize:
-            cmd += ['-b', 'volblocksize']
+            cmd += ['-b', volblocksize]
         if properties:
             for prop, value in properties.items():
                 cmd += ['-o', '%s="%s"' % (prop, value)]


Test patch: