diff --git a/lib/ansible/module_utils/ec2.py b/lib/ansible/module_utils/ec2.py index 66191e2a509..d6e047c5997 100644 --- a/lib/ansible/module_utils/ec2.py +++ b/lib/ansible/module_utils/ec2.py @@ -14,14 +14,23 @@ AWS_REGIONS = ['ap-northeast-1', 'us-west-2'] -def ec2_argument_spec(): +def ec2_argument_keys_spec(): return dict( - region=dict(aliases=['aws_region', 'ec2_region'], choices=AWS_REGIONS), - ec2_url=dict(), - ec2_secret_key=dict(aliases=['aws_secret_key', 'secret_key'], no_log=True), - ec2_access_key=dict(aliases=['aws_access_key', 'access_key']), - validate_certs=dict(default=True, type='bool'), + aws_secret_key=dict(aliases=['ec2_secret_key', 'secret_key'], no_log=True), + aws_access_key=dict(aliases=['ec2_access_key', 'access_key']), + ) + + +def ec2_argument_spec(): + spec = ec2_argument_keys_spec() + spec.update( + dict( + region=dict(aliases=['aws_region', 'ec2_region'], choices=AWS_REGIONS), + validate_certs=dict(default=True, type='bool'), + ec2_url=dict(), + ) ) + return spec def get_ec2_creds(module): @@ -29,8 +38,8 @@ def get_ec2_creds(module): # Check module args for credentials, then check environment vars 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') + ec2_secret_key = module.params.get('aws_secret_key') + ec2_access_key = module.params.get('aws_access_key') region = module.params.get('region') if not ec2_url: diff --git a/library/cloud/ec2 b/library/cloud/ec2 index ab4a58a2997..864ce5c64e1 100644 --- a/library/cloud/ec2 +++ b/library/cloud/ec2 @@ -1053,6 +1053,7 @@ def main(): ec2 = ec2_connect(module) tagged_instances = [] + if module.params.get('state') == 'absent': instance_ids = module.params.get('instance_ids') if not isinstance(instance_ids, list): diff --git a/library/cloud/ec2_elb b/library/cloud/ec2_elb index c6f4a72b0e1..ebd90aeda82 100644 --- a/library/cloud/ec2_elb +++ b/library/cloud/ec2_elb @@ -292,21 +292,21 @@ class ElbManager: def main(): - - module = AnsibleModule( - argument_spec=dict( + argument_spec = ec2_argument_spec() + argument_spec.update(dict( state={'required': True, 'choices': ['present', 'absent']}, instance_id={'required': True}, ec2_elbs={'default': None, 'required': False, 'type':'list'}, - ec2_secret_key={'default': None, 'aliases': ['aws_secret_key', 'secret_key'], 'no_log': True}, - ec2_access_key={'default': None, 'aliases': ['aws_access_key', 'access_key']}, - region={'default': None, 'required': False, 'aliases':['aws_region', 'ec2_region'], 'choices':AWS_REGIONS}, enable_availability_zone={'default': True, 'required': False, 'choices': BOOLEANS, 'type': 'bool'}, wait={'required': False, 'choices': BOOLEANS, 'default': True, 'type': 'bool'} ) ) + module = AnsibleModule( + argument_spec=argument_spec, + ) + # 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) diff --git a/library/cloud/ec2_elb_lb b/library/cloud/ec2_elb_lb index f7d23631bc0..cc2c1454876 100644 --- a/library/cloud/ec2_elb_lb +++ b/library/cloud/ec2_elb_lb @@ -447,8 +447,8 @@ class ElbManager(object): def main(): - module = AnsibleModule( - argument_spec=dict( + argument_spec = ec2_argument_spec() + argument_spec.update(dict( state={'required': True, 'choices': ['present', 'absent']}, name={'required': True}, listeners={'default': None, 'required': False, 'type': 'list'}, @@ -458,17 +458,13 @@ def main(): purge_zones={'default': False, 'required': False, 'choices': BOOLEANS, 'type': 'bool'}, health_check={'default': None, 'required': False, 'type': 'dict'}, - ec2_secret_key={'default': None, - 'aliases': ['aws_secret_key', 'secret_key'], - 'no_log': True}, - ec2_access_key={'default': None, - 'aliases': ['aws_access_key', 'access_key']}, - region={'default': None, 'required': False, - 'aliases': ['aws_region', 'ec2_region'], - 'choices': AWS_REGIONS}, ) ) + module = AnsibleModule( + argument_spec=argument_spec, + ) + # 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) diff --git a/library/cloud/ec2_vpc b/library/cloud/ec2_vpc index 7671e6314fa..c44501b5b96 100644 --- a/library/cloud/ec2_vpc +++ b/library/cloud/ec2_vpc @@ -480,8 +480,8 @@ def terminate_vpc(module, vpc_conn, vpc_id=None, cidr=None): def main(): - module = AnsibleModule( - argument_spec = dict( + argument_spec = ec2_argument_spec() + argument_spec.update(dict( cidr_block = dict(), wait = dict(choices=BOOLEANS, default=False), wait_timeout = dict(default=300), @@ -491,13 +491,14 @@ def main(): vpc_id = dict(), internet_gateway = dict(choices=BOOLEANS, default=False), route_tables = dict(type='list'), - region = dict(aliases=['aws_region', 'ec2_region'], choices=AWS_REGIONS), state = dict(choices=['present', 'absent'], default='present'), - ec2_secret_key = dict(aliases=['aws_secret_key', 'secret_key'], no_log=True), - ec2_access_key = dict(aliases=['aws_access_key', 'access_key']), ) ) + module = AnsibleModule( + argument_spec=argument_spec, + ) + state = module.params.get('state') ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module) diff --git a/library/cloud/elasticache b/library/cloud/elasticache index a54deafc25d..7cbd72d736d 100644 --- a/library/cloud/elasticache +++ b/library/cloud/elasticache @@ -458,8 +458,8 @@ class ElastiCacheManager(object): def main(): - module = AnsibleModule( - argument_spec=dict( + argument_spec = ec2_argument_spec() + argument_spec.update(dict( state={'required': True, 'choices': ['present', 'absent', 'rebooted']}, name={'required': True}, engine={'required': False, 'default': 'memcached'}, @@ -470,19 +470,15 @@ def main(): cache_security_groups={'required': False, 'default': ['default'], 'type': 'list'}, zone={'required': False, 'default': None}, - ec2_secret_key={'default': None, - 'aliases': ['aws_secret_key', 'secret_key'], - 'no_log': True}, - ec2_access_key={'default': None, - 'aliases': ['aws_access_key', 'access_key']}, - region={'default': None, 'required': False, - 'aliases': ['aws_region', 'ec2_region'], - 'choices': AWS_REGIONS}, wait={'required': False, 'choices': BOOLEANS, 'default': True}, hard_modify={'required': False, 'choices': BOOLEANS, 'default': False} ) ) + module = AnsibleModule( + argument_spec=argument_spec, + ) + ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module) name = module.params['name'] diff --git a/library/cloud/rds b/library/cloud/rds index 2b83900e48f..d0eeaf35ba5 100644 --- a/library/cloud/rds +++ b/library/cloud/rds @@ -283,8 +283,8 @@ def get_current_resource(conn, resource, command): def main(): - module = AnsibleModule( - argument_spec = dict( + argument_spec = ec2_argument_spec() + argument_spec.update(dict( command = dict(choices=['create', 'replicate', 'delete', 'facts', 'modify', 'promote', 'snapshot', 'restore'], required=True), instance_name = dict(required=True), source_instance = dict(required=False), @@ -307,11 +307,8 @@ def main(): maint_window = dict(required=False), backup_window = dict(required=False), backup_retention = dict(required=False), - region = dict(aliases=['aws_region', 'ec2_region'], choices=AWS_REGIONS, required=False), zone = dict(aliases=['aws_zone', 'ec2_zone'], required=False), subnet = dict(required=False), - aws_secret_key = dict(aliases=['ec2_secret_key', 'secret_key'], no_log=True, required=False), - aws_access_key = dict(aliases=['ec2_access_key', 'access_key'], required=False), wait = dict(type='bool', default=False), wait_timeout = dict(default=300), snapshot = dict(required=False), @@ -320,6 +317,10 @@ def main(): ) ) + module = AnsibleModule( + argument_spec=argument_spec, + ) + command = module.params.get('command') instance_name = module.params.get('instance_name') source_instance = module.params.get('source_instance') diff --git a/library/cloud/route53 b/library/cloud/route53 index 115ef870c58..2ff22ded9dc 100644 --- a/library/cloud/route53 +++ b/library/cloud/route53 @@ -157,19 +157,18 @@ def commit(changes): time.sleep(500) def main(): - module = AnsibleModule( - argument_spec = dict( + argument_spec = ec2_argument_keys_spec() + argument_spec.update(dict( command = dict(choices=['get', 'create', 'delete'], required=True), zone = dict(required=True), record = dict(required=True), ttl = dict(required=False, default=3600), type = dict(choices=['A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'NS'], required=True), value = dict(required=False), - ec2_secret_key = dict(aliases=['aws_secret_key', 'secret_key'], no_log=True, required=False), - ec2_access_key = dict(aliases=['aws_access_key', 'access_key'], required=False), overwrite = dict(required=False, type='bool') ) ) + module = AnsibleModule(argument_spec=argument_spec) command_in = module.params.get('command') zone_in = module.params.get('zone') diff --git a/library/cloud/s3 b/library/cloud/s3 index 5d2c97baf39..6e566e4b8dc 100644 --- a/library/cloud/s3 +++ b/library/cloud/s3 @@ -249,8 +249,8 @@ def is_walrus(s3_url): return False def main(): - module = AnsibleModule( - argument_spec = dict( + argument_spec = ec2_argument_keys_spec() + argument_spec.update(dict( bucket = dict(required=True), object = dict(), src = dict(), @@ -258,11 +258,10 @@ def main(): mode = dict(choices=['get', 'put', 'delete', 'create', 'geturl', 'getstr'], required=True), expiry = dict(default=600, aliases=['expiration']), s3_url = dict(aliases=['S3_URL']), - ec2_secret_key = dict(aliases=['aws_secret_key', 'secret_key'], no_log=True), - ec2_access_key = dict(aliases=['aws_access_key', 'access_key']), overwrite = dict(aliases=['force'], default=True, type='bool'), - ), + ) ) + module = AnsibleModule(argument_spec=argument_spec) bucket = module.params.get('bucket') obj = module.params.get('object')