summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSloane Hertel <shertel@redhat.com>2017-09-11 21:16:00 -0400
committerToshio Kuratomi <a.badger@gmail.com>2017-09-11 19:54:35 -0700
commit73304f50a3784f7fec4595f6fb942c0f455b800e (patch)
tree672ec6a70bc5d1b4f9e8dd61bded65a891decfb8
parent0d2154646ff88ce1cbd309076e6941b1ca7eae0e (diff)
downloadansible-73304f50a3784f7fec4595f6fb942c0f455b800e.tar.gz
ec2: fixes #19521, fixes #29456 - create instance-store AMI instances with correct shutdown behavior (#28885)
* Create instance-store AMI instances with 'terminate' as the shutdown behavior since it is required. * Match on the error code instead of searching for a string in the message. * Narrow conditional to only fix shutdown behavior if fixing it would help * Fix pep8.
-rw-r--r--lib/ansible/modules/cloud/amazon/ec2.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/ansible/modules/cloud/amazon/ec2.py b/lib/ansible/modules/cloud/amazon/ec2.py
index b77a74e218..a52b1fa3bf 100644
--- a/lib/ansible/modules/cloud/amazon/ec2.py
+++ b/lib/ansible/modules/cloud/amazon/ec2.py
@@ -227,7 +227,8 @@ options:
instance_initiated_shutdown_behavior:
version_added: "2.2"
description:
- - Set whether AWS will Stop or Terminate an instance on shutdown
+ - Set whether AWS will Stop or Terminate an instance on shutdown. This parameter is ignored when using instance-store
+ images (which require termination on shutdown).
required: false
default: 'stop'
choices: [ "stop", "terminate" ]
@@ -1193,7 +1194,16 @@ def create_instances(module, ec2, vpc, override_count=None):
# (the default) or 'terminate' here.
params['instance_initiated_shutdown_behavior'] = instance_initiated_shutdown_behavior or 'stop'
- res = ec2.run_instances(**params)
+ try:
+ res = ec2.run_instances(**params)
+ except boto.exception.EC2ResponseError as e:
+ if (params['instance_initiated_shutdown_behavior'] != 'terminate' and
+ "InvalidParameterCombination" == e.error_code):
+ params['instance_initiated_shutdown_behavior'] = 'terminate'
+ res = ec2.run_instances(**params)
+ else:
+ raise
+
instids = [i.id for i in res.instances]
while True:
try: