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

Issue:
ec2_vol errors when attaching a volume from a snapshot
**Issue type:**

Bug report

**Ansible Version:**

1.6.2

**Environment:**

Mac OS X 10.9.3

**Summary:**

ec2_vol module fails to create a new volume from a snapshot and attach to an image, returning an error message that doesn't make sense given the arguments.

**Steps to reproduce:**
1. Start an instance on EC2, record the instance id
2. Create a new snapshot on EC2, record the snapshot id
3. Use the ec2_vol module to attach:
   
   ```
   ansible localhost -m ec2_vol -a "instance=i-123456 snapshot=snap-abcdef"
   ```

**Expected results:**

Creates a new EBS volume from the snapshot, attaches volume to the instance.

**Actual results:**

```
$ ansible localhost -m ec2_vol -a "instance=i-123456 snapshot=snap-abcdef"
localhost | FAILED >> {
    "failed": true,
    "msg": "Cannot specify volume_size and either one of name or id"
}
```

The error makes no sense, given that neither volume_size, name, nor id are arguments.

Note that the documentation for ec2_vol has an example with this exact combination of arguments, so I assume this is legal. From the docs:

```
# Example using snapshot id
- local_action:
    module: ec2_vol
    instance: XXXXXX
    snapshot: "{{ snapshot }}"
```



Discussion:
Not sure why the bot triggered, the report appears to conform to the template.

With:

ec2_vol: region="{{region}}" device_name=sdd instance=i-xxxxxxxx snapshot=snap-xxxxxxxx

I get:

msg: You must specify an existing volume with id or name or a volume_size

I have written a script to do "aws ec2 create-volume" and then "aws ec2 attach-volume" since that AWS CLI seems to imply it is a two-step process.  I can't re-create this sequence with ec2_vol since I can not specify availability zone which is required in the AWS CLI create volume step.  The implication here is that availability zone will be derived from instance id so I don't see any way to clone a volume from a snapshot with this module.  :/


Resolving patch:
diff --git a/cloud/amazon/ec2_vol.py b/cloud/amazon/ec2_vol.py
--- a/cloud/amazon/ec2_vol.py
+++ b/cloud/amazon/ec2_vol.py
@@ -436,11 +436,11 @@ def main():
 
     # Delaying the checks until after the instance check allows us to get volume ids for existing volumes
     # without needing to pass an unused volume_size
-    if not volume_size and not (id or name):
-        module.fail_json(msg="You must specify an existing volume with id or name or a volume_size")
+    if not volume_size and not (id or name or snapshot):
+        module.fail_json(msg="You must specify volume_size or identify an existing volume by id, name, or snapshot")
 
-    if volume_size and id:
-        module.fail_json(msg="Cannot specify volume_size and id")
+    if volume_size and (id or snapshot):
+        module.fail_json(msg="Cannot specify volume_size together with id or snapshot")
 
     if state == 'absent':
         delete_volume(module, ec2)


Test patch:
Repository: ansible/ansible-modules-core

Issue:
add readonly flag to docker module
It will be very useful to have ability to launch docker container in readonly mode with readonly flag (as in docker run --read-only)



Discussion:

Resolving patch:
diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py
--- a/cloud/docker/docker.py
+++ b/cloud/docker/docker.py
@@ -265,6 +265,12 @@
     default: DockerHub
     aliases: []
     version_added: "1.8"
+  read_only:
+    description:
+      - Mount the container's root filesystem as read only
+    default: false
+    aliases: []
+    version_added: "2.0"
   restart_policy:
     description:
       - Container restart policy.
@@ -565,6 +571,7 @@ class DockerManager(object):
             'cpu_set': ((0, 6, 0), '1.14'),
             'cap_add': ((0, 5, 0), '1.14'),
             'cap_drop': ((0, 5, 0), '1.14'),
+            'read_only': ((1, 0, 0), '1.17'),
             # Clientside only
             'insecure_registry': ((0, 5, 0), '0.0')
             }
@@ -786,6 +793,7 @@ def get_start_params(self):
             'privileged': self.module.params.get('privileged'),
             'links': self.links,
             'network_mode': self.module.params.get('net'),
+            'read_only': self.module.params.get('read_only'),
         }
 
         optionals = {}
@@ -1634,6 +1642,7 @@ def main():
             cpu_set         = dict(default=None),
             cap_add         = dict(default=None, type='list'),
             cap_drop        = dict(default=None, type='list'),
+            read_only       = dict(default=False, type='bool'),
         ),
         required_together = (
             ['tls_client_cert', 'tls_client_key'],


Test patch:
Repository: ansible/ansible-modules-core

Issue:
Enabling/Disabling of service fails if enable_cmd is insserv and insserv returns warnings
This example message lets the task fail although rc of insserv is 0:

```
"msg": 
   "Failed to install service. rc: 0, out: , 
    err: insserv: warning: script 'S17lockgcstartup' missing LSB tags and overrides\n
    insserv: warning: script 'K01gcstartup' missing LSB tags and overrides\n 
    insserv: warning: script 'K01unlockgcstartup' missing LSB tags and overrides\n
    insserv: warning: script 'lockgcstartup' missing LSB tags and overrides\n
    insserv: warning: script 'unlockgcstartup' missing LSB tags and overrides\n
    insserv: warning: current stop runlevel(s) (3 5) of script `unlockgcstartup' overwrites defaults (empty).\n
    insserv: Default-Start undefined, assuming default start runlevel(s) for script `unlockgcstartup'\n
    insserv: script nsrps is broken: incomplete LSB comment.\n
    insserv: missing `Provides:' entry: please add.\n
    insserv: warning: script 'init.ohasd' missing LSB tags and overrides\n
    insserv: Default-Start undefined, assuming default start runlevel(s) for script `init.ohasd'\n
    insserv: warning: script 'gcstartup' missing LSB tags and overrides\n
    insserv: Service network is missed in the runlevels 4 to use service rhnsd\n
    insserv: Service syslog is missed in the runlevels 4 to use service aurad\n",
"failed": true
```

OS: SLES 11 SP2/3



Discussion:

Resolving patch:
diff --git a/system/service.py b/system/service.py
--- a/system/service.py
+++ b/system/service.py
@@ -827,12 +827,12 @@ def write_to_override_file(file_name, file_contents, ):
 
             if self.enable:
                 (rc, out, err) = self.execute_command("%s %s" % (self.enable_cmd, self.name))
-                if (rc != 0) or (err != ''):
+                if (rc != 0):
                     self.module.fail_json(msg=("Failed to install service. rc: %s, out: %s, err: %s" % (rc, out, err)))
                 return (rc, out, err)
             else:
                 (rc, out, err) = self.execute_command("%s -r %s" % (self.enable_cmd, self.name))
-                if (rc != 0) or (err != ''):
+                if (rc != 0):
                     self.module.fail_json(msg=("Failed to remove service. rc: %s, out: %s, err: %s" % (rc, out, err)))
                 return (rc, out, err)
 


Test patch:
Repository: ansible/ansible-modules-core

Issue:
rpm_key: Fedora 22: Failed to find required executable gpg
Fedora 22 has no gpg executable but only gpg2.

Is it my responsibility to provide a link gpg -> gpg2 or should the module cover this out of the box?



Discussion:
Since it is not entirely clear to me whether this is considered a bug or not I started a thread on ansible-project. Once this is clarified I might reopen the ticket here.

Brian suggested to open a bug for this - so I'm reopening it.


Resolving patch:
diff --git a/packaging/os/rpm_key.py b/packaging/os/rpm_key.py
--- a/packaging/os/rpm_key.py
+++ b/packaging/os/rpm_key.py
@@ -141,7 +141,14 @@ def normalize_keyid(self, keyid):
             return ret
 
     def getkeyid(self, keyfile):
-        gpg = self.module.get_bin_path('gpg', True)
+
+        gpg = self.module.get_bin_path('gpg')
+        if not gpg:
+            gpg = self.module.get_bin_path('gpg2')
+
+        if not gpg:
+            self.json_fail(msg="rpm_key requires a command line gpg or gpg2, none found")
+
         stdout, stderr = self.execute_command([gpg, '--no-tty', '--batch', '--with-colons', '--fixed-list-mode', '--list-packets', keyfile])
         for line in stdout.splitlines():
             line = line.strip()


Test patch:
Repository: ansible/ansible-modules-core

Issue:
Add support for S3 permissions
The amazon s3 module does not currently support setting permissions on buckets or objects. By default, all buckets are private.

Boto's S3 interface does support the use of canned ACL's.
See: http://boto.readthedocs.org/en/latest/s3_tut.html



Discussion:

Resolving patch:
diff --git a/cloud/amazon/s3.py b/cloud/amazon/s3.py
--- a/cloud/amazon/s3.py
+++ b/cloud/amazon/s3.py
@@ -93,6 +93,12 @@
       - Keyname of the object inside the bucket. Can be used to create "virtual directories", see examples.
     required: false
     default: null
+  permission:
+    description:
+      - This option let's the user set the canned permissions on the object/bucket that are created. The permissions that can be set are 'private', 'public-read', 'public-read-write', 'authenticated-read'.
+    required: false
+    default: private
+    version_added: "2.0"
   prefix:
     description:
       - Limits the response to keys that begin with the specified prefix for list mode
@@ -167,7 +173,7 @@
 - s3: bucket=mybucket mode=list prefix=/my/desired/ marker=/my/desired/0023.txt max_keys=472
 
 # Create an empty bucket
-- s3: bucket=mybucket mode=create
+- s3: bucket=mybucket mode=create permission=public-read
 
 # Create a bucket with key as directory, in the EU region
 - s3: bucket=mybucket object=/my/directory/path mode=create region=eu-west-1
@@ -236,6 +242,7 @@ def create_bucket(module, s3, bucket, location=None):
         location = Location.DEFAULT
     try:
         bucket = s3.create_bucket(bucket, location=location)
+        bucket.set_acl(module.params.get('permission'))
     except s3.provider.storage_response_error, e:
         module.fail_json(msg= str(e))
     if bucket:
@@ -306,6 +313,7 @@ def upload_s3file(module, s3, bucket, obj, src, expiry, metadata, encrypt, heade
                 key.set_metadata(meta_key, metadata[meta_key])
 
         key.set_contents_from_filename(src, encrypt_key=encrypt, headers=headers)
+        key.set_acl(module.params.get('permission'))
         url = key.generate_url(expiry)
         module.exit_json(msg="PUT operation complete", url=url, changed=True)
     except s3.provider.storage_copy_error, e:
@@ -378,6 +386,7 @@ def main():
             metadata       = dict(type='dict'),
             mode           = dict(choices=['get', 'put', 'delete', 'create', 'geturl', 'getstr', 'delobj', 'list'], required=True),
             object         = dict(),
+            permission     = dict(choices=['private', 'public-read', 'public-read-write', 'authenticated-read'], default='private'),
             version        = dict(default=None),
             overwrite      = dict(aliases=['force'], default='always'),
             prefix         = dict(default=None),


Test patch:
Repository: ansible/ansible-modules-core

Issue:
"apt upgrade=dist" incorrectly reports changed=false if number of upgraded packages is a multiple of 10
That's because the string "0 upgraded" is in "10 upgraded":

 if (apt_cmd == APT_GET_CMD and APT_GET_ZERO in out) or (apt_cmd == APTITUDE_CMD and APTITUDE_ZERO in out):
   m.exit_json(changed=False, msg=out, stdout=out, stderr=err)
   m.exit_json(changed=True, msg=out, stdout=out, stderr=err)

https://github.com/ansible/ansible-modules-core/blob/devel/packaging/os/apt.py#L535



Discussion:
he, the 'in out' is matching starting at the 0, need to check if that is start of line or has a space in front


Resolving patch:
diff --git a/packaging/os/apt.py b/packaging/os/apt.py
old mode 100644
new mode 100755
--- a/packaging/os/apt.py
+++ b/packaging/os/apt.py
@@ -179,8 +179,8 @@
 )
 
 DPKG_OPTIONS = 'force-confdef,force-confold'
-APT_GET_ZERO = "0 upgraded, 0 newly installed"
-APTITUDE_ZERO = "0 packages upgraded, 0 newly installed"
+APT_GET_ZERO = "\n0 upgraded, 0 newly installed"
+APTITUDE_ZERO = "\n0 packages upgraded, 0 newly installed"
 APT_LISTS_PATH = "/var/lib/apt/lists"
 APT_UPDATE_SUCCESS_STAMP_PATH = "/var/lib/apt/periodic/update-success-stamp"
 


Test patch:
Repository: ansible/ansible-modules-core

Issue:
Cannot use rds modify to increase storage size on Postgresql databases
##### Issue Type:

Bug Report
##### Ansible Version:

ansible 1.8.2
  configured module search path = None
##### Environment:

N/A
##### Summary:

Attempting to increase the size of an RDS instance using rds modify silently fails. I tested using Postgres, but it may affect other database engines
##### Steps To Reproduce:

```

---
- hosts: local
  connection: local
  gather_facts: False
  tasks:

    - name: Provision Postgresql RDS
      rds:
        command: create
        region: us-east-1
        instance_name: rds-resize-test
        db_engine: postgres
        port: 5432
        size: 5
        instance_type: db.t1.micro
        username: rds_resize_test
        password: rds_resize_test
        wait: yes
        wait_timeout: 1200 
      register: rds

    - name: Convert Postgresql RDS instance to SSD storage
      rds:
        command: modify
        region: us-east-1
        instance_name: rds-resize-test
        size: 10
        apply_immediately: yes
        wait: yes
        wait_timeout: 1200 
```
##### Expected Results:

The RDS instance is created, and then available storage is increased.
##### Actual Results:

The RDS instance is created, and the modify command runs successfully, and returns a `changed` status but the storage size remains the same. Rebooting the instance doesn't affect it, so I don't think it is an issue with `apply_immediately`

```
<localhost> REMOTE_MODULE rds command=modify instance_name=rds-resize-test region=us-east-1
...
changed: [localhost] => {"changed": true, "instance": {"availability_zone": "us-east-1c", "backup_retention": 1, "backup_window": "10:22-10:52", "create_time": "2015-01-13T08:39:26.191Z", "endpoint": "rds-resize-test.ctshriqocnec.us-east-1.rds.amazonaws.com", "id": "rds-resize-test", "instance_type": "db.t1.micro", "iops": null, "maintenance_window": "mon:05:58-mon:06:28", "multi_zone": false, "port": 5432, "replication_source": null, "status": "available", "username": "rds_resize_test", "vpc_security_groups": ""}}
```



Discussion:

Resolving patch:
diff --git a/cloud/amazon/rds.py b/cloud/amazon/rds.py
--- a/cloud/amazon/rds.py
+++ b/cloud/amazon/rds.py
@@ -917,6 +917,7 @@ def validate_parameters(required_vars, valid_vars, module):
             'subnet': 'db_subnet_group_name',
             'license_model': 'license_model',
             'option_group': 'option_group_name',
+            'size': 'allocated_storage',
             'iops': 'iops',
             'new_instance_name': 'new_instance_id',
             'apply_immediately': 'apply_immediately',


Test patch:
Repository: ansible/ansible-modules-core

Issue:
ec2 module: throws error on instance status change
##### Issue Type:

Bug.
##### Ansible Version:

ansible-1.9.2-1.el7.noarch
##### Ansible Configuration:

```
- name: Change the status of instance(s)
  ec2:
    region: "{{ aws_region }}"
    instance_ids: "{{ instance_ids }}"
    state: "{{ state }}"
    source_dest_check: yes
    wait: yes
  register: ec2_res
  when: instance_ids != "[]"
  tags: startstop
```
##### Environment:

CentOS 7. Ansible installed from EPEL repo with the latest "ec2.py" module from development branch (commit 1857263b63e56feecf820b7990b7bffebfef14aa).
##### Summary:

The start/stop of instance fails with an error: NameError: global name 'source_dest_check' is not defined
##### Steps To Reproduce:
1. Launch an EC2 instance in AWS.
2. Run the above playbook to stop (or start a stopped) instance.
##### Expected Results:

The instance should be stopped or started.
##### Actual Results:

```
TASK: [startstop | Change the status of instance(s)] **************************
<127.0.0.1> REMOTE_MODULE ec2 instance_ids=i-1632c1b4 state=running region=us-east-1
failed: [127.0.0.1] => (item=i-1632c1b4) => {"failed": true, "item": "i-1632c1b4", "parsed": false}
Traceback (most recent call last):
  File "/home/Mgmt/.ansible/tmp/ansible-tmp-1444044960.88-103455925405949/ec2", line 3203, in <module>
    main()
  File "/home/Mgmt/.ansible/tmp/ansible-tmp-1444044960.88-103455925405949/ec2", line 1381, in main
    (changed, instance_dict_array, new_instance_ids) = startstop_instances(module, ec2, instance_ids, state, instance_tags)
  File "/home/Mgmt/.ansible/tmp/ansible-tmp-1444044960.88-103455925405949/ec2", line 1253, in startstop_instances
    if inst.get_attribute('sourceDestCheck')['sourceDestCheck'] != source_dest_check:
NameError: global name 'source_dest_check' is not defined

FATAL: all hosts have already failed -- aborting
```

Thanks,
Constantin



Discussion:

Resolving patch:
diff --git a/cloud/amazon/ec2.py b/cloud/amazon/ec2.py
--- a/cloud/amazon/ec2.py
+++ b/cloud/amazon/ec2.py
@@ -1228,6 +1228,8 @@ def startstop_instances(module, ec2, instance_ids, state, instance_tags):
     wait_timeout = int(module.params.get('wait_timeout'))
     changed = False
     instance_dict_array = []
+    source_dest_check = module.params.get('source_dest_check')
+    termination_protection = module.params.get('termination_protection')
 
     if not isinstance(instance_ids, list) or len(instance_ids) < 1:
         # Fail unless the user defined instance tags


Test patch:
Repository: ansible/ansible-modules-core

Issue:
docker module always reload container if net parameter ommited
##### Issue Type: Bug Report
##### Component Name: _docker module
##### Ansible Version: 1.9.1
##### Ansible Configuration:

[defaults]
hash_behaviour=merge
host_key_checking=false
gathering=no
pipelining=yes
remote_user=centos
become=yes
sudo=yes
hostfile=hosts
forks=30
##### Environment:

CentOS 7
##### Summary:

docker module always reload container if net parameter ommited
##### Steps To Reproduce:

[centos@dpt-bb0 ~]$ ansible localhost -c local -s -m docker -a "image=mongo state=reloaded"
localhost | success >> {
    "ansible_facts": {
        "docker_containers": [
            {
                "Id": "8a125c823d5de6d7fe8d4338f5b68c2324c30ad7a1bbe85023b30f0af242bb3f",
                "Warnings": null
            }
        ]
    },
    "changed": true,
    "containers": [
        {
            "Id": "8a125c823d5de6d7fe8d4338f5b68c2324c30ad7a1bbe85023b30f0af242bb3f",
            "Warnings": null
        }
    ],
    "msg": "started 1 container, created 1 container, pulled 1 container.",
    "reload_reasons": null,
    "summary": {
        "created": 1,
        "killed": 0,
        "pulled": 1,
        "removed": 0,
        "restarted": 0,
        "started": 1,
        "stopped": 0
    }
}

[centos@dpt-bb0 ~]$ ansible localhost -c local -s -m docker -a "image=mongo state=reloaded"
localhost | success >> {
    "ansible_facts": {
        "docker_containers": [
            {
                "Id": "5130248d943ae9485e6287caa601d10a7bb93477df543f5e8b9db145db25da39",
                "Warnings": null
            }
        ]
    },
    "changed": true,
    "containers": [
        {
            "Id": "5130248d943ae9485e6287caa601d10a7bb93477df543f5e8b9db145db25da39",
            "Warnings": null
        }
    ],
    "msg": "removed 1 container, stopped 1 container, started 1 container, created 1 container.",
    "reload_reasons": "net (bridge => )",
    "summary": {
        "created": 1,
        "killed": 0,
        "pulled": 0,
        "removed": 1,
        "restarted": 0,
        "started": 1,
        "stopped": 1
    }
}
##### Expected Results:

Second run should not restart container 
##### Actual Results:

Container always restarted



Discussion:
I just hit this with `state: reloaded`. Adding `net: default` to the task works around the problem.

Confirmed still an issue in v1.9.3-0.1.rc1

**sigh**
_insert beleaguered cry for some sort of idempotent operation here_


Resolving patch:
diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py
--- a/cloud/docker/docker.py
+++ b/cloud/docker/docker.py
@@ -1133,7 +1133,7 @@ def get_differing_containers(self):
 
             # NETWORK MODE
 
-            expected_netmode = self.module.params.get('net') or ''
+            expected_netmode = self.module.params.get('net') or 'default'
             actual_netmode = container['HostConfig']['NetworkMode']
             if actual_netmode != expected_netmode:
                 self.reload_reasons.append('net ({0} => {1})'.format(actual_netmode, expected_netmode))


Test patch:
Repository: ansible/ansible-modules-core

Issue:
glance images uploaded via os_image with is_public: true are not public
I have the following in a playbook:

```
- name: uploading centos atomic image to glance
  os_image:
    name: centos-7-atomic
    is_public: yes
    filename: images/centos-7-atomic.qcow2
```

The resulting image is not public:

```
+------------------------------+------------------+
| Property                     | Value            |
+------------------------------+------------------+
| name                         | centos-7-atomic  |
| visibility                   | private          |
+------------------------------+------------------+
```

Whereas if I upload an image from the command line:

```
glance image-create --file images/centos-7-atomic.qcow2 \
  --name larstest --visibility public \
  --disk-format qcow2 --container-format bare
```

The resulting image is publicly visible:

```
+------------------+-------------+
| Property         | Value       |
+------------------+-------------+
| name             | larstest    |
| visibility       | public      |
+------------------+-------------+
```



Discussion:
...because the `os_image` module never actually does anything with the `is_public` parameter.

cc @emonty @Shrews 

_headdesk_

Thanks - will fix asap


Resolving patch:
diff --git a/cloud/openstack/os_image.py b/cloud/openstack/os_image.py
--- a/cloud/openstack/os_image.py
+++ b/cloud/openstack/os_image.py
@@ -154,7 +154,8 @@ def main():
                     disk_format=module.params['disk_format'],
                     container_format=module.params['container_format'],
                     wait=module.params['wait'],
-                    timeout=module.params['timeout']
+                    timeout=module.params['timeout'],
+                    is_public=module.params['is_public'],
                 )
                 changed = True
                 if not module.params['wait']:


Test patch: