Closed gregharvey closed 1 month ago
I think all described possibilities will break backwards compatility.
A new module is not a solution and will gain entropy of the aws modules.
The only way to implement it, is to introduce a new parameter modify_instance_type
which default value is False
.
In case the instance_type
differ from existing instance, you must differentiate between a running and stopped instance.
A stopped instance can changed immediately. A running instance must be stopped by using a waiter, changed and start again.
In case the AZ is running out of capacity of the new instance type, you got an error/problem.
cc @Shaps @jillr @s-hertel @tremble @wimnat click here for bot help
There is a none-active PR left in community.aws that is targeting in this direction:
Hi @gregharvey,
Thank you for taking the time to reopen this. It's indeed an interesting feature idea.
Thanks for taking the time to open this issue.
The ec2 module was based upon the original boto SDK and was dropped in release 4.0.0 please use the ec2_instance module instead which I believe has this functionality.
@tremble Is it possible to reopen this issue? Module ec2_instance
does not have this capability at the moment.
I'm currently trying to write a playbook to change the instance type, and I'm unable to do it, even with the instance being shutdown.
I know OP mentioned the module ec2
in their examples, but the they did says ec2_instance
under COMPONENT NAME. This request was originally made in the https://github.com/ansible/ansible/issues/33373 repository before the collection migration, so the ambiguity probably comes from that.
It would probably be better to rename this issue to something like ec2_instance: allow modifying instance_type for existing instances
for better clarity.
Let me know if I can be of any help!
@pgrenaud sure. For some reason I thought ec2_instance could modify the instance type, looking deeper at the code, it just doesn't throw errors.
If you're interested in trying to add support for this feature, then it may just be a case of updating diff_instance_and_params()
However, I'm not a big fan of trying to add the "force" parameter. The logic behind this has the potential to get very messy.
OP is @pkaramol - see https://github.com/ansible/ansible/issues/33373 (closed by bot)
SUMMARY
Enable on-the-fly instance type change (upgrade / downgrade).
Currently when running a script that creates ec2 instance(s), there is no way to perform a type change (e.g. from
t2.micro
tot2.small
).ISSUE TYPE
COMPONENT NAME
ec2_instance (as proposed in original ticket - see https://github.com/ansible/ansible/issues/33373#issuecomment-350321979) or potentially a new module (as suggested here - https://github.com/ansible/ansible/issues/33373#issuecomment-381685354)
ADDITIONAL INFORMATION
If you want to use Ansible to manage infrastructure then you need to be able to up and down grade EC2 instance type as part of that. Currently we need to use the CLI, which is simple enough, but it would be more elegant of Ansible just handled this.
Here's the OP again:
Using vars from below
and running the following task based on those vars:
if those instances are there and running and one wants to re-run the script, having one of the instance types changed (from
t2.micro
-->t2.small
), e.g. as follows:the script runs idempotently again, although the output yields:
(output trimmed).
OP's point being he expected the instance size to change. There's some follow-up discussion between @ryansb and @bobobox about how this might be implemented, and a plan seems to be formed, specifically:
force:
flag is set totrue
, then ec2_instance stops the instance, changes the type, and starts it back up.And some specific concerns, which caused the suggestion the default behaviour ought not to be just blindly change instance type:
It's this complexity which makes the original participants consider that maybe this is a separate module entirely, as
instance_type
is already optional forec2_instance
.Anyway, putting this back in as it feels valid and it seems to have been dropped.