-
Bug
-
Resolution: Unresolved
-
Undefined
-
None
-
Unspecified
-
False
-
-
False
-
-
https://github.com/ansible-collections/amazon.aws/issues/469
OP is @pkaramol - see https://github.com/ansible/ansible/issues/33373 (closed by bot)
-
-
-
-
- SUMMARY
Enable on-the-fly instance type change (upgrade / downgrade).
- SUMMARY
-
-
-
Currently when running a script that creates ec2 instance(s), there is no way to perform a type change (e.g. from `t2.micro` to `t2.small`).
-
-
-
-
- ISSUE TYPE
-
-
-
- Feature Idea
-
-
-
-
- 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)
- COMPONENT NAME
-
-
-
-
-
-
-
- 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.
- ADDITIONAL INFORMATION
-
-
-
Here's the OP again:
Using vars from below
```yaml
my_instances:
- instance_type: "t2.micro"
exact_count: "1"
assign_public_ip: "no" - instance_type: "t2.micro"
exact_count: "1"
assign_public_ip: "no"
```
and running the following task based on those vars:
```yaml
- name: Create my instances
ec2:
instance_type: "{{ item.ec2_instance_type }}"
region: "us-east-1"
image: "some-image"
group_id: "some-group-id"
vpc_subnet_id: "some-subnet-id"
instance_tags:
with_items: "{{ my_instances }}"
```
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:
```yaml
- instance_type: "t2.small"
```
the script runs idempotently again, although the output yields:
```yaml
ok: [localhost] => (item=
)
```
(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:
- User provides instance_type parameter, and if the instance does not exist it's created (as in ec2 module)
- User provides no instance_type parameter: no changes are made if the instance exists
- User provides an instance_type parameter that doesn't match:
- If the instance is running, no change & the module displays a warning
- If the instance is stopped, or desired state is stopped, then the instance is stopped& the type can be changed, relying on the user to follow up with a task to start the instance
- If the instance is running, and a `force:` flag is set to `true`, 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:
- ...changing an instance type can require numerous other changes as well: NVMe EBS volumes used on M5/C5 instances show up with different device names, enhanced networking and EBS optimization may need to be toggled appropriately, and of course the OS may or may not even boot successfully with a different instance type, depending on things like different virtual network adapters etc.
It's this complexity which makes the original participants consider that maybe this is a separate module entirely, as `instance_type` is already optional for `ec2_instance`.
Anyway, putting this back in as it feels valid and it seems to have been dropped.