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_instance: instance_type should not be required to start/stop instances #980

Closed
1 task done
rbobrowicz opened this issue Aug 26, 2022 · 2 comments · Fixed by #983
Closed
1 task done

ec2_instance: instance_type should not be required to start/stop instances #980

rbobrowicz opened this issue Aug 26, 2022 · 2 comments · Fixed by #983
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type) python3

Comments

@rbobrowicz
Copy link
Contributor

Summary

Hello,

I have some old ansible scripts using the old ec2 module that I'm updating to use the new ec2_instance module and I'm getting some deprecation warnings that I think don't really make sense. What I'm essentially trying to do is to start/stop instances matching a tag. I have these scripts to do this:

- name: turn on instances
  amazon.aws.ec2_instance:
    region: us-east-1
    filters:
      tag-key: shutdown_outside_business_hours
    state: running
    purge_tags: false

and

- name: shut down instances
  amazon.aws.ec2_instance:
    region: us-east-1
    filters:
      tag-key: shutdown_outside_business_hours
    state: stopped
    purge_tags: false

When I run these I get this deprecation warning:

[DEPRECATION WARNING]: Default value instance_type has been deprecated, in the 
future you must set an instance_type or a launch_template. This feature will be
removed from amazon.aws in a release after 2023-01-01. Deprecation warnings 
can be disabled by setting deprecation_warnings=False in ansible.cfg.

However, requiring instance_type doesn't really make much sense to me becasue I'm not trying to create, re-create or re-size any instances. I'm just tring to turn them on and off. Even specifying a dummy value would be a bit weird since the intances I'm turning on/off are of various sizes.

Examining the code, it looks like the warning is given for any state that is not absent: https://github.com/ansible-collections/amazon.aws/blob/main/plugins/modules/ec2_instance.py#L2053

I think the specifying instance_type or launch_template should only be required if you also specify count or exact_count, since that would be the only time new instances would or could be launched. If neither is present, then instance_type is not needed as far as I can tell.

So, I propose that the conditional for the warning be change to something like:

if not module.params.get('instance_type') and not module.params.get('launch_template'):
    if module.params.get('state') not in ('absent', 'stopped'):
        if module.params.get('size') or module.params.get('exact_size'):
           module.deprecate("Default value instance_type has been deprecated, in the future you must set an instance_type or a launch_template",
                            date='2023-01-01', collection_name='amazon.aws')

Let me know if this is acceptable or if you have other ideas or comments. I could prepare a patch if my suggestion is acceptable.

Issue Type

Bug Report

Component Name

ec2_instance

Ansible Version

ansible 2.10.8
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.10.4 (main, Apr  2 2022, 09:04:19) [GCC 11.2.0]

Collection Versions

# /usr/lib/python3/dist-packages/ansible_collections
Collection                Version
------------------------- -------
amazon.aws                1.4.0
ansible.netcommon         1.5.0
ansible.posix             1.1.1
ansible.windows           1.4.0
arista.eos                1.3.0
awx.awx                   14.1.0
azure.azcollection        1.4.0
check_point.mgmt          1.0.6
chocolatey.chocolatey     1.0.2
cisco.aci                 1.1.1
cisco.asa                 1.0.4
cisco.intersight          1.0.10
cisco.ios                 1.3.0
cisco.iosxr               1.2.1
cisco.meraki              2.2.0
cisco.mso                 1.1.0
cisco.nso                 1.0.3
cisco.nxos                1.4.0
cisco.ucs                 1.6.0
cloudscale_ch.cloud       1.3.1
community.aws             1.3.0
community.azure           1.0.0
community.crypto          1.4.0
community.digitalocean    1.0.0
community.docker          1.2.2
community.fortios         1.0.0
community.general         1.3.6
community.google          1.0.0
community.grafana         1.1.0
community.hashi_vault     1.1.0
community.hrobot          1.1.0
community.kubernetes      1.1.1
community.kubevirt        1.0.0
community.libvirt         1.0.0
community.mongodb         1.2.0
community.mysql           1.2.0
community.network         1.3.2
community.okd             1.0.0
community.postgresql      1.1.1
community.proxysql        1.0.0
community.rabbitmq        1.0.1
community.routeros        1.1.0
community.skydive         1.0.0
community.vmware          1.7.0
community.windows         1.3.0
community.zabbix          1.2.0
containers.podman         1.4.1
cyberark.conjur           1.1.0
cyberark.pas              1.0.5
dellemc.os10              1.0.2
dellemc.os6               1.0.6
dellemc.os9               1.0.3
f5networks.f5_modules     1.7.1
fortinet.fortimanager     1.0.5
fortinet.fortios          1.1.8
frr.frr                   1.0.3
gluster.gluster           1.0.1
google.cloud              1.0.2
hetzner.hcloud            1.2.1
ibm.qradar                1.0.3
infinidat.infinibox       1.2.4
junipernetworks.junos     1.3.0
mellanox.onyx             1.0.0
netapp.aws                20.9.0
netapp.elementsw          20.11.0
netapp.ontap              20.12.0
netapp_eseries.santricity 1.1.0
netbox.netbox             1.2.1
ngine_io.cloudstack       1.2.0
ngine_io.exoscale         1.0.0
ngine_io.vultr            1.1.0
openstack.cloud           1.2.1
openvswitch.openvswitch   1.1.0
ovirt.ovirt               1.3.0
purestorage.flasharray    1.6.2
purestorage.flashblade    1.4.0
servicenow.servicenow     1.0.4
splunk.es                 1.0.2
theforeman.foreman        1.5.1
vyos.vyos                 1.1.1
wti.remote                1.0.1

# /usr/share/ansible/collections/ansible_collections
Collection    Version
------------- -------
amazon.aws    4.1.0
community.aws 4.1.1

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: /usr/lib/python3/dist-packages
Requires:
Required-by:
---
Name: boto3
Version: 1.20.34
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: /usr/lib/python3/dist-packages
Requires:
Required-by:
---
Name: botocore
Version: 1.23.34
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: /usr/lib/python3/dist-packages
Requires:
Required-by:

Configuration

HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
INVENTORY_ENABLED(/etc/ansible/ansible.cfg) = ['aws_ec2', 'host_list', 'ini', 'yaml', 'constructed']

OS / Environment

Ubuntu 22.04

Steps to Reproduce

- name: turn on instances
  amazon.aws.ec2_instance:
    region: us-east-1
    filters:
      tag-key: shutdown_outside_business_hours
    state: running
    purge_tags: false

- name: shut down instances
  amazon.aws.ec2_instance:
    region: us-east-1
    filters:
      tag-key: shutdown_outside_business_hours
    state: stopped
    purge_tags: false

Expected Results

Tasks run with no warning or depracations.

Actual Results

[DEPRECATION WARNING]: Default value instance_type has been deprecated, in the 
future you must set an instance_type or a launch_template. This feature will be
removed from amazon.aws in a release after 2023-01-01. Deprecation warnings 
can be disabled by setting deprecation_warnings=False in ansible.cfg.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@alinabuzachis
Copy link
Collaborator

@rbobrowicz Thank you for bringing this. Feel free to open a pull request with this contribution. Add a changelog fragment also please.

@ansibullbot
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module needs_triage plugins plugin (any type) python3 labels Aug 26, 2022
rbobrowicz added a commit to rbobrowicz/amazon.aws that referenced this issue Aug 29, 2022
Specifying instance_type should not be required unless count or
exact_count are specified.

Fixes ansible-collections#980
softwarefactory-project-zuul bot pushed a commit that referenced this issue Sep 6, 2022
Fix deprecation warning on instance_type

SUMMARY
Specifying instance_type should not be required unless count or exact_count are specified.
If the user is just trying to start/stop instances then we don't need to ask for size.
Fixes #980
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
ec2_instance
ADDITIONAL INFORMATION

Reviewed-by: Gonéri Le Bouder <[email protected]>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: Brian Scholer <None>
patchback bot pushed a commit that referenced this issue Sep 6, 2022
Fix deprecation warning on instance_type

SUMMARY
Specifying instance_type should not be required unless count or exact_count are specified.
If the user is just trying to start/stop instances then we don't need to ask for size.
Fixes #980
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
ec2_instance
ADDITIONAL INFORMATION

Reviewed-by: Gonéri Le Bouder <[email protected]>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: Brian Scholer <None>
(cherry picked from commit d80ab5b)
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 plugins plugin (any type) python3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants