mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
e2d86e4f43
commit
ba4838cde5
1 changed files with 40 additions and 0 deletions
|
@ -70,6 +70,20 @@ options:
|
||||||
default: null
|
default: null
|
||||||
aliases: []
|
aliases: []
|
||||||
version_added: "1.6"
|
version_added: "1.6"
|
||||||
|
wait:
|
||||||
|
description:
|
||||||
|
- Wait for the specified action to complete before returning.
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
aliases: []
|
||||||
|
version_added: "1.6"
|
||||||
|
wait_timeout:
|
||||||
|
description:
|
||||||
|
- How long before wait gives up, in seconds
|
||||||
|
required: false
|
||||||
|
default: 300
|
||||||
|
aliases: []
|
||||||
|
version_added: "1.6"
|
||||||
|
|
||||||
requirements: [ "boto" ]
|
requirements: [ "boto" ]
|
||||||
author: Vincent Viallet
|
author: Vincent Viallet
|
||||||
|
@ -124,6 +138,8 @@ def main():
|
||||||
name=dict(required=True),
|
name=dict(required=True),
|
||||||
key_material=dict(required=False),
|
key_material=dict(required=False),
|
||||||
state = dict(default='present', choices=['present', 'absent']),
|
state = dict(default='present', choices=['present', 'absent']),
|
||||||
|
wait = dict(type='bool', default=False),
|
||||||
|
wait_timeout = dict(default=300),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
@ -134,6 +150,8 @@ def main():
|
||||||
name = module.params['name']
|
name = module.params['name']
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
key_material = module.params.get('key_material')
|
key_material = module.params.get('key_material')
|
||||||
|
wait = module.params.get('wait')
|
||||||
|
wait_timeout = int(module.params.get('wait_timeout'))
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
|
@ -148,6 +166,16 @@ def main():
|
||||||
'''found a match, delete it'''
|
'''found a match, delete it'''
|
||||||
try:
|
try:
|
||||||
key.delete()
|
key.delete()
|
||||||
|
if wait:
|
||||||
|
start = time.time()
|
||||||
|
action_complete = False
|
||||||
|
while (time.time() - start) < wait_timeout:
|
||||||
|
if not ec2.get_key_pair(name):
|
||||||
|
action_complete = True
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
|
if not action_complete:
|
||||||
|
module.fail_json(msg="timed out while waiting for the key to be removed")
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
module.fail_json(msg="Unable to delete key pair '%s' - %s" % (key, e))
|
module.fail_json(msg="Unable to delete key pair '%s' - %s" % (key, e))
|
||||||
else:
|
else:
|
||||||
|
@ -178,6 +206,18 @@ def main():
|
||||||
retrieve the private key
|
retrieve the private key
|
||||||
'''
|
'''
|
||||||
key = ec2.create_key_pair(name)
|
key = ec2.create_key_pair(name)
|
||||||
|
|
||||||
|
if wait:
|
||||||
|
start = time.time()
|
||||||
|
action_complete = False
|
||||||
|
while (time.time() - start) < wait_timeout:
|
||||||
|
if ec2.get_key_pair(name):
|
||||||
|
action_complete = True
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
|
if not action_complete:
|
||||||
|
module.fail_json(msg="timed out while waiting for the key to be created")
|
||||||
|
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
if key:
|
if key:
|
||||||
|
|
Loading…
Reference in a new issue