From e45858ba7fd87c33687527bb2fe4bf39645845d4 Mon Sep 17 00:00:00 2001 From: willthames Date: Thu, 19 Jun 2014 11:21:28 +1000 Subject: [PATCH] Delay instance tagging to later in the instance creation process Tagging recently created instances can result in InvalidInstanceID.NotFound errors. By delaying the tagging until the last part of instance creation, we should be typically more fortunate (avoiding all such race conditions might need more work) --- cloud/ec2 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cloud/ec2 b/cloud/ec2 index ac1f4012f4b..654bf6e4cf4 100644 --- a/cloud/ec2 +++ b/cloud/ec2 @@ -913,12 +913,6 @@ def create_instances(module, ec2, override_count=None): except boto.exception.BotoServerError, e: module.fail_json(msg = "Instance creation failed => %s: %s" % (e.error_code, e.error_message)) - if instance_tags: - try: - ec2.create_tags(instids, instance_tags) - except boto.exception.EC2ResponseError, e: - module.fail_json(msg = "Instance tagging failed => %s: %s" % (e.error_code, e.error_message)) - # wait here until the instances are up num_running = 0 wait_timeout = time.time() + wait_timeout @@ -950,6 +944,13 @@ def create_instances(module, ec2, override_count=None): for inst in res.instances: inst.modify_attribute('sourceDestCheck', False) + # Leave this as late as possible to try and avoid InvalidInstanceID.NotFound + if instance_tags: + try: + ec2.create_tags(instids, instance_tags) + except boto.exception.EC2ResponseError, e: + module.fail_json(msg = "Instance tagging failed => %s: %s" % (e.error_code, e.error_message)) + instance_dict_array = [] created_instance_ids = [] for inst in running_instances: