-
Notifications
You must be signed in to change notification settings - Fork 328
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: Add count parameter to ec2_instance #539
ec2_instance: Add count parameter to ec2_instance #539
Conversation
@mandar242 this PR contains the following merge commits: Please rebase your branch to remove these commits. |
aec9a0a
to
9142575
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, thanks @mandar242!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @mandar242
tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/instance_multiple.yml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mandar242,
(following up on a private conversation so the reasoning behind any new logic can be publicly followed)
Usually, with Ansible we try to default to things being idempotent, and update an existing object rather than always triggering a change. Given this context the way I would generally have interpreted "Max" and "Min" for the ec2_instance module is that we want the total number of matching instances to be between the two values: something approximating an Ansible-managed alternative to an AutoScalingGroup.
Currently, we have users migrating from the old ec2 module [1] which has exact_count
and count
. count
would always spawn instances (the behaviour you've implemented), but exact_count
would try to ensure that the total number of matching (filters
) instances is exact_count
(the behaviour I thought you were trying to implement).
The fact that I misinterpreted what you had tried to implement things (having generally used exact_count
rather than count
) means that users probably will too.
Rather than exposing max_count
and min_count
, I'd recommend:
count
(int - default 1): number of instances expected to match the filters, mimicking ec2.py's "exact_count" by default.always_launch
(bool - default false): if set to true then always trigger a launch. (as you do today if count > 1)
This means that the count=1
behaviour is much closer to the count>1
behaviour, it also means if the user really did want to always launch a new instance, they can now also launch them one at a time if they wanted.
tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/instance_multiple.yml
Show resolved
Hide resolved
|
||
elif current_count < exact_count: | ||
to_launch = exact_count - current_count | ||
module.params['to_launch'] = to_launch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could overwrite module.params['count']
here to avoid the extra code path in build_run_instance_spec
@jillr do you have any opinions on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally don't like overwriting module.params, I worry that it's asking for issues down the road when we make some other change that uses count
and expects it to be whatever the user originally specified. I think I'd rather have the extra conditional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for all your work on this @mandar242!
|
||
elif current_count < exact_count: | ||
to_launch = exact_count - current_count | ||
module.params['to_launch'] = to_launch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally don't like overwriting module.params, I worry that it's asking for issues down the road when we make some other change that uses count
and expects it to be whatever the user originally specified. I think I'd rather have the extra conditional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Backport to stable-2: 💚 backport PR created✅ Backport PR branch: Backported as #580 🤖 @patchback |
ec2_instance: Add count parameter to ec2_instance SUMMARY Adding min_count and max_count parameter to ec2_instance. Fixes #536. ISSUE TYPE Feature Pull Request COMPONENT NAME ec2_instance Reviewed-by: Jill R <None> Reviewed-by: Mark Chappell <None> Reviewed-by: Mandar Kulkarni <mandar242@gmail.com> Reviewed-by: None <None> (cherry picked from commit 760186c)
Add missing version_added to ec2_instance.py SUMMARY Realised after #539 merged that we didn't add version_added ISSUE TYPE Docs Pull Request COMPONENT NAME ec2_instance ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis <None> Reviewed-by: None <None>
ec2_instance: Add count parameter to ec2_instance SUMMARY Adding min_count and max_count parameter to ec2_instance. Fixes #536. ISSUE TYPE Feature Pull Request COMPONENT NAME ec2_instance Reviewed-by: Jill R <None> Reviewed-by: Mark Chappell <None> Reviewed-by: Mandar Kulkarni <mandar242@gmail.com> Reviewed-by: None <None> (cherry picked from commit 760186c) Co-authored-by: Mandar Kulkarni <mandar242@gmail.com>
Add missing version_added to ec2_instance.py SUMMARY Realised after #539 merged that we didn't add version_added ISSUE TYPE Docs Pull Request COMPONENT NAME ec2_instance ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis <None> Reviewed-by: None <None> (cherry picked from commit cf2b9aa) Co-authored-by: Mark Chappell <mchappel@redhat.com>
…ble-jobs_29701 disable shippable jobs Reviewed-by: https://github.com/apps/ansible-zuul
SUMMARY
UPDATE: Added
count
andexact_count
parameters toec2_instance
instead ofmin_count
andmax_count
.Adding min_count and max_count parameter to ec2_instance.
Fixes #536.
ISSUE TYPE
COMPONENT NAME
ec2_instance