Closed markuman closed 2 years ago
Files identified in the description:
plugins/modules/ec2_instance.py
](https://github.com/['ansible-collections/amazon.aws', 'ansible-collections/community.aws', 'ansible-collections/community.vmware']/blob/main/plugins/modules/ec2_instance.py)If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
cc @jillr @ryansb @s-hertel @tremble @wimnat click here for bot help
maybe the implementation is not that difficult at the end.
the only question that is left: what to do with the default values?
One possibility is, that they are only applied when launch_template
parameter is not requested.
if not module.params.get('launch_template'):
instance_type = 't2.micro'
But that means that they must remove from AnsibleAWSModule()
initialisation, because you cannot differentiate if module.params.get('instance_type')
is a requested value or a default value. Or is it possible?
Removing default values from AnsibleAWSModule()
will result in doc errors I think.
Removing the default value in general will be the easiest fix. But that must be made in some iteration steps with deprecation warnings?
I would love to see this implemented. IMO, the best behavior would be to apply the values in the following order:
I have 0 knowledge of boto, so I don't know how easy that is to make happen, though.
I think its vice-versa :)
ec2_instance
task.If launch template is defined
ec2_instance
task.I have 0 knowledge of boto, so I don't know how easy that is to make happen, though.
I think it's not that difficult, but a lot of time consuming (adjust and expand integration tests).
If you like to get involved, you just missed the ansible-fest 2022. But there are many helping hands on libera irc in #ansible-aws and also #ansible-community
I was thinking of the numbers from least important to most, and you were going vice versa, I think. In any case, I agree with you. I'd be interested in getting involved, but I don't know how much time I'd have to maintain stuff. Also, at my work, we're tied to ansible 2.9, unfortunately, so I wouldn't be able to use and test the thing very much. I'll definitley look into it, though, if we ever get things sorted out so that we can upgrade our ansible.
Two issues (TL;DR)
launch_template
paremeter with otherec2_instance
parameters in the same task (e.g.instance_type
).ec2_instance
is making this even more diffcult to handleSummary
Origin Issue: https://github.com/ansible/ansible/issues/51941
First trial of fix: https://github.com/ansible-collections/community.aws/pull/111
Broken condition still exists: https://github.com/ansible-collections/amazon.aws/blob/main/plugins/modules/ec2_instance.py#L1165
However. It's not that easy.
Imo, LaunchTemplate parameters are not changeable in the context of
run_instance
.You must read-out the launch_template parameters and throw them aginst
run_instance
to pretend they came frommodule.params
."Failed to create new EC2 instance: An error occurred (Unsupported) when calling the RunInstances operation: The requested configuration is currently not supported. Please check the documentation for supported configurations."
One issues are the default values the modules applies.
{'BlockDeviceMappings': [], 'ClientToken': '37d405af374948e2bd427ff4a7a7fc04', 'InstanceType': 't2.micro', 'LaunchTemplate': {'LaunchTemplateName': 'ubuntu-20.04'}, 'MaxCount': 1, 'MinCount': 1, 'NetworkInterfaces': [{'DeviceIndex': 0, 'SubnetId': 'subnet-3e5fe743'}], 'TagSpecifications': [{'ResourceType': 'volume', 'Tags': [{'Key': 'Name', 'Value': 'lttest01'}]}, {'ResourceType': 'instance', 'Tags': [{'Key': 'Name', 'Value': 'lttest01'}]}]}
This happen when you run
ec2_instance
without any parameters, just with aLaunchTemplateName
. So the module appliesBlockDeviceMappings: []
InstanceType:
t2.micro`basically when I run
I expect that all values are taken from the launch_template, only the requested will be overwritten (
instance_type
andvpc_subnet_id
.)but because of the default values, when I request
what instance_type will be choosen? I expect the one that is defined in the launch_template (e.g. t3a.small). But the module will request a t2.micro instance (default value in
ec2_instance
).so one point that must be reworked are the parameters that breaks the launch_template when no extra parameters are requested.
that might be the easiert part.
the harder part is to read-out launch_template parameters and compare them to ec2_instance parameters if requested and throw everything against
run_instance
withoutLaunchTemplate
parameter.Issue Type
Bug Report
Component Name
ec2_instance
Ansible Version
Collection Versions
AWS SDK versions
Configuration
OS / Environment
Linux rocket 5.11.22-2-MANJARO #1 SMP PREEMPT Fri May 21 17:45:54 UTC 2021 x86_64 GNU/Linux
Steps to Reproduce
Expected Results
Deploy an ec2 instance with lauch_template parameters for all parameters that are not requested by
ec2_instance
module.Actual Results
Code of Conduct