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

Issue:
password_hash filter doesn't use full character set when generating a salt
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME

password_hash filter

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/willmerae/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
```

##### CONFIGURATION

##### OS / ENVIRONMENT
N/A

##### SUMMARY
In a template the filter `{{ 'some string' | password_hash }}` or `{{ 'some string' | password_hash(hashtype='sha256') }}` will return a crypt formatted hash of the string in question. This format is `$<hashtype>$<salt>$<hash>. Where `hashtype` is a code indicating the has algorithm (e.g. `6` = sha512), and salt is a random value used to make the hash unique.

According to [man crypt(3)](http://man7.org/linux/man-pages/man3/crypt.3.html) the character set for the salt is `A-Za-z0-9/.`, but if no salt is provided then Ansible only uses `A-Za-z0-9` when generating a new salt. The offending code is in `ansible.plugins.filter.core.get_encrypted_password`

```python
salt = ''.join([r.choice(string.ascii_letters + string.digits) for _ in range(saltsize)])
```

The result is hash is still usable, but the strength is weakened slightly due to the smaller key space.

##### STEPS TO REPRODUCE
```yaml
ansible -i localhost, localhost -mdebug -a"msg={{ 'foo' | password_hash }}" -o
```

##### EXPECTED RESULTS
Generated salts may include `/` and '.'. 

##### ACTUAL RESULTS
Generated salts never include `/` or `.`.

```
localhost | SUCCESS => {    "changed": false,     "msg": "$6$2YpulGE5GSC8RYhp$txhd8h6r9fts/bQjcrKft8lkn0GRwImVeVpN/ZwBNK9OPJogJTzs8P/7xEJAWyK/Eca.UU4v2/nfJSvlMnDNv/"}

```


Discussion:

Resolving patch:
diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py
--- a/lib/ansible/plugins/filter/core.py
+++ b/lib/ansible/plugins/filter/core.py
@@ -256,7 +256,8 @@ def get_encrypted_password(password, hashtype='sha512', salt=None):
                 saltsize = 8
             else:
                 saltsize = 16
-            salt = ''.join([r.choice(string.ascii_letters + string.digits) for _ in range(saltsize)])
+            saltcharset = string.ascii_letters + string.digits + '/.'
+            salt = ''.join([r.choice(saltcharset) for _ in range(saltsize)])
 
         if not HAS_PASSLIB:
             if sys.platform.startswith('darwin'):


Test patch:
Repository: ansible/ansible

Issue:
Cannot build deb on debian8 without editing Makefile
##### ISSUE TYPE
 - Bug Report
##### COMPONENT NAME
make deb fails

##### ANSIBLE VERSION
Clone of ansible/ansible as of today. a0344acd78c422457b5a018b9de59e213f39dc87

##### CONFIGURATION
docker run -ti debian:8 /bin/bash
apt-get install the following
git, make, python-sphinx, python-yaml, asciidoc, python-setuptools
git clone 
https://github.com/ansible/ansible
cd ansible
make deb
##### OS / ENVIRONMENT
See above, debian 8 docker image
##### SUMMARY
When running make deb on debian 8, you get the following error.
```
Traceback (most recent call last):
  File "./docs/bin/generate_man.py", line 128, in <module>
    f.write(manpage)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in position 4964: ordinal not in range(128)
Makefile:306: recipe for target 'docs' failed
make: *** [docs] Error 1
```
I was able to work around this, by removing the doc section in the Makefile, but this is not an ideal long term solution.
##### STEPS TO REPRODUCE
See configuration section.

##### EXPECTED RESULTS
Produces a deb

##### ACTUAL RESULTS
Throws a traceback



Discussion:
I think this is the fix:
```
--- a/docs/bin/generate_man.py
+++ b/docs/bin/generate_man.py
@@ -1,11 +1,12 @@
 #!/usr/bin/env python
 
 import os
-import io
 import sys
 
 from jinja2 import Environment, FileSystemLoader
 
+from ansible.module_utils._text import to_bytes
+
 
 def get_options(optlist):
     ''' get actual options '''
@@ -124,6 +125,6 @@ if __name__ == '__main__':
 
         manpage = template.render(tvars)
         filename = '../man/man1/%s' % output[libname]
-        with io.open(filename, 'w') as f:
-            f.write(manpage)
+        with open(filename, 'wb') as f:
+            f.write(to_bytes(manpage))
             print("Wrote man docs to %s" % filename)
```

Will talk to bcoca after the meeting to see why we're using io.open() right now, though, then push a PR.

Resolving patch:
diff --git a/docs/bin/generate_man.py b/docs/bin/generate_man.py
--- a/docs/bin/generate_man.py
+++ b/docs/bin/generate_man.py
@@ -1,11 +1,12 @@
 #!/usr/bin/env python
 
 import os
-import io
 import sys
 
 from jinja2 import Environment, FileSystemLoader
 
+from ansible.module_utils._text import to_bytes
+
 
 def get_options(optlist):
     ''' get actual options '''
@@ -124,6 +125,6 @@ def opts_docs(cli, name):
 
         manpage = template.render(tvars)
         filename = '../man/man1/%s' % output[libname]
-        with io.open(filename, 'w') as f:
-            f.write(manpage)
+        with open(filename, 'wb') as f:
+            f.write(to_bytes(manpage))
             print("Wrote man docs to %s" % filename)


Test patch:
Repository: ansible/ansible

Issue:
module_utils/eos.py: supports_sessions defined twice
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
module_utils/eos.py

##### ANSIBLE VERSION
```
ansible 2.4.0 (devel 9a43603761) last updated 2017/04/03 19:18:59 (GMT +100)

```

##### SUMMARY
Two functions, different cde


Discussion:

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
@@ -111,10 +111,6 @@ def check_authorization(self):
             rc, out, err = self.exec_command(cmd)
         return out.endswith('#')
 
-    def supports_sessions(self):
-        rc, out, err = self.exec_command('show configuration sessions')
-        return rc == 0
-
     def get_config(self, flags=[]):
         """Retrieves the current config from the device or cache
         """


Test patch:
Repository: ansible/ansible

Issue:
[python3] copy module broken when using diff and binary files
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
[copy] python3

##### ANSIBLE VERSION
```
ansible 2.4.0 (commit 1fd58c295cbbd9183c0f9702ee7eab6407365e9a)
  config file = /Users/jddupas/Projects/python/playbooks/app/ansible.cfg
  configured module search path = ['/Users/jddupas/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  python version = 3.5.3 (default, Jan 21 2017, 15:44:58) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
```

##### CONFIGURATION


##### OS / ENVIRONMENT
macOS Sierra

##### SUMMARY
When using the copy module in diff mode (using ansible-playbook -D), the module crash if one of the copied file is a binary file. Note: Python3 is used only on the ansible host side, not on the remote machines.

```
fatal: [vpnprx]: FAILED! => {"failed": true, "msg": "Unexpected error while reading source (/Users/jddupas/Projects/python/playbooks/app/roles/squid/files/xolcheck) for diff: 'utf-8' codec can't decode byte 0x85 in position 25: invalid start byte "}
```

While doing the same operation using python2, the copy module properly detect the file is a binary file and report a warning instead of raising an exception.

##### STEPS TO REPRODUCE
Create a playbook with a simple 'copy' step that copy a binary file.

Launch the playbook using -D to see diff.
Update the binary file.
Launch the playbook using -D to see diff.

##### EXPECTED RESULTS
copy tells me that it can't diff binary file and proceed.

##### ACTUAL RESULTS
copy crash.




Discussion:

Resolving patch:
diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py
--- a/lib/ansible/plugins/action/__init__.py
+++ b/lib/ansible/plugins/action/__init__.py
@@ -952,12 +952,12 @@ def _get_diff_data(self, destination, source, task_vars, source_file=True):
                 else:
                     display.debug("Reading local copy of the file %s" % source)
                     try:
-                        src = open(source)
-                        src_contents = src.read()
+                        with open(source, 'rb') as src:
+                            src_contents = src.read()
                     except Exception as e:
                         raise AnsibleError("Unexpected error while reading source (%s) for diff: %s " % (source, str(e)))
 
-                    if "\x00" in src_contents:
+                    if b"\x00" in src_contents:
                         diff['src_binary'] = 1
                     else:
                         diff['after_header'] = source


Test patch:
Repository: ansible/ansible

Issue:
add_host doesn't add/update hostvars for an inventory-defined host
When using add_host for a new hostname, the plugin correctly adds the host/group and any custom variables, and subsequent calls will add/update as expected. If the hostname already exists in the inventory, however, it does not get updated.



Discussion:
What is "ansible --version"?

Always include this when reporting bugs.

Also, can you please provide a playbook you are using that showcases the problem?

I am unable to reproduce this with the current head of devel (f270777):

<pre>
$ cat test_4808.yml 
---
- hosts: localhost
  connection: local
  gather_facts: false
  tasks:
  - add_host: hostname=localhost ansible_ssh_hostname=127.0.0.2
- hosts: localhost
  connection: local
  gather_facts: false
  tasks:
  - debug: var=foo
$ cat inventory_4808 
localhost
$ cat host_vars/localhost 
---
foo: bar
$ ansible-playbook test_4808.yml -i inventory_4808 
PLAY [localhost] ************************************************************** 
TASK: [add_host hostname=localhost ansible_ssh_hostname=127.0.0.2] ************ 
ok: [localhost]
PLAY [localhost] ************************************************************** 
TASK: [debug var=foo] ********************************************************* 
ok: [localhost] => {
    "foo": "bar"
}
PLAY RECAP ******************************************************************** 
localhost                  : ok=2    changed=0    unreachable=0    failed=0   
</pre>

Closing due to no feedback on the above.

Thanks!


Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/rds.py b/lib/ansible/modules/cloud/amazon/rds.py
--- a/lib/ansible/modules/cloud/amazon/rds.py
+++ b/lib/ansible/modules/cloud/amazon/rds.py
@@ -50,7 +50,8 @@
       - mariadb was added in version 2.2
     required: false
     default: null
-    choices: ['mariadb', 'MySQL', 'oracle-se1', 'oracle-se', 'oracle-ee', 'sqlserver-ee', 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web', 'postgres', 'aurora']
+    choices: ['mariadb', 'MySQL', 'oracle-se1', 'oracle-se2', 'oracle-se', 'oracle-ee',
+              'sqlserver-ee', 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web', 'postgres', 'aurora']
   size:
     description:
       - Size in gigabytes of the initial storage for the DB instance. Used only when command=create or command=modify.
@@ -1316,7 +1317,7 @@ def main():
         command=dict(choices=['create', 'replicate', 'delete', 'facts', 'modify', 'promote', 'snapshot', 'reboot', 'restore'], required=True),
         instance_name=dict(required=False),
         source_instance=dict(required=False),
-        db_engine=dict(choices=['mariadb', 'MySQL', 'oracle-se1', 'oracle-se', 'oracle-ee', 'sqlserver-ee', 'sqlserver-se', 'sqlserver-ex',
+        db_engine=dict(choices=['mariadb', 'MySQL', 'oracle-se1', 'oracle-se2', 'oracle-se', 'oracle-ee', 'sqlserver-ee', 'sqlserver-se', 'sqlserver-ex',
                                 'sqlserver-web', 'postgres', 'aurora'], required=False),
         size=dict(required=False),
         instance_type=dict(aliases=['type'], required=False),


Test patch:
Repository: ansible/ansible

Issue:
Fix select loop reading from SSH channel
When select() returns a list of file descriptors with data waiting, they
_all_ need to be flushed. The current logic will _not_ empty stderr if
EOF is encountered on stdout, due to the 'break' statement.

I've rewritten the loop the way I think it should be.

Signed-off-by: martin f. krafft madduck@madduck.net



Discussion:
What is the observed vs expected behavior in this bug as witnessed by a user?

I only encountered it while researching the lack of output on `stderr` (#3309). And since there will never be data on `stderr`, at least as long as you force the use of PTYs, this patch is not needed. But the code I fixed is not a proper `select` loop and if ever the PTY situation changes, this could come to haunt you. Thus I propose fixing it now, especially since I have done the work already.

Agreeing with user that this patch is not needed.


Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/ec2_metric_alarm.py b/lib/ansible/modules/cloud/amazon/ec2_metric_alarm.py
--- a/lib/ansible/modules/cloud/amazon/ec2_metric_alarm.py
+++ b/lib/ansible/modules/cloud/amazon/ec2_metric_alarm.py
@@ -197,7 +197,9 @@ def create_metric_alarm(connection, module):
 
         for attr in ('alarm_actions','insufficient_data_actions','ok_actions'):
             action = module.params.get(attr) or []
-            if getattr(alarm, attr) != action:
+            # Boto and/or ansible may provide same elements in lists but in different order.
+            # Compare on sets since they do not need any order.
+            if set(getattr(alarm, attr)) != set(action):
                 changed = True
                 setattr(alarm, attr, module.params.get(attr))
 


Test patch:
Repository: ansible/ansible

Issue:
ecs_taskdefinition module : Convert environment variables to string
##### SUMMARY

In this module, if the `containers` - `environment` variable is not a string type, it will result in an error.

This fix converts the value of the `containers` - `environment` variable to a string type.

##### ISSUE TYPE

 - Bugfix Pull Request

##### COMPONENT NAME

ecs_taskdefinition

##### ANSIBLE VERSION

2.2.2.0



Discussion:
cc @simplesteph @Java1Guy @rmorlok
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Note to core team: this bugfix may need backporting to stable-2.3 & stable-2.2
@nazo Thanks for the patch, we can look at pulling this in once one of @simplesteph @Java1Guy @rmorlok have looked at it.
@nazo thanks for the PR. Looks good to me.
cc @gundalow
shipit
Merged into `devel` and cherry-picked into `stable-2.3`
https://github.com/ansible/ansible/commit/84d09cdf32a4eb571919d81780186f8c488997a2

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py b/lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py
--- a/lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py
+++ b/lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py
@@ -240,6 +240,11 @@ def main():
     task_mgr = EcsTaskManager(module)
     results = dict(changed=False)
 
+    for container in module.params['containers']:
+        if 'environment' in container:
+            for environment in container['environment']:
+                environment['value'] = str(environment['value'])
+
     if module.params['state'] == 'present':
         if 'containers' not in module.params or not module.params['containers']:
             module.fail_json(msg="To use task definitions, a list of containers must be specified")
@@ -352,10 +357,6 @@ def _task_definition_matches(requested_volumes, requested_containers, existing_t
             if not module.check_mode:
                 # Doesn't exist. create it.
                 volumes = module.params.get('volumes', []) or []
-                for container in module.params['containers']:
-                    if 'environment' in container:
-                        for environment in container['environment']:
-                            environment['value'] = str(environment['value'])
                 results['taskdefinition'] = task_mgr.register_task(module.params['family'],
                                                                    module.params['task_role_arn'],
                                                                    module.params['network_mode'],


Test patch:
Repository: ansible/ansible

Issue:
Amazon SNS module doesnt show up in cloud modules list
##### ISSUE TYPE
Documentation Report

##### COMPONENT NAME
sns module

##### ANSIBLE VERSION
2.1

##### CONFIGURATION


##### OS / ENVIRONMENT


##### SUMMARY
This link http://docs.ansible.com/ansible/sns_module.html does not appear on the Cloud Modules page:

http://docs.ansible.com/ansible/list_of_cloud_modules.html


##### STEPS TO REPRODUCE


##### EXPECTED RESULTS


##### ACTUAL RESULTS



Amazon SNS module doesnt show up in cloud modules list
##### ISSUE TYPE
Documentation Report

##### COMPONENT NAME
sns module

##### ANSIBLE VERSION
2.1

##### CONFIGURATION


##### OS / ENVIRONMENT


##### SUMMARY
This link http://docs.ansible.com/ansible/sns_module.html does not appear on the Cloud Modules page:

http://docs.ansible.com/ansible/list_of_cloud_modules.html


##### STEPS TO REPRODUCE


##### EXPECTED RESULTS


##### ACTUAL RESULTS





Discussion:
cc @mjschultz
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @mjschultz
[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/notification/sns.py b/lib/ansible/modules/cloud/amazon/sns.py
similarity index 98%
rename from lib/ansible/modules/notification/sns.py
rename to lib/ansible/modules/cloud/amazon/sns.py
--- a/lib/ansible/modules/notification/sns.py
+++ b/lib/ansible/modules/cloud/amazon/sns.py
@@ -200,9 +200,9 @@ def main():
         e = get_exception()
         module.fail_json(msg=str(e))
 
-    if not message_structure=='string' and message_attributes:
+    if not message_structure == 'string' and message_attributes:
         module.fail_json(msg="when specifying message_attributes, the message_structure must be set to 'string'; otherwise the attributes will not be sent.")
-    elif message_structure=='string' and (email or sqs or sms or http or https):
+    elif message_structure == 'string' and (email or sqs or sms or http or https):
         module.fail_json(msg="do not specify non-default message formats when using the 'string' message_structure. they can only be used with "
                              "the 'json' message_structure.")
 


Test patch:
diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt
--- a/test/sanity/pep8/legacy-files.txt
+++ b/test/sanity/pep8/legacy-files.txt
@@ -652,7 +652,6 @@ lib/ansible/modules/notification/pushover.py
 lib/ansible/modules/notification/rocketchat.py
 lib/ansible/modules/notification/sendgrid.py
 lib/ansible/modules/notification/slack.py
-lib/ansible/modules/notification/sns.py
 lib/ansible/modules/notification/twilio.py
 lib/ansible/modules/packaging/language/bundler.py
 lib/ansible/modules/packaging/language/cpanm.py
Repository: ansible/ansible

Issue:
puppet module execute parameter ignored
##### ISSUE TYPE
 - Bug Report


##### COMPONENT NAME
modules/system/puppet.py

##### ANSIBLE VERSION
```
ansible 2.3.0.0
  config file =
  configured module search path = Default w/o overrides
  python version = 2.7.10 (default, Jul 30 2016, 19:40:32) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]
```

##### CONFIGURATION
ANSIBLE_NOCOWS=1
ANSIBLE_SSH_PIPLINEING=1

##### OS / ENVIRONMENT
mac osx 10.12.3

##### SUMMARY
when using the puppet module execute function a full `puppet agent -t` run is preformed instead

##### STEPS TO REPRODUCE
<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Disable puppet cron job
  puppet:
    execute: 'cron {"puppet_conf: Kick puppet" : ensure => absent }'
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
runs the following command
`puppet apply -e 'cron {"puppet_conf: Kick puppet" : ensure => absent }`

##### ACTUAL RESULTS
ran `puppet agent -t`



Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/system/puppet.py b/lib/ansible/modules/system/puppet.py
--- a/lib/ansible/modules/system/puppet.py
+++ b/lib/ansible/modules/system/puppet.py
@@ -219,7 +219,7 @@ def main():
     else:
         base_cmd = PUPPET_CMD
 
-    if not p['manifest']:
+    if not p['manifest'] and not p['execute']:
         cmd = ("%(base_cmd)s agent --onetime"
                " --ignorecache --no-daemonize --no-usecacheonfailure --no-splay"
                " --detailed-exitcodes --verbose --color 0") % dict(
@@ -247,15 +247,16 @@ def main():
             cmd += "--environment '%s' " % p['environment']
         if p['certname']:
             cmd += " --certname='%s'" % p['certname']
-        if p['execute']:
-            cmd += " --execute '%s'" % p['execute']
         if p['tags']:
             cmd += " --tags '%s'" % ','.join(p['tags'])
         if module.check_mode:
             cmd += "--noop "
         else:
             cmd += "--no-noop "
-        cmd += pipes.quote(p['manifest'])
+        if p['execute']:
+            cmd += " --execute '%s'" % p['execute']
+        else:
+            cmd += pipes.quote(p['manifest'])
     rc, stdout, stderr = module.run_command(cmd)
 
     if rc == 0:


Test patch: