1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add support for AWS Security Token Service (temporary credentials) to all AWS cloud modules.

This commit is contained in:
Mick Bass 2014-12-24 17:04:25 -07:00 committed by Matt Clay
parent e710e46ff2
commit 9980205edc
7 changed files with 59 additions and 141 deletions

View file

@ -41,12 +41,6 @@ options:
required: false required: false
default: {} default: {}
aliases: [] aliases: []
region:
description:
- The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used.
required: true
default: null
aliases: ['aws_region', 'ec2_region']
state: state:
description: description:
- If state is "present", stack will be created. If state is "present" and if stack exists and template has changed, it will be updated. - If state is "present", stack will be created. If state is "present" and if stack exists and template has changed, it will be updated.
@ -75,29 +69,17 @@ options:
default: null default: null
aliases: [] aliases: []
version_added: "1.4" version_added: "1.4"
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_secret_key', 'secret_key' ]
version_added: "1.5"
aws_access_key:
description:
- AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_access_key', 'access_key' ]
version_added: "1.5"
region: region:
description: description:
- The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used. - The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used.
required: false required: true
default: null
aliases: ['aws_region', 'ec2_region'] aliases: ['aws_region', 'ec2_region']
version_added: "1.5" version_added: "1.5"
requirements: [ "boto" ] requirements: [ "boto" ]
author: James S. Martin author: James S. Martin
extends_documentation_fragment: aws
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -233,7 +215,7 @@ def main():
template_parameters = module.params['template_parameters'] template_parameters = module.params['template_parameters']
tags = module.params['tags'] tags = module.params['tags']
ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module) region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
kwargs = dict() kwargs = dict()
if tags is not None: if tags is not None:
@ -249,8 +231,7 @@ def main():
try: try:
cfn = boto.cloudformation.connect_to_region( cfn = boto.cloudformation.connect_to_region(
region, region,
aws_access_key_id=aws_access_key, **aws_connect_kwargs
aws_secret_access_key=aws_secret_key,
) )
except boto.exception.NoAuthHandlerFound, e: except boto.exception.NoAuthHandlerFound, e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))

View file

@ -96,33 +96,13 @@ options:
aliases: [] aliases: []
region: region:
description: description:
- region in which the resource exists. - The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used.
required: false required: true
default: null default: null
aliases: ['aws_region', 'ec2_region'] aliases: ['aws_region', 'ec2_region']
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
required: false
default: None
aliases: ['ec2_secret_key', 'secret_key' ]
aws_access_key:
description:
- AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
required: false
default: None
aliases: ['ec2_access_key', 'access_key' ]
validate_certs:
description:
- When set to "no", SSL certificates will not be validated for boto versions >= 2.6.0.
required: false
default: "yes"
choices: ["yes", "no"]
aliases: []
version_added: "1.5"
requirements: [ "boto" ] requirements: [ "boto" ]
author: Carson Gee author: Carson Gee
extends_documentation_fragment: aws
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -599,7 +579,19 @@ def main():
state = module.params.get('state') state = module.params.get('state')
vpc_conn = ec2_connect(module) region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
# If we have a region specified, connect to its endpoint.
if region:
try:
vpc_conn = boto.vpc.connect_to_region(
region,
**aws_connect_kwargs
)
except boto.exception.NoAuthHandlerFound, e:
module.fail_json(msg = str(e))
else:
module.fail_json(msg="region must be specified")
if module.params.get('state') == 'absent': if module.params.get('state') == 'absent':
vpc_id = module.params.get('vpc_id') vpc_id = module.params.get('vpc_id')

View file

@ -92,24 +92,13 @@ options:
required: false required: false
default: no default: no
choices: [ "yes", "no" ] choices: [ "yes", "no" ]
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
required: false
default: None
aliases: ['ec2_secret_key', 'secret_key']
aws_access_key:
description:
- AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
required: false
default: None
aliases: ['ec2_access_key', 'access_key']
region: region:
description: description:
- The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used. - The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used.
required: false required: true
default: null
aliases: ['aws_region', 'ec2_region'] aliases: ['aws_region', 'ec2_region']
extends_documentation_fragment: aws
""" """
EXAMPLES = """ EXAMPLES = """
@ -163,7 +152,7 @@ class ElastiCacheManager(object):
def __init__(self, module, name, engine, cache_engine_version, node_type, def __init__(self, module, name, engine, cache_engine_version, node_type,
num_nodes, cache_port, cache_subnet_group, num_nodes, cache_port, cache_subnet_group,
cache_security_groups, security_group_ids, zone, wait, cache_security_groups, security_group_ids, zone, wait,
hard_modify, aws_access_key, aws_secret_key, region): hard_modify, region, **aws_connect_kwargs):
self.module = module self.module = module
self.name = name self.name = name
self.engine = engine self.engine = engine
@ -178,9 +167,8 @@ class ElastiCacheManager(object):
self.wait = wait self.wait = wait
self.hard_modify = hard_modify self.hard_modify = hard_modify
self.aws_access_key = aws_access_key
self.aws_secret_key = aws_secret_key
self.region = region self.region = region
self.aws_connect_kwargs = aws_connect_kwargs
self.changed = False self.changed = False
self.data = None self.data = None
@ -433,9 +421,10 @@ class ElastiCacheManager(object):
try: try:
endpoint = "elasticache.%s.amazonaws.com" % self.region endpoint = "elasticache.%s.amazonaws.com" % self.region
connect_region = RegionInfo(name=self.region, endpoint=endpoint) connect_region = RegionInfo(name=self.region, endpoint=endpoint)
return ElastiCacheConnection(aws_access_key_id=self.aws_access_key, return ElastiCacheConnection(
aws_secret_access_key=self.aws_secret_key, region=connect_region,
region=connect_region) **self.aws_connect_kwargs
)
except boto.exception.NoAuthHandlerFound, e: except boto.exception.NoAuthHandlerFound, e:
self.module.fail_json(msg=e.message) self.module.fail_json(msg=e.message)
@ -509,7 +498,7 @@ def main():
argument_spec=argument_spec, argument_spec=argument_spec,
) )
ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module) region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
name = module.params['name'] name = module.params['name']
state = module.params['state'] state = module.params['state']
@ -537,7 +526,7 @@ def main():
module.fail_json(msg="'num_nodes' is a required parameter. Please specify num_nodes > 0") module.fail_json(msg="'num_nodes' is a required parameter. Please specify num_nodes > 0")
if not region: if not region:
module.fail_json(msg=str("Either region or EC2_REGION environment variable must be set.")) module.fail_json(msg=str("Either region or AWS_REGION or EC2_REGION environment variable or boto config aws_region or ec2_region must be set."))
elasticache_manager = ElastiCacheManager(module, name, engine, elasticache_manager = ElastiCacheManager(module, name, engine,
cache_engine_version, node_type, cache_engine_version, node_type,
@ -545,8 +534,7 @@ def main():
cache_subnet_group, cache_subnet_group,
cache_security_groups, cache_security_groups,
security_group_ids, zone, wait, security_group_ids, zone, wait,
hard_modify, aws_access_key, hard_modify, region, **aws_connect_kwargs)
aws_secret_key, region)
if state == 'present': if state == 'present':
elasticache_manager.ensure_present() elasticache_manager.ensure_present()

View file

@ -63,24 +63,13 @@ options:
choices: [ 'mysql5.1', 'mysql5.5', 'mysql5.6', 'oracle-ee-11.2', 'oracle-se-11.2', 'oracle-se1-11.2', 'postgres9.3', 'sqlserver-ee-10.5', 'sqlserver-ee-11.0', 'sqlserver-ex-10.5', 'sqlserver-ex-11.0', 'sqlserver-se-10.5', 'sqlserver-se-11.0', 'sqlserver-web-10.5', 'sqlserver-web-11.0'] choices: [ 'mysql5.1', 'mysql5.5', 'mysql5.6', 'oracle-ee-11.2', 'oracle-se-11.2', 'oracle-se1-11.2', 'postgres9.3', 'sqlserver-ee-10.5', 'sqlserver-ee-11.0', 'sqlserver-ex-10.5', 'sqlserver-ex-11.0', 'sqlserver-se-10.5', 'sqlserver-se-11.0', 'sqlserver-web-10.5', 'sqlserver-web-11.0']
region: region:
description: description:
- The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used. - The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used.
required: true required: true
default: null default: null
aliases: [ 'aws_region', 'ec2_region' ] aliases: ['aws_region', 'ec2_region']
aws_access_key:
description:
- AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_access_key', 'access_key' ]
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_secret_key', 'secret_key' ]
requirements: [ "boto" ] requirements: [ "boto" ]
author: Scott Anderson author: Scott Anderson
extends_documentation_fragment: aws
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -248,13 +237,13 @@ def main():
module.fail_json(msg = str("Parameter %s not allowed for state='absent'" % not_allowed)) module.fail_json(msg = str("Parameter %s not allowed for state='absent'" % not_allowed))
# Retrieve any AWS settings from the environment. # Retrieve any AWS settings from the environment.
ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module) region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
if not region: if not region:
module.fail_json(msg = str("region not specified and unable to determine region from EC2_REGION.")) module.fail_json(msg = str("Either region or AWS_REGION or EC2_REGION environment variable or boto config aws_region or ec2_region must be set."))
try: try:
conn = boto.rds.connect_to_region(region, aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key) conn = boto.rds.connect_to_region(region, **aws_connect_kwargs)
except boto.exception.BotoServerError, e: except boto.exception.BotoServerError, e:
module.fail_json(msg = e.error_message) module.fail_json(msg = e.error_message)

View file

@ -49,24 +49,13 @@ options:
aliases: [] aliases: []
region: region:
description: description:
- The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used. - The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used.
required: true required: true
default: null default: null
aliases: [ 'aws_region', 'ec2_region' ] aliases: ['aws_region', 'ec2_region']
aws_access_key:
description:
- AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_access_key', 'access_key' ]
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_secret_key', 'secret_key' ]
requirements: [ "boto" ] requirements: [ "boto" ]
author: Scott Anderson author: Scott Anderson
extends_documentation_fragment: aws
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -121,13 +110,13 @@ def main():
module.fail_json(msg = str("Parameter %s not allowed for state='absent'" % not_allowed)) module.fail_json(msg = str("Parameter %s not allowed for state='absent'" % not_allowed))
# Retrieve any AWS settings from the environment. # Retrieve any AWS settings from the environment.
region, ec2_url, aws_connect_params = get_aws_connection_info(module) region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
if not region: if not region:
module.fail_json(msg = str("region not specified and unable to determine region from EC2_REGION.")) module.fail_json(msg = str("Either region or AWS_REGION or EC2_REGION environment variable or boto config aws_region or ec2_region must be set."))
try: try:
conn = boto.rds.connect_to_region(region, **aws_connect_params) conn = boto.rds.connect_to_region(region, **aws_connection_kwargs)
except boto.exception.BotoServerError, e: except boto.exception.BotoServerError, e:
module.fail_json(msg = e.error_message) module.fail_json(msg = e.error_message)

View file

@ -74,18 +74,6 @@ options:
required: false required: false
default: null default: null
aliases: [] aliases: []
aws_secret_key:
description:
- AWS secret key.
required: false
default: null
aliases: ['ec2_secret_key', 'secret_key']
aws_access_key:
description:
- AWS access key.
required: false
default: null
aliases: ['ec2_access_key', 'access_key']
overwrite: overwrite:
description: description:
- Whether an existing record should be overwritten on create if values do not match - Whether an existing record should be overwritten on create if values do not match
@ -106,6 +94,7 @@ options:
version_added: "1.9" version_added: "1.9"
requirements: [ "boto" ] requirements: [ "boto" ]
author: Bruce Pennypacker author: Bruce Pennypacker
extends_documentation_fragment: aws
''' '''
# FIXME: the command stuff should have a more state like configuration alias -- MPD # FIXME: the command stuff should have a more state like configuration alias -- MPD
@ -176,6 +165,7 @@ import time
try: try:
import boto import boto
from boto import route53 from boto import route53
from boto.route53 import Route53Connection
from boto.route53.record import ResourceRecordSets from boto.route53.record import ResourceRecordSets
except ImportError: except ImportError:
print "failed=True msg='boto required for this module'" print "failed=True msg='boto required for this module'"
@ -223,7 +213,7 @@ def main():
retry_interval_in = module.params.get('retry_interval') retry_interval_in = module.params.get('retry_interval')
private_zone_in = module.params.get('private_zone') private_zone_in = module.params.get('private_zone')
ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module) region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
value_list = () value_list = ()
@ -250,7 +240,7 @@ def main():
# connect to the route53 endpoint # connect to the route53 endpoint
try: try:
conn = boto.route53.connection.Route53Connection(aws_access_key, aws_secret_key) conn = Route53Connection(**aws_connect_kwargs)
except boto.exception.BotoServerError, e: except boto.exception.BotoServerError, e:
module.fail_json(msg = e.error_message) module.fail_json(msg = e.error_message)

View file

@ -71,18 +71,6 @@ options:
- "S3 URL endpoint for usage with Eucalypus, fakes3, etc. Otherwise assumes AWS" - "S3 URL endpoint for usage with Eucalypus, fakes3, etc. Otherwise assumes AWS"
default: null default: null
aliases: [ S3_URL ] aliases: [ S3_URL ]
aws_secret_key:
description:
- AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
required: false
default: null
aliases: ['ec2_secret_key', 'secret_key']
aws_access_key:
description:
- AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
required: false
default: null
aliases: [ 'ec2_access_key', 'access_key' ]
metadata: metadata:
description: description:
- Metadata for PUT operation, as a dictionary of 'key=value' and 'key=value,key=value'. - Metadata for PUT operation, as a dictionary of 'key=value' and 'key=value,key=value'.
@ -91,13 +79,13 @@ options:
version_added: "1.6" version_added: "1.6"
region: region:
description: description:
- "AWS region to create the bucket in. If not set then the value of the EC2_REGION and AWS_REGION environment variables are checked, followed by the aws_region and ec2_region settings in the Boto config file. If none of those are set the region defaults to the S3 Location: US Standard. Prior to ansible 1.8 this parameter could be specified but had no effect." - "AWS region to create the bucket in. If not set then the value of the AWS_REGION and EC2_REGION environment variables are checked, followed by the aws_region and ec2_region settings in the Boto config file. If none of those are set the region defaults to the S3 Location: US Standard. Prior to ansible 1.8 this parameter could be specified but had no effect."
required: false required: false
default: null default: null
version_added: "1.8" version_added: "1.8"
requirements: [ "boto" ] requirements: [ "boto" ]
author: Lester Wade, Ralph Tice author: Lester Wade, Ralph Tice
extends_documentation_fragment: aws
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -130,6 +118,7 @@ from boto.s3.connection import OrdinaryCallingFormat
try: try:
import boto import boto
from boto.s3.connection import Location from boto.s3.connection import Location
from boto.s3.connection import S3Connection
except ImportError: except ImportError:
print "failed=True msg='boto required for this module'" print "failed=True msg='boto required for this module'"
sys.exit(1) sys.exit(1)
@ -301,7 +290,7 @@ def main():
overwrite = module.params.get('overwrite') overwrite = module.params.get('overwrite')
metadata = module.params.get('metadata') metadata = module.params.get('metadata')
ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module) region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module)
if region in ('us-east-1', '', None): if region in ('us-east-1', '', None):
# S3ism for the US Standard region # S3ism for the US Standard region
@ -323,13 +312,13 @@ def main():
try: try:
if is_fakes3(s3_url): if is_fakes3(s3_url):
fakes3 = urlparse.urlparse(s3_url) fakes3 = urlparse.urlparse(s3_url)
s3 = boto.connect_s3( s3 = S3Connection(
aws_access_key,
aws_secret_key,
is_secure=False, is_secure=False,
host=fakes3.hostname, host=fakes3.hostname,
port=fakes3.port, port=fakes3.port,
calling_format=OrdinaryCallingFormat()) calling_format=OrdinaryCallingFormat(),
**aws_connect_kwargs
)
elif is_walrus(s3_url): elif is_walrus(s3_url):
walrus = urlparse.urlparse(s3_url).hostname walrus = urlparse.urlparse(s3_url).hostname
s3 = boto.connect_walrus(walrus, aws_access_key, aws_secret_key) s3 = boto.connect_walrus(walrus, aws_access_key, aws_secret_key)