From 798aa8a2d2c134bd62708d6dd94a9384213cc68e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Wed, 3 Jan 2018 15:31:34 +0100 Subject: [PATCH] ec2_asg: fix desired_capacity not optional (#34194) 1# Please enter the commit message for your changes. Lines starting --- lib/ansible/modules/cloud/amazon/ec2_asg.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_asg.py b/lib/ansible/modules/cloud/amazon/ec2_asg.py index b67ab8d0c51..ec871d2593c 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_asg.py +++ b/lib/ansible/modules/cloud/amazon/ec2_asg.py @@ -1145,6 +1145,9 @@ def replace(connection): replace_instances = module.params.get('replace_instances') as_group = describe_autoscaling_groups(connection, group_name)[0] + if desired_capacity is None: + desired_capacity = as_group['DesiredCapacity'] + wait_for_new_inst(connection, group_name, wait_timeout, as_group['MinSize'], 'viable_instances') props = get_properties(as_group) instances = props['instances'] @@ -1178,8 +1181,7 @@ def replace(connection): min_size = as_group['MinSize'] if max_size is None: max_size = as_group['MaxSize'] - if desired_capacity is None: - desired_capacity = as_group['DesiredCapacity'] + # set temporary settings and wait for them to be reached # This should get overwritten if the number of instances left is less than the batch size. @@ -1265,6 +1267,9 @@ def terminate_batch(connection, replace_instances, initial_instances, leftovers= break_loop = False as_group = describe_autoscaling_groups(connection, group_name)[0] + if desired_capacity is None: + desired_capacity = as_group['DesiredCapacity'] + props = get_properties(as_group) desired_size = as_group['MinSize'] @@ -1434,5 +1439,6 @@ def main(): changed = True module.exit_json(changed=changed, **asg_properties) + if __name__ == '__main__': main()