def main(): argument_spec = dict(name=dict(required=True), description=dict(), source=dict(required=True, type='dict'), artifacts=dict(required=True, type='dict'), cache=dict(type='dict'), environment=dict(type='dict'), service_role=dict(), timeout_in_minutes=dict(type='int', default=60), encryption_key=dict(), tags=dict(type='list'), vpc_config=dict(type='dict'), state=dict(choices=['present', 'absent'], default='present')) module = AnsibleAWSModule(argument_spec=argument_spec) client_conn = module.client('codebuild') state = module.params.get('state') changed = False if state == 'present': project_result, changed = create_or_update_project( client=client_conn, params=module.params, module=module) elif state == 'absent': project_result, changed = delete_project(client=client_conn, name=module.params['name'], module=module) module.exit_json(changed=changed, **camel_dict_to_snake_dict(project_result))
def main(): argument_spec = dict(caller_reference=dict(), distribution_id=dict(), alias=dict(), target_paths=dict(required=True, type='list')) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=False, mutually_exclusive=[['distribution_id', 'alias']]) validation_mgr = CloudFrontInvalidationValidationManager(module) service_mgr = CloudFrontInvalidationServiceManager(module) caller_reference = module.params.get('caller_reference') distribution_id = module.params.get('distribution_id') alias = module.params.get('alias') target_paths = module.params.get('target_paths') result = {} distribution_id = validation_mgr.validate_distribution_id( distribution_id, alias) valid_target_paths = validation_mgr.validate_invalidation_batch( target_paths, caller_reference) valid_pascal_target_paths = snake_dict_to_camel_dict( valid_target_paths, True) result, changed = service_mgr.create_invalidation( distribution_id, valid_pascal_target_paths) module.exit_json(changed=changed, **camel_dict_to_snake_dict(result))
def main(): """ Module action handler """ argument_spec = ec2_argument_spec() argument_spec.update( dict( name=dict(aliases=['role_name']), path_prefix=dict(), )) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True, mutually_exclusive=[['name', 'path_prefix']]) if module._name == 'iam_role_facts': module.deprecate( "The 'iam_role_facts' module has been renamed to 'iam_role_info'", version='2.13') region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True) client = boto3_conn(module, conn_type='client', resource='iam', region=region, endpoint=ec2_url, **aws_connect_params) module.exit_json(changed=False, iam_roles=describe_iam_roles(module, client))
def main(): argument_spec = ec2_argument_spec() argument_spec.update(dict(names={'default': [], 'type': 'list'})) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) if module._name == 'elb_classic_lb_facts': module.deprecate( "The 'elb_classic_lb_facts' module has been renamed to 'elb_classic_lb_info'", version='2.13') region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True) connection = boto3_conn(module, conn_type='client', resource='elb', region=region, endpoint=ec2_url, **aws_connect_params) try: elbs = list_elbs(connection, module.params.get('names')) except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg="Failed to get load balancer information.") module.exit_json(elbs=elbs)
def main(): argument_spec = dict(iam_type=dict(required=True, choices=['user', 'group', 'role']), state=dict(default='present', choices=['present', 'absent']), iam_name=dict(required=True), policy_name=dict(required=True), policy_document=dict(default=None, required=False), policy_json=dict(type='json', default=None, required=False), skip_duplicates=dict(type='bool', default=None, required=False)) mutually_exclusive = [['policy_document', 'policy_json']] module = AnsibleAWSModule(argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, supports_check_mode=True) skip_duplicates = module.params.get('skip_duplicates') if (skip_duplicates is None): module.deprecate( 'The skip_duplicates behaviour has caused confusion and' ' will be disabled by default in Ansible 2.14', version='2.14') skip_duplicates = True if module.params.get('policy_document'): module.deprecate( 'The policy_document option has been deprecated and' ' will be removed in Ansible 2.14', version='2.14') args = dict( client=module.client('iam'), name=module.params.get('iam_name'), policy_name=module.params.get('policy_name'), policy_document=module.params.get('policy_document'), policy_json=module.params.get('policy_json'), skip_duplicates=skip_duplicates, state=module.params.get('state'), check_mode=module.check_mode, ) iam_type = module.params.get('iam_type') try: if iam_type == 'user': policy = UserPolicy(**args) elif iam_type == 'role': policy = RolePolicy(**args) elif iam_type == 'group': policy = GroupPolicy(**args) module.exit_json(**(policy.run())) except (BotoCoreError, ClientError) as e: module.fail_json_aws(e) except PolicyError as e: module.fail_json(msg=str(e))
def main(): argument_spec = dict( name=dict(required=True), schedule_expression=dict(), event_pattern=dict(), state=dict(choices=['present', 'disabled', 'absent'], default='present'), description=dict(), role_arn=dict(), targets=dict(type='list', default=[]), ) module = AnsibleAWSModule(argument_spec=argument_spec) rule_data = dict( [(rf, module.params.get(rf)) for rf in CloudWatchEventRuleManager.RULE_FIELDS] ) targets = module.params.get('targets') state = module.params.get('state') client = module.client('events') cwe_rule = CloudWatchEventRule(module, client=client, **rule_data) cwe_rule_manager = CloudWatchEventRuleManager(cwe_rule, targets) if state == 'present': cwe_rule_manager.ensure_present() elif state == 'disabled': cwe_rule_manager.ensure_disabled() elif state == 'absent': cwe_rule_manager.ensure_absent() else: module.fail_json(msg="Invalid state '{0}' provided".format(state)) module.exit_json(**cwe_rule_manager.fetch_aws_state())
def main(): argument_spec = ec2_argument_spec() argument_spec.update(dict(task_definition=dict(required=True, type='str'))) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) if module._name == 'ecs_taskdefinition_facts': module.deprecate( "The 'ecs_taskdefinition_facts' module has been renamed to 'ecs_taskdefinition_info'", version='2.13') region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) ecs = boto3_conn(module, conn_type='client', resource='ecs', region=region, endpoint=ec2_url, **aws_connect_kwargs) try: ecs_td = ecs.describe_task_definition( taskDefinition=module.params['task_definition'])['taskDefinition'] except botocore.exceptions.ClientError: ecs_td = {} module.exit_json(changed=False, **camel_dict_to_snake_dict(ecs_td))
def main(): module = AnsibleAWSModule( argument_spec={}, supports_check_mode=True, ) if module._name == 'aws_caller_facts': module.deprecate( "The 'aws_caller_facts' module has been renamed to 'aws_caller_info'", version='2.13') client = module.client('sts') try: caller_info = client.get_caller_identity() caller_info.pop('ResponseMetadata', None) except (BotoCoreError, ClientError) as e: module.fail_json_aws(e, msg='Failed to retrieve caller identity') iam_client = module.client('iam') try: # Although a list is returned by list_account_aliases AWS supports maximum one alias per account. # If an alias is defined it will be returned otherwise a blank string is filled in as account_alias. # see https://docs.aws.amazon.com/cli/latest/reference/iam/list-account-aliases.html#output response = iam_client.list_account_aliases() if response and response['AccountAliases']: caller_info['account_alias'] = response['AccountAliases'][0] else: caller_info['account_alias'] = '' except (BotoCoreError, ClientError) as e: # The iam:ListAccountAliases permission is required for this operation to succeed. # Lacking this permission is handled gracefully by not returning the account_alias. pass module.exit_json(changed=False, **camel_dict_to_snake_dict(caller_info))
def main(): argument_spec = ec2_argument_spec() argument_spec.update( dict(vpc_id=dict(required=True), state=dict(default='present', choices=['present', 'absent']))) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True) connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params) vpc_id = module.params.get('vpc_id') state = module.params.get('state') eigw_id = describe_eigws(module, connection, vpc_id) result = dict(gateway_id=eigw_id, vpc_id=vpc_id) changed = False if state == 'present' and not eigw_id: changed, result['gateway_id'] = create_eigw(module, connection, vpc_id) elif state == 'absent' and eigw_id: changed = delete_eigw(module, connection, eigw_id) module.exit_json(changed=changed, **result)
def main(): argument_spec = dict( iam_type=dict(required=True, choices=['user', 'group', 'role']), iam_name=dict(required=True), policy_name=dict(default=None, required=False), ) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) args = dict( client=module.client('iam'), name=module.params.get('iam_name'), policy_name=module.params.get('policy_name'), ) iam_type = module.params.get('iam_type') try: if iam_type == 'user': policy = UserPolicy(**args) elif iam_type == 'role': policy = RolePolicy(**args) elif iam_type == 'group': policy = GroupPolicy(**args) module.exit_json(**(policy.run())) except (BotoCoreError, ClientError) as e: if e.response['Error']['Code'] == 'NoSuchEntity': module.exit_json(changed=False, msg=e.response['Error']['Message']) module.fail_json_aws(e) except PolicyError as e: module.fail_json(msg=str(e))
def main(): argument_spec = dict( autoscaling_group_name=dict(required=True, type='str'), lifecycle_hook_name=dict(required=True, type='str'), transition=dict(type='str', choices=[ 'autoscaling:EC2_INSTANCE_TERMINATING', 'autoscaling:EC2_INSTANCE_LAUNCHING' ]), role_arn=dict(type='str'), notification_target_arn=dict(type='str'), notification_meta_data=dict(type='str'), heartbeat_timeout=dict(type='int'), default_result=dict(default='ABANDON', choices=['ABANDON', 'CONTINUE']), state=dict(default='present', choices=['present', 'absent'])) module = AnsibleAWSModule( argument_spec=argument_spec, required_if=[['state', 'present', ['transition']]]) state = module.params.get('state') connection = module.client('autoscaling') changed = False if state == 'present': changed = create_lifecycle_hook(connection, module) elif state == 'absent': changed = delete_lifecycle_hook(connection, module) module.exit_json(changed=changed)
def main(): argument_spec = dict( instance_id={"required": True, "type": "str"}, get_unused_target_groups={"required": False, "default": True, "type": "bool"} ) module = AnsibleAWSModule( argument_spec=argument_spec, supports_check_mode=True, ) if module._name == 'elb_target_facts': module.deprecate("The 'elb_target_facts' module has been renamed to 'elb_target_info'", version='2.13') instance_id = module.params["instance_id"] get_unused_target_groups = module.params["get_unused_target_groups"] tg_gatherer = TargetInfoGatherer(module, instance_id, get_unused_target_groups ) instance_target_groups = [each.to_dict() for each in tg_gatherer.tgs] module.exit_json(instance_target_groups=instance_target_groups)
def main(): argument_spec = dict( db_snapshot_identifier=dict(aliases=['snapshot_name']), db_instance_identifier=dict(), db_cluster_identifier=dict(), db_cluster_snapshot_identifier=dict(), snapshot_type=dict( choices=['automated', 'manual', 'shared', 'public'])) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True, mutually_exclusive=[[ 'db_snapshot_identifier', 'db_instance_identifier', 'db_cluster_identifier', 'db_cluster_snapshot_identifier' ]]) if module._name == 'rds_snapshot_facts': module.deprecate( "The 'rds_snapshot_facts' module has been renamed to 'rds_snapshot_info'", version='2.13') conn = module.client('rds', retry_decorator=AWSRetry.jittered_backoff(retries=10)) results = dict() if not module.params['db_cluster_identifier'] and not module.params[ 'db_cluster_snapshot_identifier']: results['snapshots'] = standalone_snapshot_info(module, conn) if not module.params['db_snapshot_identifier'] and not module.params[ 'db_instance_identifier']: results['cluster_snapshots'] = cluster_snapshot_info(module, conn) module.exit_json(changed=False, **results)
def main(): argument_spec = dict(name=dict(required=True, type='str'), role_arn=dict(required=True, type='str'), artifact_store=dict(required=True, type='dict'), stages=dict(required=True, type='list'), version=dict(type='int'), state=dict(choices=['present', 'absent'], default='present')) module = AnsibleAWSModule(argument_spec=argument_spec) client_conn = module.client('codepipeline') state = module.params.get('state') changed = False # Determine if the CodePipeline exists found_code_pipeline = describe_pipeline(client=client_conn, name=module.params['name'], version=module.params['version'], module=module) pipeline_result = {} if state == 'present': if 'pipeline' in found_code_pipeline: pipeline_dict = copy.deepcopy(found_code_pipeline['pipeline']) # Update dictionary with provided module params: pipeline_dict['roleArn'] = module.params['role_arn'] pipeline_dict['artifactStore'] = module.params['artifact_store'] pipeline_dict['stages'] = module.params['stages'] if module.params['version'] is not None: pipeline_dict['version'] = module.params['version'] pipeline_result = update_pipeline(client=client_conn, pipeline_dict=pipeline_dict, module=module) if compare_policies(found_code_pipeline['pipeline'], pipeline_result['pipeline']): changed = True else: pipeline_result = create_pipeline( client=client_conn, name=module.params['name'], role_arn=module.params['role_arn'], artifact_store=module.params['artifact_store'], stages=module.params['stages'], version=module.params['version'], module=module) changed = True elif state == 'absent': if found_code_pipeline: pipeline_result = delete_pipeline(client=client_conn, name=module.params['name'], module=module) changed = True module.exit_json(changed=changed, **camel_dict_to_snake_dict(pipeline_result))
def main(): argument_spec = ec2_argument_spec() argument_spec.update( dict(az=dict(default=None, required=False), cidr=dict(required=True), ipv6_cidr=dict(default='', required=False), state=dict(default='present', choices=['present', 'absent']), tags=dict(default={}, required=False, type='dict', aliases=['resource_tags']), vpc_id=dict(required=True), map_public=dict(default=False, required=False, type='bool'), assign_instances_ipv6=dict(default=False, required=False, type='bool'), wait=dict(type='bool', default=True), wait_timeout=dict(type='int', default=300, required=False), purge_tags=dict(default=True, type='bool'))) required_if = [('assign_instances_ipv6', True, ['ipv6_cidr'])] module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True, required_if=required_if) if module.params.get( 'assign_instances_ipv6') and not module.params.get('ipv6_cidr'): module.fail_json( msg= "assign_instances_ipv6 is True but ipv6_cidr is None or an empty string" ) if not module.botocore_at_least("1.7.0"): module.warn( "botocore >= 1.7.0 is required to use wait_timeout for custom wait times" ) region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True) connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params) state = module.params.get('state') try: if state == 'present': result = ensure_subnet_present(connection, module) elif state == 'absent': result = ensure_subnet_absent(connection, module) except botocore.exceptions.ClientError as e: module.fail_json_aws(e) module.exit_json(**result)
def main(): module = AnsibleAWSModule( argument_spec={ 'name': dict(type='str', required=True), 'state': dict(type='str', choices=['present', 'absent'], default='present'), 's3_bucket': dict(type='str', required=True), 's3_prefix': dict(type='str'), 'sns_topic_arn': dict(type='str'), 'delivery_frequency': dict(type='str', choices=[ 'One_Hour', 'Three_Hours', 'Six_Hours', 'Twelve_Hours', 'TwentyFour_Hours' ]), }, supports_check_mode=False, ) result = {'changed': False} name = module.params.get('name') state = module.params.get('state') params = {} if name: params['name'] = name if module.params.get('s3_bucket'): params['s3BucketName'] = module.params.get('s3_bucket') if module.params.get('s3_prefix'): params['s3KeyPrefix'] = module.params.get('s3_prefix') if module.params.get('sns_topic_arn'): params['snsTopicARN'] = module.params.get('sns_topic_arn') if module.params.get('delivery_frequency'): params['configSnapshotDeliveryProperties'] = { 'deliveryFrequency': module.params.get('delivery_frequency') } client = module.client('config', retry_decorator=AWSRetry.jittered_backoff()) resource_status = resource_exists(client, module, params) if state == 'present': if not resource_status: create_resource(client, module, params, result) if resource_status: update_resource(client, module, params, result) if state == 'absent': if resource_status: delete_resource(client, module, params, result) module.exit_json(**result)
def main(): module = AnsibleAWSModule( argument_spec=dict(filters=dict(type='dict', default={})), supports_check_mode=True) if module._module._name == 'ec2_eip_facts': module._module.deprecate( "The 'ec2_eip_facts' module has been renamed to 'ec2_eip_info'", version='2.13') module.exit_json(changed=False, addresses=get_eips_details(module))
def main(): argument_spec = dict( state=dict(type='str', choices=['present', 'absent'], default='present'), identifier=dict(type='str', required=True), description=dict(type='str', required=True), subnet_ids=dict(type='list', elements='str', required=True), ) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) exit_message = None changed = False state = module.params.get('state') dmsclient = module.client('dms') subnet_group = describe_subnet_group(dmsclient, module.params.get('identifier')) if state == 'present': if replication_subnet_exists(subnet_group): if compare_params(module, subnet_group["ReplicationSubnetGroups"][0]): if not module.check_mode: exit_message = modify_replication_subnet_group( module, dmsclient) else: exit_message = dmsclient changed = True else: exit_message = "No changes to Subnet group" else: if not module.check_mode: exit_message = create_replication_subnet_group( module, dmsclient) changed = True else: exit_message = "Check mode enabled" elif state == 'absent': if replication_subnet_exists(subnet_group): if not module.check_mode: replication_subnet_group_delete(module, dmsclient) changed = True exit_message = "Replication subnet group Deleted" else: exit_message = dmsclient changed = True else: changed = False exit_message = "Replication subnet group does not exist" module.exit_json(changed=changed, msg=exit_message)
def main(): argument_spec = dict(name=dict(required=True), state=dict(choices=['present', 'absent'], required=True), description=dict(default='', aliases=['comment'])) ansible_aws_module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) aws_codecommit = CodeCommit(module=ansible_aws_module) result = aws_codecommit.process() ansible_aws_module.exit_json(**camel_dict_to_snake_dict(result))
def run_module(): argument_spec = ec2_argument_spec() argument_spec.update( dict( cluster_name=dict(type='str', required=True, aliases=['cluster']), state=dict(type='str', choices=['present', 'absent'], default='present'), region=dict(type='str', required=True, aliases=['source']), destination_region=dict(type='str', required=True, aliases=['destination']), snapshot_copy_grant=dict(type='str', aliases=['copy_grant']), snapshot_retention_period=dict(type='int', required=True, aliases=['retention_period']), ) ) module = AnsibleAWSModule( argument_spec=argument_spec, supports_check_mode=True ) result = dict( changed=False, message='' ) connection = module.client('redshift') snapshot_controller = SnapshotController(client=connection, cluster_name=module.params.get('cluster_name')) current_config = snapshot_controller.get_cluster_snapshot_copy_status() if current_config is not None: if module.params.get('state') == 'present': if requesting_unsupported_modifications(current_config, module.params): message = 'Cannot modify destination_region or grant_name. ' \ 'Please disable cross-region snapshots, and re-run.' module.fail_json(msg=message, **result) if needs_update(current_config, module.params): result['changed'] = True if not module.check_mode: snapshot_controller.modify_snapshot_copy_retention_period( module.params.get('snapshot_retention_period') ) else: result['changed'] = True if not module.check_mode: snapshot_controller.disable_snapshot_copy() else: if module.params.get('state') == 'present': result['changed'] = True if not module.check_mode: snapshot_controller.enable_snapshot_copy(module.params.get('destination_region'), module.params.get('snapshot_copy_grant'), module.params.get('snapshot_retention_period')) module.exit_json(**result)
def main(): event_types = [ 's3:ObjectCreated:*', 's3:ObjectCreated:Put', 's3:ObjectCreated:Post', 's3:ObjectCreated:Copy', 's3:ObjectCreated:CompleteMultipartUpload', 's3:ObjectRemoved:*', 's3:ObjectRemoved:Delete', 's3:ObjectRemoved:DeleteMarkerCreated', 's3:ObjectRestore:Post', 's3:ObjectRestore:Completed', 's3:ReducedRedundancyLostObject' ] argument_spec = dict( state=dict(default='present', choices=['present', 'absent']), event_name=dict(required=True), lambda_function_arn=dict(aliases=['function_arn']), bucket_name=dict(required=True), events=dict(type='list', default=[], choices=event_types), prefix=dict(default=''), suffix=dict(default=''), lambda_alias=dict(), lambda_version=dict(type='int', default=0), ) module = AnsibleAWSModule( argument_spec=argument_spec, supports_check_mode=True, mutually_exclusive=[['lambda_alias', 'lambda_version']], required_if=[['state', 'present', ['events']]]) bucket = AmazonBucket(module.client('s3'), module.params['bucket_name']) current = bucket.current_config(module.params['event_name']) desired = Config.from_params(**module.params) notification_configuration = [cfg.raw for cfg in bucket.full_config()] state = module.params['state'] try: if (state == 'present' and current == desired) or (state == 'absent' and not current): changed = False elif module.check_mode: changed = True elif state == 'present': changed = True notification_configuration = bucket.apply_config(desired) elif state == 'absent': changed = True notification_configuration = bucket.delete_config(desired) except (ClientError, BotoCoreError) as e: module.fail_json(msg='{0}'.format(e)) module.exit_json(**dict(changed=changed, notification_configuration=[ camel_dict_to_snake_dict(cfg) for cfg in notification_configuration ]))
def main(): """ Module action handler """ argument_spec = ec2_argument_spec() argument_spec.update( dict(id=dict(), name=dict(aliases=['creation_token']), tags=dict(type="dict", default={}), targets=dict(type="list", default=[]))) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) is_old_facts = module._name == 'efs_facts' if is_old_facts: module.deprecate( "The 'efs_facts' module has been renamed to 'efs_info', " "and the renamed one no longer returns ansible_facts", version='2.13') region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True) connection = EFSConnection(module, region, **aws_connect_params) name = module.params.get('name') fs_id = module.params.get('id') tags = module.params.get('tags') targets = module.params.get('targets') file_systems_info = connection.get_file_systems(fs_id, name) if tags: file_systems_info = [ item for item in file_systems_info if has_tags(item['tags'], tags) ] file_systems_info = connection.get_mount_targets_data(file_systems_info) file_systems_info = connection.get_security_groups_data(file_systems_info) if targets: targets = [(item, prefix_to_attr(item)) for item in targets] file_systems_info = [ item for item in file_systems_info if has_targets(item['mount_targets'], targets) ] if is_old_facts: module.exit_json(changed=False, ansible_facts={'efs': file_systems_info}) else: module.exit_json(changed=False, efs=file_systems_info)
def main(): argument_spec = dict(state=dict(required=True, choices=['present', 'absent']), name=dict(), location=dict(), bandwidth=dict(choices=['1Gbps', '10Gbps']), link_aggregation_group=dict(), connection_id=dict(), forced_update=dict(type='bool', default=False)) module = AnsibleAWSModule(argument_spec=argument_spec, required_one_of=[('connection_id', 'name')], required_if=[('state', 'present', ('location', 'bandwidth'))]) connection = module.client('directconnect') state = module.params.get('state') try: connection_id = connection_exists( connection, connection_id=module.params.get('connection_id'), connection_name=module.params.get('name')) if not connection_id and module.params.get('connection_id'): module.fail_json( msg="The Direct Connect connection {0} does not exist.".format( module.params.get('connection_id'))) if state == 'present': changed, connection_id = ensure_present( connection, connection_id=connection_id, connection_name=module.params.get('name'), location=module.params.get('location'), bandwidth=module.params.get('bandwidth'), lag_id=module.params.get('link_aggregation_group'), forced_update=module.params.get('forced_update')) response = connection_status(connection, connection_id) elif state == 'absent': changed = ensure_absent(connection, connection_id) response = {} except DirectConnectError as e: if e.last_traceback: module.fail_json(msg=e.msg, exception=e.last_traceback, **camel_dict_to_snake_dict(e.exception.response)) else: module.fail_json(msg=e.msg) module.exit_json(changed=changed, **camel_dict_to_snake_dict(response))
def main(): argument_spec = dict( state=dict(choices=['present', 'absent'], default='present'), origin_access_identity_id=dict(), caller_reference=dict(), comment=dict(), ) result = {} e_tag = None changed = False module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=False) service_mgr = CloudFrontOriginAccessIdentityServiceManager(module) validation_mgr = CloudFrontOriginAccessIdentityValidationManager(module) state = module.params.get('state') caller_reference = module.params.get('caller_reference') comment = module.params.get('comment') origin_access_identity_id = module.params.get('origin_access_identity_id') if origin_access_identity_id is None and caller_reference is not None: origin_access_identity_id = validation_mgr.validate_origin_access_identity_id_from_caller_reference( caller_reference) e_tag = validation_mgr.validate_etag_from_origin_access_identity_id( origin_access_identity_id) comment = validation_mgr.validate_comment(comment) if state == 'present': if origin_access_identity_id is not None and e_tag is not None: result, changed = service_mgr.update_origin_access_identity( caller_reference, comment, origin_access_identity_id, e_tag) else: result = service_mgr.create_origin_access_identity( caller_reference, comment) changed = True elif (state == 'absent' and origin_access_identity_id is not None and e_tag is not None): result = service_mgr.delete_origin_access_identity( origin_access_identity_id, e_tag) changed = True result.pop('ResponseMetadata', None) module.exit_json(changed=changed, **camel_dict_to_snake_dict(result))
def main(): argument_spec = dict( db_instance_identifier=dict(aliases=['id']), filters=dict(type='dict') ) module = AnsibleAWSModule( argument_spec=argument_spec, supports_check_mode=True, ) if module._name == 'rds_instance_facts': module.deprecate("The 'rds_instance_facts' module has been renamed to 'rds_instance_info'", version='2.13') conn = module.client('rds', retry_decorator=AWSRetry.jittered_backoff(retries=10)) module.exit_json(**instance_info(module, conn))
def main(): filters_subspec = dict( country=dict(), field_to_match=dict( choices=['uri', 'query_string', 'header', 'method', 'body']), header=dict(), transformation=dict(choices=[ 'none', 'compress_white_space', 'html_entity_decode', 'lowercase', 'cmd_line', 'url_decode' ]), position=dict(choices=[ 'exactly', 'starts_with', 'ends_with', 'contains', 'contains_word' ]), comparison=dict(choices=['EQ', 'NE', 'LE', 'LT', 'GE', 'GT']), target_string=dict(), # Bytes size=dict(type='int'), ip_address=dict(), regex_pattern=dict(), ) argument_spec = dict( name=dict(required=True), type=dict(required=True, choices=['byte', 'geo', 'ip', 'regex', 'size', 'sql', 'xss']), filters=dict(type='list'), purge_filters=dict(type='bool', default=False), waf_regional=dict(type='bool', default=False), state=dict(default='present', choices=['present', 'absent']), ) module = AnsibleAWSModule(argument_spec=argument_spec, required_if=[['state', 'present', ['filters']]]) state = module.params.get('state') resource = 'waf' if not module.params['waf_regional'] else 'waf-regional' client = module.client(resource) condition = Condition(client, module) if state == 'present': (changed, results) = condition.ensure_condition_present() # return a condition agnostic ID for use by aws_waf_rule results['ConditionId'] = results[condition.conditionsetid] else: (changed, results) = condition.ensure_condition_absent() module.exit_json(changed=changed, condition=camel_dict_to_snake_dict(results))
def main(): module = AnsibleAWSModule( argument_spec={ 'state': dict(choices=['present', 'absent'], required=True), 'min_pw_length': dict(type='int', aliases=['minimum_password_length'], default=6), 'require_symbols': dict(type='bool', default=False), 'require_numbers': dict(type='bool', default=False), 'require_uppercase': dict(type='bool', default=False), 'require_lowercase': dict(type='bool', default=False), 'allow_pw_change': dict(type='bool', aliases=['allow_password_change'], default=False), 'pw_max_age': dict(type='int', aliases=['password_max_age'], default=0), 'pw_reuse_prevent': dict(type='int', aliases=['password_reuse_prevent', 'prevent_reuse'], default=0), 'pw_expire': dict(type='bool', aliases=['password_expire', 'expire'], default=False), }, supports_check_mode=True, ) resource = IAMConnection(module) policy = resource.connection.AccountPasswordPolicy() state = module.params.get('state') if state == 'present': (changed, new_policy, update_result) = resource.update_password_policy(module, policy) module.exit_json(changed=changed, task_status={'IAM': update_result}, policy=new_policy) if state == 'absent': delete_result = resource.delete_password_policy(policy) module.exit_json(changed=True, task_status={'IAM': delete_result})
def main(): argument_spec = dict( zone=dict(required=True), state=dict(default='present', choices=['present', 'absent']), vpc_id=dict(default=None), vpc_region=dict(default=None), comment=dict(default=''), hosted_zone_id=dict(), delegation_set_id=dict(), ) mutually_exclusive = [ ['delegation_set_id', 'vpc_id'], ['delegation_set_id', 'vpc_region'], ] module = AnsibleAWSModule( argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, supports_check_mode=True, ) zone_in = module.params.get('zone').lower() state = module.params.get('state').lower() vpc_id = module.params.get('vpc_id') vpc_region = module.params.get('vpc_region') if not zone_in.endswith('.'): zone_in += "." private_zone = bool(vpc_id and vpc_region) client = module.client('route53') zones = find_zones(module, client, zone_in, private_zone) if state == 'present': changed, result = create(module, client, matching_zones=zones) elif state == 'absent': changed, result = delete(module, client, matching_zones=zones) if isinstance(result, dict): module.exit_json(changed=changed, result=result, **result) else: module.exit_json(changed=changed, result=result)
def main(): argument_spec = dict( name=dict(required=True), state=dict(default='present', choices=['present', 'absent']), display_name=dict(), policy=dict(type='dict'), delivery_policy=dict(type='dict'), subscriptions=dict(default=[], type='list'), purge_subscriptions=dict(type='bool', default=True), ) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) name = module.params.get('name') state = module.params.get('state') display_name = module.params.get('display_name') policy = module.params.get('policy') delivery_policy = module.params.get('delivery_policy') subscriptions = module.params.get('subscriptions') purge_subscriptions = module.params.get('purge_subscriptions') check_mode = module.check_mode sns_topic = SnsTopicManager(module, name, state, display_name, policy, delivery_policy, subscriptions, purge_subscriptions, check_mode) if state == 'present': changed = sns_topic.ensure_ok() elif state == 'absent': changed = sns_topic.ensure_gone() sns_facts = dict(changed=changed, sns_arn=sns_topic.topic_arn, sns_topic=sns_topic.get_info()) module.exit_json(**sns_facts)
def main(): argument_spec = ec2_argument_spec() argument_spec.update( dict(name=dict(required=True, type='str'), state=dict(default='present', choices=['present', 'absent']), strategy=dict(default='cluster', choices=['cluster', 'spread']))) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True) connection = boto3_conn(module, resource='ec2', conn_type='client', region=region, endpoint=ec2_url, **aws_connect_params) state = module.params.get("state") if state == 'present': placement_group = get_placement_group_details(connection, module) if placement_group is None: create_placement_group(connection, module) else: strategy = module.params.get("strategy") if placement_group['strategy'] == strategy: module.exit_json(changed=False, placement_group=placement_group) else: name = module.params.get("name") module.fail_json( msg=("Placement group '{}' exists, can't change strategy" + " from '{}' to '{}'" ).format(name, placement_group['strategy'], strategy)) elif state == 'absent': placement_group = get_placement_group_details(connection, module) if placement_group is None: module.exit_json(changed=False) else: delete_placement_group(connection, module)