From 17f0c9e4775a5b899189ab36df3449222563e9f6 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Fri, 24 Jan 2014 15:33:41 -0500 Subject: [PATCH] Refactor ec2_elb_lb to use shared module snippet code --- library/cloud/ec2_elb_lb | 52 ++++++++++------------------------------ 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/library/cloud/ec2_elb_lb b/library/cloud/ec2_elb_lb index d7c55cd3eb..5e4db144c8 100644 --- a/library/cloud/ec2_elb_lb +++ b/library/cloud/ec2_elb_lb @@ -21,7 +21,7 @@ description: Creates or destroys Amazon ELB. short_description: Creates or destroys Amazon ELB. - Returns information about the load balancer. - Will be marked changed when called only if state is changed. -version_added: "1.4" +version_added: "1.5" requirements: [ "boto" ] author: Jim Dalton options: @@ -161,15 +161,6 @@ EXAMPLES = """ import sys import os -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 import boto.ec2.elb @@ -459,20 +450,21 @@ def main(): purge_zones={'default': False, 'required': False, 'choices': BOOLEANS, 'type': 'bool'}, health_check={'default': None, 'required': False, 'type': 'dict'}, - aws_secret_key={'default': None, - 'aliases': ['ec2_secret_key', 'secret_key'], + ec2_secret_key={'default': None, + 'aliases': ['aws_secret_key', 'secret_key'], 'no_log': True}, - aws_access_key={'default': None, - 'aliases': ['ec2_access_key', 'access_key']}, + ec2_access_key={'default': None, + 'aliases': ['aws_access_key', 'access_key']}, region={'default': None, 'required': False, 'aliases': ['aws_region', 'ec2_region'], 'choices': AWS_REGIONS}, ) ) - aws_secret_key = module.params['aws_secret_key'] - aws_access_key = module.params['aws_access_key'] - region = module.params['region'] + # def get_ec2_creds(module): + # return ec2_url, ec2_access_key, ec2_secret_key, region + ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module) + name = module.params['name'] state = module.params['state'] listeners = module.params['listeners'] @@ -487,27 +479,6 @@ def main(): if state == 'present' and not zones: module.fail_json(msg="At least one availability zone is required for ELB creation") - 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 not region: - module.fail_json(msg=str("Either region or EC2_REGION environment variable must be set.")) - elb_man = ElbManager(module, name, listeners, purge_listeners, zones, purge_zones, health_check, aws_access_key, aws_secret_key, region=region) @@ -524,7 +495,8 @@ def main(): module.exit_json(**ec2_facts_result) -# this is magic, see lib/ansible/module_common.py -#<> +# import module snippets +from ansible.module_utils.basic import * +from ansible.module_utils.ec2 import * main()