mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Refactor ec2_elb_lb to use shared module snippet code
This commit is contained in:
parent
512c02b7d2
commit
17f0c9e477
1 changed files with 12 additions and 40 deletions
|
@ -21,7 +21,7 @@ description: Creates or destroys Amazon ELB.
|
||||||
short_description: Creates or destroys Amazon ELB.
|
short_description: Creates or destroys Amazon ELB.
|
||||||
- Returns information about the load balancer.
|
- Returns information about the load balancer.
|
||||||
- Will be marked changed when called only if state is changed.
|
- Will be marked changed when called only if state is changed.
|
||||||
version_added: "1.4"
|
version_added: "1.5"
|
||||||
requirements: [ "boto" ]
|
requirements: [ "boto" ]
|
||||||
author: Jim Dalton
|
author: Jim Dalton
|
||||||
options:
|
options:
|
||||||
|
@ -161,15 +161,6 @@ EXAMPLES = """
|
||||||
import sys
|
import sys
|
||||||
import os
|
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:
|
try:
|
||||||
import boto
|
import boto
|
||||||
import boto.ec2.elb
|
import boto.ec2.elb
|
||||||
|
@ -459,20 +450,21 @@ def main():
|
||||||
purge_zones={'default': False, 'required': False,
|
purge_zones={'default': False, 'required': False,
|
||||||
'choices': BOOLEANS, 'type': 'bool'},
|
'choices': BOOLEANS, 'type': 'bool'},
|
||||||
health_check={'default': None, 'required': False, 'type': 'dict'},
|
health_check={'default': None, 'required': False, 'type': 'dict'},
|
||||||
aws_secret_key={'default': None,
|
ec2_secret_key={'default': None,
|
||||||
'aliases': ['ec2_secret_key', 'secret_key'],
|
'aliases': ['aws_secret_key', 'secret_key'],
|
||||||
'no_log': True},
|
'no_log': True},
|
||||||
aws_access_key={'default': None,
|
ec2_access_key={'default': None,
|
||||||
'aliases': ['ec2_access_key', 'access_key']},
|
'aliases': ['aws_access_key', 'access_key']},
|
||||||
region={'default': None, 'required': False,
|
region={'default': None, 'required': False,
|
||||||
'aliases': ['aws_region', 'ec2_region'],
|
'aliases': ['aws_region', 'ec2_region'],
|
||||||
'choices': AWS_REGIONS},
|
'choices': AWS_REGIONS},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
aws_secret_key = module.params['aws_secret_key']
|
# def get_ec2_creds(module):
|
||||||
aws_access_key = module.params['aws_access_key']
|
# return ec2_url, ec2_access_key, ec2_secret_key, region
|
||||||
region = module.params['region']
|
ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module)
|
||||||
|
|
||||||
name = module.params['name']
|
name = module.params['name']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
listeners = module.params['listeners']
|
listeners = module.params['listeners']
|
||||||
|
@ -487,27 +479,6 @@ def main():
|
||||||
if state == 'present' and not zones:
|
if state == 'present' and not zones:
|
||||||
module.fail_json(msg="At least one availability zone is required for ELB creation")
|
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,
|
elb_man = ElbManager(module, name, listeners, purge_listeners, zones,
|
||||||
purge_zones, health_check, aws_access_key,
|
purge_zones, health_check, aws_access_key,
|
||||||
aws_secret_key, region=region)
|
aws_secret_key, region=region)
|
||||||
|
@ -524,7 +495,8 @@ def main():
|
||||||
|
|
||||||
module.exit_json(**ec2_facts_result)
|
module.exit_json(**ec2_facts_result)
|
||||||
|
|
||||||
# this is magic, see lib/ansible/module_common.py
|
# import module snippets
|
||||||
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
from ansible.module_utils.basic import *
|
||||||
|
from ansible.module_utils.ec2 import *
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue