Merge pull request #5881 from willthames/ec2_keys
Minor tweaks to simplify examples and documentation
This commit is contained in:
commit
bf149474e5
1 changed files with 7 additions and 37 deletions
|
@ -35,17 +35,16 @@ options:
|
||||||
- EC2 secret key
|
- EC2 secret key
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
aliases: ['aws_secret_key']
|
aliases: ['aws_secret_key', 'secret_key']
|
||||||
ec2_access_key:
|
ec2_access_key:
|
||||||
description:
|
description:
|
||||||
- EC2 access key
|
- EC2 access key
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
aliases: ['aws_access_key']
|
aliases: ['aws_access_key', 'access_key']
|
||||||
state:
|
state:
|
||||||
version_added: "1.5"
|
|
||||||
description:
|
description:
|
||||||
- create or delete security group
|
- create or delete keypair
|
||||||
required: false
|
required: false
|
||||||
default: 'present'
|
default: 'present'
|
||||||
aliases: []
|
aliases: []
|
||||||
|
@ -55,15 +54,15 @@ author: Vincent Viallet
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
# Note: None of these examples set aws_access_key, aws_secret_key, or region.
|
||||||
|
# It is assumed that their matching environment variables are set.
|
||||||
|
|
||||||
# Creates a new ec2 key pair named `example` if not present, returns generated
|
# Creates a new ec2 key pair named `example` if not present, returns generated
|
||||||
# private key
|
# private key
|
||||||
- name: example ec2 key
|
- name: example ec2 key
|
||||||
local_action:
|
local_action:
|
||||||
module: ec2_key
|
module: ec2_key
|
||||||
name: example
|
name: example
|
||||||
region: eu-west-1a
|
|
||||||
ec2_secret_key: SECRET
|
|
||||||
ec2_access_key: ACCESS
|
|
||||||
|
|
||||||
# Creates a new ec2 key pair named `example` if not present using provided key
|
# Creates a new ec2 key pair named `example` if not present using provided key
|
||||||
# material
|
# material
|
||||||
|
@ -71,9 +70,6 @@ EXAMPLES = '''
|
||||||
local_action:
|
local_action:
|
||||||
module: ec2_key
|
module: ec2_key
|
||||||
name: example2
|
name: example2
|
||||||
region: eu-west-1a
|
|
||||||
ec2_secret_key: SECRET
|
|
||||||
ec2_access_key: ACCESS
|
|
||||||
key_material: 'ssh-rsa AAAAxyz...== me@example.com'
|
key_material: 'ssh-rsa AAAAxyz...== me@example.com'
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
|
@ -83,9 +79,6 @@ EXAMPLES = '''
|
||||||
local_action:
|
local_action:
|
||||||
module: ec2_key
|
module: ec2_key
|
||||||
name: example3
|
name: example3
|
||||||
region: eu-west-1a
|
|
||||||
ec2_secret_key: SECRET
|
|
||||||
ec2_access_key: ACCESS
|
|
||||||
key_material: "{{ item }}"
|
key_material: "{{ item }}"
|
||||||
with_file: /path/to/public_key.id_rsa.pub
|
with_file: /path/to/public_key.id_rsa.pub
|
||||||
|
|
||||||
|
@ -95,9 +88,6 @@ EXAMPLES = '''
|
||||||
module: ec2_key
|
module: ec2_key
|
||||||
name: example
|
name: example
|
||||||
state: absent
|
state: absent
|
||||||
region: eu-west-1a
|
|
||||||
ec2_secret_key: SECRET
|
|
||||||
ec2_access_key: ACCESS
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -120,31 +110,13 @@ def main():
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# def get_ec2_creds(module):
|
|
||||||
# return ec2_url, ec2_access_key, ec2_secret_key, region
|
|
||||||
ec2_url, ec2_access_key, ec2_secret_key, region = get_ec2_creds(module)
|
|
||||||
|
|
||||||
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')
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
# If we have a region specified, connect to its endpoint.
|
ec2 = ec2_connect(module)
|
||||||
if region:
|
|
||||||
try:
|
|
||||||
ec2 = boto.ec2.connect_to_region(region, aws_access_key_id=ec2_access_key, aws_secret_access_key=ec2_secret_key)
|
|
||||||
except boto.exception.NoAuthHandlerFound, e:
|
|
||||||
module.fail_json(msg=str(e))
|
|
||||||
# Otherwise, no region so we fallback to the old connection method
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
if ec2_url: # if we have an URL set, connect to the specified endpoint
|
|
||||||
ec2 = boto.connect_ec2_endpoint(ec2_url, ec2_access_key, ec2_secret_key)
|
|
||||||
else: # otherwise it's Amazon.
|
|
||||||
ec2 = boto.connect_ec2(ec2_access_key, ec2_secret_key)
|
|
||||||
except boto.exception.NoAuthHandlerFound, e:
|
|
||||||
module.fail_json(msg=str(e))
|
|
||||||
|
|
||||||
# find the key if present
|
# find the key if present
|
||||||
key = ec2.get_key_pair(name)
|
key = ec2.get_key_pair(name)
|
||||||
|
@ -186,8 +158,6 @@ def main():
|
||||||
'''
|
'''
|
||||||
key = ec2.create_key_pair(name)
|
key = ec2.create_key_pair(name)
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
|
||||||
module.fail_json(msg="Unsupported state requested: %s" % state)
|
|
||||||
|
|
||||||
if key:
|
if key:
|
||||||
data = {
|
data = {
|
||||||
|
|
Loading…
Reference in a new issue