Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec2_vol preserves Name Tag to None and removes other Tags from volume #229

Closed
jaudriga opened this issue Jan 7, 2021 · 9 comments · Fixed by #242
Closed

ec2_vol preserves Name Tag to None and removes other Tags from volume #229

jaudriga opened this issue Jan 7, 2021 · 9 comments · Fixed by #242
Assignees
Labels
bug This issue/PR relates to a bug has_pr module module priority/high python3

Comments

@jaudriga
Copy link

jaudriga commented Jan 7, 2021

SUMMARY

ec2_vol sets Name tag to None and removes all other Tags from volume.

It works when I use ansible 2.9 and ec2_vol instead of amazon.aws.ec2_vol.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ec2_vol

ANSIBLE VERSION
ansible 2.9.16
  config file = /home/ubuntu/user/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]

Also reproduced with ansible 2.10.

CONFIGURATION
INTERPRETER_PYTHON(/home/ubuntu/user/ansible.cfg) = auto
OS / ENVIRONMENT
    Virtualization: kvm
  Operating System: Ubuntu 20.04.1 LTS
            Kernel: Linux 5.4.0-1034-aws
      Architecture: x86-64
# dpkg -l | grep boto
ii  python3-boto                         2.49.0-2.1                        all          Python interface to Amazon's Web Services - Python 3.x
ii  python3-boto3                        1.9.253-1                         all          Python interface to Amazon's Web Services - Python 3.x
ii  python3-botocore                     1.16.19+repack-1ubuntu0.20.04.1   all          Low-level, data-driven core of boto 3 (Python 3)

I am using amazon.aws version 1.3.0

STEPS TO REPRODUCE

Run the following from an ec2 machine with a volume that has the appropriate tags.

- name: Get ec2 instance facts
  amazon.aws.ec2_metadata_facts:

- name: Get available volumes 
  amazon.aws.ec2_vol_info: 
    filters:
      status: available
      availability-zone: "{{ ansible_ec2_placement_availability_zone }}"
      tag:Instance: "{{ server_type }}*"
      tag:Service: "{{ service_type }}"
      tag:Environment: "{{ env }}"
    region: "{{ ansible_ec2_placement_region }}"
  register: available_volumes
    
- name: Attach volume
  amazon.aws.ec2_vol:
    id: "{{ available_volumes.volumes[0].id }}"
    instance: "{{ ansible_ec2_instance_id }}"
    device_name: "{{ attach_volume_name }}"
    region: "{{ ansible_ec2_placement_region }}"
EXPECTED RESULTS

Tags should be left alone.

TASK [attach_volume : Get available volumes] *************************************************************************************************************************************************
task path: /home/ubuntu/user/roles/attach_volume/tasks/aws.yml:32
ok: [localhost] => {"changed": false, "volumes": [{"attachment_set": {"attach_time": null, "delete_on_termination": null, "device": null, "instance_id": null, "status": null}, "create_time": "2020-05-26T15:24:55.813000+00:00", "encrypted": true, "id": "vol-0c994ca3a7d01bad6", "iops": 100, "region": "eu-west-1", "size": 8, "snapshot_id": "", "status": "available", "tags": {"Environment": "exp", "Instance": "monitoring", "IsMaster": "master", "Name": "grafana-data", "Role": "LOMO", "Service": "grafana"}, "type": "gp2", "zone": "eu-west-1b"}]}

TASK [attach_volume : Attach volume] *********************************************************************************************************************************************************
task path: /home/ubuntu/user/roles/attach_volume/tasks/aws.yml:44
changed: [localhost] => {"changed": true, "device": "/dev/sdf", "volume": {"attachment_set": {"attach_time": "2021-01-07T13:50:34.000Z", "deleteOnTermination": "false", "device": "/dev/sdf", "instance_id": "i-0b09f6d53dbac581f", "status": "attached"}, "create_time": "2020-05-26T15:24:55.813Z", "encrypted": true, "id": "vol-0c994ca3a7d01bad6", "iops": 100, "size": 8, "snapshot_id": "", "status": "in-use", "tags": {"Environment": "exp", "Instance": "monitoring", "IsMaster": "master", "Name": "grafana-data", "Role": "LOMO", "Service": "grafana"}, "type": "gp2", "zone": "eu-west-1b"}, "volume_id": "vol-0c994ca3a7d01bad6", "volume_type": "gp2"}
ACTUAL RESULTS

Tags get changed:

TASK [attach_volume : Get available volumes] *************************************************************************************************************************************************
task path: /home/ubuntu/user/roles/attach_volume/tasks/aws.yml:32
ok: [localhost] => {"changed": false, "volumes": [{"attachment_set": {"attach_time": null, "delete_on_termination": null, "device": null, "instance_id": null, "status": null}, "create_time": "2020-05-26T15:24:55.813000+00:00", "encrypted": true, "id": "vol-0c994ca3a7d01bad6", "iops": 100, "region": "eu-west-1", "size": 8, "snapshot_id": "", "status": "available", "tags": {"Environment": "exp", "Instance": "monitoring", "IsMaster": "master", "Name": "grafana-data", "Role": "LOMO", "Service": "grafana"}, "type": "gp2", "zone": "eu-west-1b"}]}

TASK [attach_volume : Attach volume] *********************************************************************************************************************************************************
task path: /home/ubuntu/user/roles/attach_volume/tasks/aws.yml:44
changed: [localhost] => {"changed": true, "device": "/dev/sdf", "volume": {"attachment_set": {"attach_time": "2021-01-07T08:36:52+00:00", "deleteOnTermination": false, "device": "/dev/sdf", "instance_id": "i-0bdb31471ad654d66", "status": "attaching"}, "create_time": "2020-05-26T15:24:55.813000+00:00", "encrypted": true, "id": "vol-0c994ca3a7d01bad6", "iops": 100, "size": 8, "snapshot_id": "", "status": "in-use", "tags": {"Name": "None"}, "type": "gp2", "zone": "eu-west-1b"}, "volume_id": "vol-0c994ca3a7d01bad6", "volume_type": "gp2"}
@cooperbaird
Copy link

We are facing the same issue. And when the tag begins with "aws:", an exception is thrown because aws doesn't allow modifying/deleting those reserved tags.

@goneri
Copy link
Member

goneri commented Jan 8, 2021

Hi, thank you for the your bug report. It sounds like the regression has been introduced between 1.2.0 and 1.3.0. Can you give a try to 1.2.0 to see if this version work for you?

@jaudriga
Copy link
Author

jaudriga commented Jan 8, 2021

Just a quick note from me before the weekend: I have not tried to reproduce this again with 1.2.0, but I had been using amazon.aws.ec2_vol with 1.2.0 successfully. This was a few weeks ago. I used the same playbook for that.

So yes. I assume this would still work with 1.2.0. Maybe #53 somehow introduced this issue?

@tremble
Copy link
Contributor

tremble commented Jan 11, 2021

Likely introduced by

         final_tags, tags_changed = ensure_tags(module, ec2_conn, volume['volume_id'], 'volume', tags, False)

I suspect that switching the final 'False' to 'True' should restore the old behaviour
Best fix would be to add a purge_tags option with a default of False, then use that to set the value passed to that function.

@ansibullbot
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module python3 labels Jan 13, 2021
goneri added a commit to goneri/amazon.aws that referenced this issue Jan 15, 2021
goneri added a commit to goneri/amazon.aws that referenced this issue Jan 15, 2021
@goneri
Copy link
Member

goneri commented Jan 15, 2021

goneri added a commit to goneri/amazon.aws that referenced this issue Jan 18, 2021
goneri added a commit to goneri/amazon.aws that referenced this issue Jan 18, 2021
goneri added a commit to goneri/amazon.aws that referenced this issue Jan 18, 2021
goneri added a commit to goneri/amazon.aws that referenced this issue Jan 18, 2021
goneri added a commit to goneri/amazon.aws that referenced this issue Jan 18, 2021
@goneri goneri changed the title ec2_vol sets Name Tag to None and removes other Tags from volume ec2_vol preserve Name Tag to None and removes other Tags from volume Jan 19, 2021
@goneri goneri changed the title ec2_vol preserve Name Tag to None and removes other Tags from volume ec2_vol preserves Name Tag to None and removes other Tags from volume Jan 19, 2021
@jaudriga
Copy link
Author

jaudriga commented Feb 1, 2021

@goneri Yes. That fixes it for me.

TASK [attach_volume : Get available volumes] *************************************************************************************************************************************************
task path: /home/ubuntu/audriga-init/roles/attach_volume/tasks/aws.yml:32
ok: [localhost] => {"changed": false, "volumes": [{"attachment_set": {"attach_time": null, "delete_on_termination": null, "device": null, "instance_id": null, "status": null}, "create_time": "2020-05-26T15:24:55.813000+00:00", "encrypted": true, "id": "vol-0c994ca3a7d01bad6", "iops": 100, "region": "eu-west-1", "size": 8, "snapshot_id": "", "status": "available", "tags": {"Environment": "exp", "Instance": "monitoring", "IsMaster": "master", "Name": "grafana-data", "Role": "LOMO", "Service": "grafana"}, "type": "gp2", "zone": "eu-west-1b"}]}

TASK [attach_volume : Attach volume] *********************************************************************************************************************************************************
task path: /home/ubuntu/audriga-init/roles/attach_volume/tasks/aws.yml:44
changed: [localhost] => {"changed": true, "device": "/dev/sdf", "volume": {"attachment_set": {"attach_time": "2021-02-01T15:19:53+00:00", "deleteOnTermination": false, "device": "/dev/sdf", "instance_id": "i-0d9f98f520061f4f3", "status": "attaching"}, "create_time": "2020-05-26T15:24:55.813000+00:00", "encrypted": true, "id": "vol-0c994ca3a7d01bad6", "iops": 100, "size": 8, "snapshot_id": "", "status": "in-use", "tags": {"Environment": "exp", "Instance": "monitoring", "IsMaster": "master", "Name": "grafana-data", "Role": "LOMO", "Service": "grafana"}, "throughput": null, "type": "gp2", "zone": "eu-west-1b"}, "volume_id": "vol-0c994ca3a7d01bad6", "volume_type": "gp2"}

@kbrahmbh
Copy link

I am facing the similiar issue so has this been backported to 2.10 branch? I am currently using 2.10.18 and i still see this issue. Can someone please help?

@goneri
Copy link
Member

goneri commented Apr 30, 2021

Hi @kbrahmbh! This change is unlikely to get backported. The best you can do is to install the last release of ansible.aws collection through ansible-galaxy.

alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this issue Sep 9, 2022
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@cd938b2
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this issue Sep 9, 2022
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@cd938b2
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this issue Sep 9, 2022
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@cd938b2
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this issue Sep 9, 2022
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@cd938b2
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this issue Sep 16, 2022
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@cd938b2
goneri pushed a commit to alinabuzachis/amazon.aws that referenced this issue Sep 21, 2022
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@cd938b2
goneri pushed a commit to alinabuzachis/amazon.aws that referenced this issue Sep 21, 2022
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@cd938b2
goneri pushed a commit to alinabuzachis/amazon.aws that referenced this issue Sep 21, 2022
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@cd938b2
goneri pushed a commit to alinabuzachis/amazon.aws that referenced this issue Sep 21, 2022
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@cd938b2
goneri pushed a commit to alinabuzachis/amazon.aws that referenced this issue Sep 21, 2022
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@cd938b2
goneri pushed a commit to alinabuzachis/amazon.aws that referenced this issue Sep 21, 2022
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@cd938b2
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Oct 24, 2023
…#229)

* Type conversion issue for creating read replicas
* Added changelog snippet
* Updated tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr module module priority/high python3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants