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:
[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.
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.
[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.
Summary
Hello,
I have some old ansible scripts using the old
ec2
module that I'm updating to use the newec2_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:and
When I run these I get this deprecation warning:
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#L2053I think the specifying
instance_type
orlaunch_template
should only be required if you also specifycount
orexact_count
, since that would be the only time new instances would or could be launched. If neither is present, theninstance_type
is not needed as far as I can tell.So, I propose that the conditional for the warning be change to something like:
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
Collection Versions
AWS SDK versions
Configuration
OS / Environment
Ubuntu 22.04
Steps to Reproduce
Expected Results
Tasks run with no warning or depracations.
Actual Results
Code of Conduct