Skip to content

ec2_vol doesn't report volume changes properly #482

Description

@lowlydba

Summary

When modify_volume is used but no new disk is being attached, the module incorrectly reports that no change has occurred even when disks have been modified (iops, throughput, type, etc.). This is due to the attach function overwriting the changed variable even if no disks are attached:

if volume:
volume, changed = update_volume(module, ec2_conn, volume)
else:
volume, changed = create_volume(module, ec2_conn, zone=zone)
if name:
tags['Name'] = name
final_tags, tags_changed = ensure_tags(module, ec2_conn, volume['volume_id'], 'volume', tags, module.params.get('purge_tags'))
if detach_vol_flag:
volume, changed = detach_volume(module, ec2_conn, volume_dict=volume)
elif inst is not None:
volume, changed = attach_volume(module, ec2_conn, volume_dict=volume, instance_dict=inst, device_name=device_name)
# Add device, volume_id and volume_type parameters separately to maintain backward compatibility
volume_info = get_volume_info(module, volume, tags=final_tags)
if tags_changed:
changed = True

Locally I have used the following workaround as a fix:

        if detach_vol_flag:
            volume, changed = detach_volume(module, ec2_conn, volume_dict=volume)
        elif inst is not None:
            volume, vol_attached = attach_volume(module, ec2_conn, volume_dict=volume, instance_dict=inst, device_name=device_name)

        # Add device, volume_id and volume_type parameters separately to maintain backward compatibility
        volume_info = get_volume_info(module, volume, tags=final_tags)

        if tags_changed or vol_attached:
            changed = True

I am happy to make a PR with this change if this is an acceptable route to go down.

Issue Type

Bug Report

Component Name

ec2_vol

Ansible Version

ansible 2.9.9

Collection Versions

Collection        Version
----------------- -------
amazon.aws        1.5.0

AWS SDK versions

Name: boto
Version: 2.49.0
Summary: Amazon Web Services Library
Home-page: https://github.com/boto/boto/
Author: Mitch Garnaat
Author-email: [email protected]
License: MIT
Location: /Users/john.mccall/.pyenv/versions/3.6.5/lib/python3.6/site-packages
Requires: 
Required-by: 
---
Name: boto3
Version: 1.18.31
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: 
License: Apache License 2.0
Location: /Users/john.mccall/.pyenv/versions/3.6.5/lib/python3.6/site-packages
Requires: botocore, jmespath, s3transfer
Required-by: 
---
Name: botocore
Version: 1.21.31
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email: 
License: Apache License 2.0
Location: /Users/john.mccall/.pyenv/versions/3.6.5/lib/python3.6/site-packages
Requires: jmespath, urllib3, python-dateutil
Required-by: s3transfer, boto3

Configuration

N/A

OS / Environment

MacOS

Steps to Reproduce

amazon.aws.ec2_vol:
        region: "region-name"
        name: "disk-name"
        device_name: "device-name"
        volume_type: gp3
        volume_size: 50
        iops: 126
        throughput: 3001
        modify_volume: true

Run something similar to the above example to upgrade an existing attached gp2 volume to gp3, along with non-default iops and throughput. The module will make the changes correctly but mark the volume as "ok" instead of "changed" in the results.

Expected Results

I expect the module to report back changed: true when modifying the type, iops, etc. of an already-attached ebs volume.

Actual Results

Module reports changed: false when modifying the type, iops, etc. of an already-attached ebs volume.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue/PR relates to a bugmodulemodulepluginsplugin (any type)python3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions