mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Remove all reference to obsolete client_id and rename api_key to the for v2 more correct api_token
This commit is contained in:
parent
02883a460b
commit
459fd81435
1 changed files with 85 additions and 91 deletions
|
@ -23,82 +23,79 @@ description:
|
||||||
- Create/delete a droplet in DigitalOcean and optionally wait for it to be 'running', or deploy an SSH key.
|
- Create/delete a droplet in DigitalOcean and optionally wait for it to be 'running', or deploy an SSH key.
|
||||||
version_added: "1.3"
|
version_added: "1.3"
|
||||||
options:
|
options:
|
||||||
command:
|
command:
|
||||||
description:
|
description:
|
||||||
- Which target you want to operate on.
|
- Which target you want to operate on.
|
||||||
default: droplet
|
default: droplet
|
||||||
choices: ['droplet', 'ssh']
|
choices: ['droplet', 'ssh']
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- 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:
|
api_token:
|
||||||
description:
|
description:
|
||||||
- DigitalOcean manager id.
|
- DigitalOcean api token.
|
||||||
api_key:
|
id:
|
||||||
description:
|
description:
|
||||||
- DigitalOcean api key.
|
- Numeric, the droplet id you want to operate on.
|
||||||
id:
|
name:
|
||||||
description:
|
description:
|
||||||
- Numeric, the droplet id you want to operate on.
|
- String, this is the name of the droplet - must be formatted by hostname rules, or the name of a SSH key.
|
||||||
name:
|
unique_name:
|
||||||
description:
|
description:
|
||||||
- String, this is the name of the droplet - must be formatted by hostname rules, or the name of a SSH key.
|
- Bool, require unique hostnames. By default, DigitalOcean allows multiple hosts with the same name. Setting this to "yes" allows only one host per name. Useful for idempotence.
|
||||||
unique_name:
|
version_added: "1.4"
|
||||||
description:
|
default: "no"
|
||||||
- Bool, require unique hostnames. By default, DigitalOcean allows multiple hosts with the same name. Setting this to "yes" allows only one host per name. Useful for idempotence.
|
choices: [ "yes", "no" ]
|
||||||
version_added: "1.4"
|
size_id:
|
||||||
default: "no"
|
description:
|
||||||
choices: [ "yes", "no" ]
|
- This is the slug of the size you would like the droplet created with.
|
||||||
size_id:
|
image_id:
|
||||||
description:
|
description:
|
||||||
- This is the slug of the size you would like the droplet created with.
|
- This is the slug of the image you would like the droplet created with.
|
||||||
image_id:
|
region_id:
|
||||||
description:
|
description:
|
||||||
- This is the slug of the image you would like the droplet created with.
|
- This is the slug of the region you would like your server to be created in.
|
||||||
region_id:
|
ssh_key_ids:
|
||||||
description:
|
description:
|
||||||
- This is the slug of the region you would like your server to be created in.
|
- Optional, array of of ssh_key_ids that you would like to be added to the server.
|
||||||
ssh_key_ids:
|
virtio:
|
||||||
description:
|
description:
|
||||||
- Optional, array of of ssh_key_ids that you would like to be added to the server.
|
- "Bool, turn on virtio driver in droplet for improved network and storage I/O."
|
||||||
virtio:
|
version_added: "1.4"
|
||||||
description:
|
default: "yes"
|
||||||
- "Bool, turn on virtio driver in droplet for improved network and storage I/O."
|
choices: [ "yes", "no" ]
|
||||||
version_added: "1.4"
|
private_networking:
|
||||||
default: "yes"
|
description:
|
||||||
choices: [ "yes", "no" ]
|
- "Bool, add an additional, private network interface to droplet for inter-droplet communication."
|
||||||
private_networking:
|
version_added: "1.4"
|
||||||
description:
|
default: "no"
|
||||||
- "Bool, add an additional, private network interface to droplet for inter-droplet communication."
|
choices: [ "yes", "no" ]
|
||||||
version_added: "1.4"
|
backups_enabled:
|
||||||
default: "no"
|
description:
|
||||||
choices: [ "yes", "no" ]
|
- Optional, Boolean, enables backups for your droplet.
|
||||||
backups_enabled:
|
version_added: "1.6"
|
||||||
description:
|
default: "no"
|
||||||
- Optional, Boolean, enables backups for your droplet.
|
choices: [ "yes", "no" ]
|
||||||
version_added: "1.6"
|
user_data:
|
||||||
default: "no"
|
description:
|
||||||
choices: [ "yes", "no" ]
|
- opaque blob of data which is made available to the droplet
|
||||||
user_data:
|
version_added: "1.10"
|
||||||
description:
|
required: false
|
||||||
- opaque blob of data which is made available to the droplet
|
default: None
|
||||||
version_added: "1.10"
|
wait:
|
||||||
required: false
|
description:
|
||||||
default: None
|
- Wait for the droplet to be in state 'running' before returning. If wait is "no" an ip_address may not be returned.
|
||||||
wait:
|
default: "yes"
|
||||||
description:
|
choices: [ "yes", "no" ]
|
||||||
- Wait for the droplet to be in state 'running' before returning. If wait is "no" an ip_address may not be returned.
|
wait_timeout:
|
||||||
default: "yes"
|
description:
|
||||||
choices: [ "yes", "no" ]
|
- How long before wait gives up, in seconds.
|
||||||
wait_timeout:
|
default: 300
|
||||||
description:
|
ssh_pub_key:
|
||||||
- How long before wait gives up, in seconds.
|
description:
|
||||||
default: 300
|
- The public SSH key you want to add to your account.
|
||||||
ssh_pub_key:
|
|
||||||
description:
|
|
||||||
- The public SSH key you want to add to your account.
|
|
||||||
|
|
||||||
notes:
|
notes:
|
||||||
- Two environment variables can be used, DO_API_KEY and DO_API_TOKEN. They both refer to the v2 token.
|
- Two environment variables can be used, DO_API_KEY and DO_API_TOKEN. They both refer to the v2 token.
|
||||||
|
@ -116,7 +113,7 @@ EXAMPLES = '''
|
||||||
command=ssh
|
command=ssh
|
||||||
name=my_ssh_key
|
name=my_ssh_key
|
||||||
ssh_pub_key='ssh-rsa AAAA...'
|
ssh_pub_key='ssh-rsa AAAA...'
|
||||||
api_key=XXX
|
api_token=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)
|
||||||
|
@ -125,7 +122,7 @@ EXAMPLES = '''
|
||||||
state=present
|
state=present
|
||||||
command=droplet
|
command=droplet
|
||||||
name=mydroplet
|
name=mydroplet
|
||||||
api_key=XXX
|
api_token=XXX
|
||||||
size_id=2gb
|
size_id=2gb
|
||||||
region_id=ams2
|
region_id=ams2
|
||||||
image_id=fedora-19-x64
|
image_id=fedora-19-x64
|
||||||
|
@ -143,7 +140,7 @@ EXAMPLES = '''
|
||||||
command=droplet
|
command=droplet
|
||||||
id=123
|
id=123
|
||||||
name=mydroplet
|
name=mydroplet
|
||||||
api_key=XXX
|
api_token=XXX
|
||||||
size_id=2gb
|
size_id=2gb
|
||||||
region_id=ams2
|
region_id=ams2
|
||||||
image_id=fedora-19-x64
|
image_id=fedora-19-x64
|
||||||
|
@ -158,7 +155,7 @@ EXAMPLES = '''
|
||||||
state=present
|
state=present
|
||||||
ssh_key_ids=[id1,id2]
|
ssh_key_ids=[id1,id2]
|
||||||
name=mydroplet
|
name=mydroplet
|
||||||
api_key=XXX
|
api_token=XXX
|
||||||
size_id=2gb
|
size_id=2gb
|
||||||
region_id=ams2
|
region_id=ams2
|
||||||
image_id=fedora-19-x64
|
image_id=fedora-19-x64
|
||||||
|
@ -233,8 +230,8 @@ class Droplet(JsonfyMixIn):
|
||||||
return self.manager.destroy_droplet(self.id, scrub_data=True)
|
return self.manager.destroy_droplet(self.id, scrub_data=True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup(cls, client_id, api_key):
|
def setup(cls, api_token):
|
||||||
cls.manager = DoManager(client_id, api_key, api_version=2)
|
cls.manager = DoManager(None, api_token, api_version=2)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add(cls, name, size_id, image_id, region_id, ssh_key_ids=None, virtio=True, private_networking=False, backups_enabled=False, user_data=None):
|
def add(cls, name, size_id, image_id, region_id, ssh_key_ids=None, virtio=True, private_networking=False, backups_enabled=False, user_data=None):
|
||||||
|
@ -280,8 +277,8 @@ class SSH(JsonfyMixIn):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup(cls, client_id, api_key):
|
def setup(cls, api_token):
|
||||||
cls.manager = DoManager(client_id, api_key, api_version=2)
|
cls.manager = DoManager(None, api_token, api_version=2)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def find(cls, name):
|
def find(cls, name):
|
||||||
|
@ -311,18 +308,16 @@ def core(module):
|
||||||
return v
|
return v
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# params['client_id'] will be None even if client_id is not passed in
|
api_token = module.params['api_token'] or os.environ['DO_API_TOKEN'] or os.environ['DO_API_KEY']
|
||||||
api_key = module.params['api_key'] or os.environ['DO_API_TOKEN'] or os.environ['DO_API_KEY']
|
|
||||||
except KeyError, e:
|
except KeyError, e:
|
||||||
module.fail_json(msg='Unable to load %s' % e.message)
|
module.fail_json(msg='Unable to load %s' % e.message)
|
||||||
|
|
||||||
changed = True
|
changed = True
|
||||||
command = module.params['command']
|
command = module.params['command']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
client_id = 'notused'
|
|
||||||
|
|
||||||
if command == 'droplet':
|
if command == 'droplet':
|
||||||
Droplet.setup(client_id, api_key)
|
Droplet.setup(api_token)
|
||||||
if state in ('active', 'present'):
|
if state in ('active', 'present'):
|
||||||
|
|
||||||
# First, try to find a droplet by id.
|
# First, try to find a droplet by id.
|
||||||
|
@ -375,7 +370,7 @@ def core(module):
|
||||||
module.exit_json(changed=True)
|
module.exit_json(changed=True)
|
||||||
|
|
||||||
elif command == 'ssh':
|
elif command == 'ssh':
|
||||||
SSH.setup(client_id, api_key)
|
SSH.setup(api_token)
|
||||||
name = getkeyordie('name')
|
name = getkeyordie('name')
|
||||||
if state in ('active', 'present'):
|
if state in ('active', 'present'):
|
||||||
key = SSH.find(name)
|
key = SSH.find(name)
|
||||||
|
@ -397,8 +392,7 @@ def main():
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
command = dict(choices=['droplet', 'ssh'], default='droplet'),
|
command = dict(choices=['droplet', 'ssh'], default='droplet'),
|
||||||
state = dict(choices=['active', 'present', 'absent', 'deleted'], default='present'),
|
state = dict(choices=['active', 'present', 'absent', 'deleted'], default='present'),
|
||||||
client_id = dict(aliases=['CLIENT_ID'], no_log=True),
|
api_token = dict(aliases=['API_TOKEN'], no_log=True),
|
||||||
api_key = dict(aliases=['API_KEY'], no_log=True),
|
|
||||||
name = dict(type='str'),
|
name = dict(type='str'),
|
||||||
size_id = dict(),
|
size_id = dict(),
|
||||||
image_id = dict(),
|
image_id = dict(),
|
||||||
|
|
Loading…
Reference in a new issue