diff options
author | einarc <einarc@users.noreply.github.com> | 2016-11-11 10:10:22 -0800 |
---|---|---|
committer | Ryan Brown <sb@ryansb.com> | 2016-11-11 13:10:22 -0500 |
commit | 8d1fe3b444737b26d6c634fc55010239ad342174 (patch) | |
tree | 8e293cfca7cdea70a8f125a12ac52d73d4f60293 | |
parent | afa1750105318e3535038d2d631acc4b4db566e9 (diff) | |
download | ansible-modules-core-8d1fe3b444737b26d6c634fc55010239ad342174.tar.gz |
Avoid `TypeError` when desired_capacity is not provided to `ec2_asg` module (#5501)
Moving the "check if min_size/max_size/desired_capacity..." code to execute BEFORE the desired_capacity code is used in the following operation:
num_new_inst_needed = desired_capacity - len(new_instances)
Otherwise the following exception occurs when desired_capacity is not specified and you're replacing instances:
num_new_inst_needed = desired_capacity - len(new_instances)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
Stack Trace:
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File "/var/lib/awx/.ansible/tmp/ansible-tmp-1478229985.74-62334493713074/ec2_asg", line 3044, in <module>
main()
File "/var/lib/awx/.ansible/tmp/ansible-tmp-1478229985.74-62334493713074/ec2_asg", line 3038, in main
replace_changed, asg_properties=replace(connection, module)
File "/var/lib/awx/.ansible/tmp/ansible-tmp-1478229985.74-62334493713074/ec2_asg", line 2778, in replace
num_new_inst_needed = desired_capacity - len(new_instances)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "ec2_asg"}, "module_stderr": "Traceback (most recent call last):\n File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1478229985.74-62334493713074/ec2_asg\", line 3044, in <module>\n main()\n File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1478229985.74-62334493713074/ec2_asg\", line 3038, in main\n replace_changed, asg_properties=replace(connection, module)\n File \"/var/lib/awx/.ansible/tmp/ansible-tmp-1478229985.74-62334493713074/ec2_asg\", line 2778, in replace\n num_new_inst_needed = desired_capacity - len(new_instances)\nTypeError: unsupported operand type(s) for -: 'NoneType' and 'int'\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}
to retry, use: --limit @
-rw-r--r-- | cloud/amazon/ec2_asg.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/cloud/amazon/ec2_asg.py b/cloud/amazon/ec2_asg.py index 6cf0bc8f..beb1d5ad 100644 --- a/cloud/amazon/ec2_asg.py +++ b/cloud/amazon/ec2_asg.py @@ -598,6 +598,14 @@ def replace(connection, module): instances = props['instances'] if replace_instances: instances = replace_instances + + #check if min_size/max_size/desired capacity have been specified and if not use ASG values + if min_size is None: + min_size = as_group.min_size + if max_size is None: + max_size = as_group.max_size + if desired_capacity is None: + desired_capacity = as_group.desired_capacity # check to see if instances are replaceable if checking launch configs new_instances, old_instances = get_instances_by_lc(props, lc_check, instances) @@ -620,14 +628,7 @@ def replace(connection, module): if not old_instances: changed = False return(changed, props) - - #check if min_size/max_size/desired capacity have been specified and if not use ASG values - if min_size is None: - min_size = as_group.min_size - if max_size is None: - max_size = as_group.max_size - if desired_capacity is None: - desired_capacity = as_group.desired_capacity + # 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. |