mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
Rebase attempt
No idea if I'm rebasing properly or not. This is my first attempt.
This commit is contained in:
@@ -23,22 +23,22 @@ description:
|
||||
options:
|
||||
ec2_url:
|
||||
description:
|
||||
- url to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints)
|
||||
- Url to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints). Must be specified if region is not used. If not set then the value of the EC2_URL environment variable, if any, is used
|
||||
required: false
|
||||
default: null
|
||||
aliases: []
|
||||
ec2_secret_key:
|
||||
aws_secret_key:
|
||||
description:
|
||||
- ec2 secret key
|
||||
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
|
||||
required: false
|
||||
default: null
|
||||
aliases: []
|
||||
ec2_access_key:
|
||||
aliases: [ 'ec2_secret_key', 'secret_key' ]
|
||||
aws_access_key:
|
||||
description:
|
||||
- ec2 access key
|
||||
- AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
|
||||
required: false
|
||||
default: null
|
||||
aliases: []
|
||||
aliases: ['ec2_access_key', 'access_key' ]
|
||||
instance_id:
|
||||
description:
|
||||
- instance id of the image to create
|
||||
@@ -71,10 +71,10 @@ options:
|
||||
aliases: []
|
||||
region:
|
||||
description:
|
||||
- the EC2 region to use
|
||||
- The AWS region to use. Must be specified if ec2_url is not used. If not specified then the value of the EC2_REGION environment variable, if any, is used.
|
||||
required: false
|
||||
default: null
|
||||
aliases: []
|
||||
aliases: [ 'aws_region', 'ec2_region' ]
|
||||
description:
|
||||
description:
|
||||
- An optional human-readable string describing the contents and purpose of the AMI.
|
||||
@@ -113,8 +113,8 @@ EXAMPLES = '''
|
||||
# Basic AMI Creation
|
||||
- local_action:
|
||||
module: ec2_ami
|
||||
ec2_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
||||
ec2_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
||||
aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
instance_id: i-xxxxxx
|
||||
wait: yes
|
||||
name: newtest
|
||||
@@ -123,8 +123,9 @@ EXAMPLES = '''
|
||||
# Basic AMI Creation, without waiting
|
||||
- local_action:
|
||||
module: ec2_ami
|
||||
ec2_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
||||
ec2_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
||||
aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
region: xxxxxx
|
||||
instance_id: i-xxxxxx
|
||||
wait: no
|
||||
name: newtest
|
||||
@@ -133,8 +134,9 @@ EXAMPLES = '''
|
||||
# Deregister/Delete AMI
|
||||
- local_action:
|
||||
module: ec2_ami
|
||||
ec2_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
||||
ec2_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
||||
aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
region: xxxxxx
|
||||
image_id: ${instance.image_id}
|
||||
delete_snapshot: True
|
||||
state: absent
|
||||
@@ -142,8 +144,9 @@ EXAMPLES = '''
|
||||
# Deregister AMI
|
||||
- local_action:
|
||||
module: ec2_ami
|
||||
ec2_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
||||
ec2_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
||||
aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
region: xxxxxx
|
||||
image_id: ${instance.image_id}
|
||||
delete_snapshot: False
|
||||
state: absent
|
||||
@@ -152,6 +155,15 @@ EXAMPLES = '''
|
||||
import sys
|
||||
import time
|
||||
|
||||
AWS_REGIONS = ['ap-northeast-1',
|
||||
'ap-southeast-1',
|
||||
'ap-southeast-2',
|
||||
'eu-west-1',
|
||||
'sa-east-1',
|
||||
'us-east-1',
|
||||
'us-west-1',
|
||||
'us-west-2']
|
||||
|
||||
try:
|
||||
import boto.ec2
|
||||
except ImportError:
|
||||
@@ -235,9 +247,9 @@ def deregister_image(module, ec2):
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
ec2_url = dict(aliases=['EC2_URL']),
|
||||
ec2_secret_key = dict(aliases=['EC2_SECRET_KEY'], no_log=True),
|
||||
ec2_access_key = dict(aliases=['EC2_ACCESS_KEY']),
|
||||
ec2_url = dict(),
|
||||
aws_secret_key = dict(aliases=['ec2_secret_key', 'secret_key'], no_log=True),
|
||||
aws_access_key = dict(aliases=['ec2_access_key', 'access_key']),
|
||||
instance_id = dict(),
|
||||
image_id = dict(),
|
||||
delete_snapshot = dict(),
|
||||
@@ -247,38 +259,51 @@ def main():
|
||||
description = dict(default=""),
|
||||
no_reboot = dict(default=True, type="bool"),
|
||||
state = dict(default='present'),
|
||||
region = dict()
|
||||
region = dict(aliases=['aws_region', 'ec2_region'], choices=AWS_REGIONS)
|
||||
)
|
||||
)
|
||||
|
||||
ec2_url = module.params.get('ec2_url')
|
||||
ec2_secret_key = module.params.get('ec2_secret_key')
|
||||
ec2_access_key = module.params.get('ec2_access_key')
|
||||
aws_secret_key = module.params.get('aws_secret_key')
|
||||
aws_access_key = module.params.get('aws_access_key')
|
||||
region = module.params.get('region')
|
||||
|
||||
# allow eucarc environment variables to be used if ansible vars aren't set
|
||||
if not ec2_url and 'EC2_URL' in os.environ:
|
||||
ec2_url = os.environ['EC2_URL']
|
||||
if not ec2_secret_key and 'EC2_SECRET_KEY' in os.environ:
|
||||
ec2_secret_key = os.environ['EC2_SECRET_KEY']
|
||||
if not ec2_access_key and 'EC2_ACCESS_KEY' in os.environ:
|
||||
ec2_access_key = os.environ['EC2_ACCESS_KEY']
|
||||
|
||||
if not aws_secret_key:
|
||||
if 'AWS_SECRET_KEY' in os.environ:
|
||||
aws_secret_key = os.environ['AWS_SECRET_KEY']
|
||||
elif 'EC2_SECRET_KEY' in os.environ:
|
||||
aws_secret_key = os.environ['EC2_SECRET_KEY']
|
||||
|
||||
if not aws_access_key:
|
||||
if 'AWS_ACCESS_KEY' in os.environ:
|
||||
aws_access_key = os.environ['AWS_ACCESS_KEY']
|
||||
elif 'EC2_ACCESS_KEY' in os.environ:
|
||||
aws_access_key = os.environ['EC2_ACCESS_KEY']
|
||||
|
||||
if not region:
|
||||
if 'AWS_REGION' in os.environ:
|
||||
region = os.environ['AWS_REGION']
|
||||
elif 'EC2_REGION' in os.environ:
|
||||
region = os.environ['EC2_REGION']
|
||||
|
||||
# If we have a region specified, connect to its endpoint.
|
||||
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(" %s %s %s " % (region, ec2_access_key, ec2_secret_key)))
|
||||
# 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)
|
||||
ec2 = boto.ec2.connect_to_region(region, aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
module.fail_json(msg = str(e))
|
||||
# If we specified an ec2_url then try connecting to it
|
||||
elif ec2_url:
|
||||
try:
|
||||
ec2 = boto.connect_ec2_endpoint(ec2_url, aws_access_key, aws_secret_key)
|
||||
except boto.exception.NoAuthHandlerFound, e:
|
||||
module.fail_json(msg = str(e))
|
||||
else:
|
||||
module.fail_json(msg="Either region or ec2_url must be specified")
|
||||
|
||||
if module.params.get('state') == 'absent':
|
||||
if not module.params.get('image_id'):
|
||||
|
||||
Reference in New Issue
Block a user