mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #4148 from ralphbean/digital_ocean_cleanup
Cosmetic - Digital ocean cleanup
This commit is contained in:
commit
39659db72a
1 changed files with 37 additions and 61 deletions
|
@ -33,7 +33,7 @@ options:
|
||||||
- Indicate desired state of the target.
|
- Indicate desired state of the target.
|
||||||
default: present
|
default: present
|
||||||
choices: ['present', 'active', 'absent', 'deleted']
|
choices: ['present', 'active', 'absent', 'deleted']
|
||||||
client_id:
|
client_id:
|
||||||
description:
|
description:
|
||||||
- Digital Ocean manager id.
|
- Digital Ocean manager id.
|
||||||
api_key:
|
api_key:
|
||||||
|
@ -58,7 +58,7 @@ options:
|
||||||
description:
|
description:
|
||||||
- Optional, comma separated list of ssh_key_ids that you would like to be added to the server
|
- Optional, comma separated list of ssh_key_ids that you would like to be added to the server
|
||||||
wait:
|
wait:
|
||||||
description:
|
description:
|
||||||
- Wait for the droplet to be in state 'running' before returning. If wait is "no" an ip_address may not be returned.
|
- Wait for the droplet to be in state 'running' before returning. If wait is "no" an ip_address may not be returned.
|
||||||
default: "yes"
|
default: "yes"
|
||||||
choices: [ "yes", "no" ]
|
choices: [ "yes", "no" ]
|
||||||
|
@ -81,25 +81,25 @@ EXAMPLES = '''
|
||||||
# If no existing key matches this name, a new key is created, the ssh key id is returned and changed = False
|
# If no existing key matches this name, a new key is created, the ssh key id is returned and changed = False
|
||||||
|
|
||||||
- digital_ocean: >
|
- digital_ocean: >
|
||||||
state=present
|
state=present
|
||||||
command=ssh
|
command=ssh
|
||||||
name=my_ssh_key
|
name=my_ssh_key
|
||||||
ssh_pub_key='ssh-rsa AAAA...'
|
ssh_pub_key='ssh-rsa AAAA...'
|
||||||
client_id=XXX
|
client_id=XXX
|
||||||
api_key=XXX
|
api_key=XXX
|
||||||
|
|
||||||
# Create a new Droplet
|
# Create a new Droplet
|
||||||
# Will return the droplet details including the droplet id (used for idempotence)
|
# Will return the droplet details including the droplet id (used for idempotence)
|
||||||
|
|
||||||
- digital_ocean: >
|
- digital_ocean: >
|
||||||
state=present
|
state=present
|
||||||
command=droplet
|
command=droplet
|
||||||
name=my_new_droplet
|
name=my_new_droplet
|
||||||
client_id=XXX
|
client_id=XXX
|
||||||
api_key=XXX
|
api_key=XXX
|
||||||
size_id=1
|
size_id=1
|
||||||
region_id=2
|
region_id=2
|
||||||
image_id=3
|
image_id=3
|
||||||
wait_timeout=500
|
wait_timeout=500
|
||||||
register: my_droplet
|
register: my_droplet
|
||||||
- debug: msg="ID: {{ my_droplet.droplet.id }} IP: {{ my_droplet.droplet.ip_address }}"
|
- debug: msg="ID: {{ my_droplet.droplet.id }} IP: {{ my_droplet.droplet.ip_address }}"
|
||||||
|
@ -109,55 +109,31 @@ EXAMPLES = '''
|
||||||
# If no droplet matches the id, a new droplet will be created and the droplet details (including the new id) are returned, changed = True.
|
# If no droplet matches the id, a new droplet will be created and the droplet details (including the new id) are returned, changed = True.
|
||||||
|
|
||||||
- digital_ocean: >
|
- digital_ocean: >
|
||||||
state=present
|
state=present
|
||||||
command=droplet
|
command=droplet
|
||||||
id=123
|
id=123
|
||||||
name=my_new_droplet
|
name=my_new_droplet
|
||||||
client_id=XXX
|
client_id=XXX
|
||||||
api_key=XXX
|
api_key=XXX
|
||||||
size_id=1
|
size_id=1
|
||||||
region_id=2
|
region_id=2
|
||||||
image_id=3
|
image_id=3
|
||||||
wait_timeout=500
|
wait_timeout=500
|
||||||
|
|
||||||
# Create a droplet with ssh key
|
# Create a droplet with ssh key
|
||||||
# The ssh key id can be passed as argument at the creation of a droplet (see ssh_key_ids).
|
# The ssh key id can be passed as argument at the creation of a droplet (see ssh_key_ids).
|
||||||
# Several keys can be added to ssh_key_ids as id1,id2,id3
|
# Several keys can be added to ssh_key_ids as id1,id2,id3
|
||||||
# The keys are used to connect as root to the droplet.
|
# The keys are used to connect as root to the droplet.
|
||||||
|
|
||||||
- digital_ocean: >
|
- digital_ocean: >
|
||||||
state=present
|
state=present
|
||||||
ssh_key_ids=id1,id2
|
ssh_key_ids=id1,id2
|
||||||
name=my_new_droplet
|
name=my_new_droplet
|
||||||
client_id=XXX
|
client_id=XXX
|
||||||
api_key=XXX
|
api_key=XXX
|
||||||
size_id=1
|
size_id=1
|
||||||
region_id=2
|
region_id=2
|
||||||
image_id=3
|
image_id=3
|
||||||
=======
|
|
||||||
- digital_ocean: state=present command=ssh name=my_ssh_key ssh_pub_key='ssh-rsa AAAA...' client_id=XXX api_key=XXX
|
|
||||||
|
|
||||||
If a key matches this name, will return the ssh key id and changed = False
|
|
||||||
If no existing key matches this name, a new key is created, the ssh key id is returned and changed = False
|
|
||||||
|
|
||||||
# Create a new Droplet
|
|
||||||
- digital_ocean: state=present command=droplet name=my_new_droplet client_id=XXX api_key=XXX size_id=1 region_id=2 image_id=3 wait_timeout=500
|
|
||||||
|
|
||||||
Will return the droplet details including the droplet id (used for idempotence)
|
|
||||||
|
|
||||||
# Ensure a droplet is present
|
|
||||||
- digital_ocean: state=present command=droplet id=123 name=my_new_droplet client_id=XXX api_key=XXX size_id=1 region_id=2 image_id=3 wait_timeout=500
|
|
||||||
|
|
||||||
If droplet id already exist, will return the droplet details and changed = False
|
|
||||||
If no droplet matches the id, a new droplet will be created and the droplet details (including the new id) are returned, changed = True.
|
|
||||||
|
|
||||||
# Create a droplet with ssh key
|
|
||||||
- digital_ocean: state=present ssh_key_ids=id name=my_new_droplet client_id=XXX api_key=XXX size_id=1 region_id=2 image_id=3
|
|
||||||
|
|
||||||
The ssh key id can be passed as argument at the creation of a droplet (see ssh_key_ids).
|
|
||||||
Several keys can be added to ssh_key_ids as id1,id2,id3
|
|
||||||
|
|
||||||
The keys are used to connect as root to the droplet.
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
@ -222,7 +198,7 @@ class Droplet(JsonfyMixIn):
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
return self.manager.destroy_droplet(self.id)
|
return self.manager.destroy_droplet(self.id)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup(cls, client_id, api_key):
|
def setup(cls, client_id, api_key):
|
||||||
cls.manager = DoManager(client_id, api_key)
|
cls.manager = DoManager(client_id, api_key)
|
||||||
|
@ -307,10 +283,10 @@ def core(module):
|
||||||
droplet = Droplet.find(module.params['id'])
|
droplet = Droplet.find(module.params['id'])
|
||||||
if not droplet:
|
if not droplet:
|
||||||
droplet = Droplet.add(
|
droplet = Droplet.add(
|
||||||
name=getkeyordie('name'),
|
name=getkeyordie('name'),
|
||||||
size_id=getkeyordie('size_id'),
|
size_id=getkeyordie('size_id'),
|
||||||
image_id=getkeyordie('image_id'),
|
image_id=getkeyordie('image_id'),
|
||||||
region_id=getkeyordie('region_id'),
|
region_id=getkeyordie('region_id'),
|
||||||
ssh_key_ids=module.params['ssh_key_ids']
|
ssh_key_ids=module.params['ssh_key_ids']
|
||||||
)
|
)
|
||||||
if droplet.is_powered_on():
|
if droplet.is_powered_on():
|
||||||
|
@ -320,7 +296,7 @@ def core(module):
|
||||||
wait_timeout=getkeyordie('wait_timeout')
|
wait_timeout=getkeyordie('wait_timeout')
|
||||||
)
|
)
|
||||||
module.exit_json(changed=changed, droplet=droplet.to_json())
|
module.exit_json(changed=changed, droplet=droplet.to_json())
|
||||||
|
|
||||||
elif state in ('absent', 'deleted'):
|
elif state in ('absent', 'deleted'):
|
||||||
droplet = Droplet.find(getkeyordie('id'))
|
droplet = Droplet.find(getkeyordie('id'))
|
||||||
if not droplet:
|
if not droplet:
|
||||||
|
|
Loading…
Reference in a new issue