mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 14:41:23 -07:00
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.
This commit is contained in:
parent
2165bac212
commit
9bc330c89b
1 changed files with 12 additions and 2 deletions
|
@ -227,7 +227,8 @@ options:
|
||||||
instance_initiated_shutdown_behavior:
|
instance_initiated_shutdown_behavior:
|
||||||
version_added: "2.2"
|
version_added: "2.2"
|
||||||
description:
|
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
|
required: false
|
||||||
default: 'stop'
|
default: 'stop'
|
||||||
choices: [ "stop", "terminate" ]
|
choices: [ "stop", "terminate" ]
|
||||||
|
@ -1193,7 +1194,16 @@ def create_instances(module, ec2, vpc, override_count=None):
|
||||||
# (the default) or 'terminate' here.
|
# (the default) or 'terminate' here.
|
||||||
params['instance_initiated_shutdown_behavior'] = instance_initiated_shutdown_behavior or 'stop'
|
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]
|
instids = [i.id for i in res.instances]
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue