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( catalog_id=dict(type='str'), connection_properties=dict(type='dict'), connection_type=dict(type='str', default='JDBC', choices=['JDBC', 'SFTP']), description=dict(type='str'), match_criteria=dict(type='list'), name=dict(required=True, type='str'), security_groups=dict(type='list'), state=dict(required=True, choices=['present', 'absent'], type='str'), subnet_id=dict(type='str') ) ) module = AnsibleAWSModule(argument_spec=argument_spec, required_if=[ ('state', 'present', ['connection_properties']) ] ) connection_glue = module.client('glue') connection_ec2 = module.client('ec2') glue_connection = _get_glue_connection(connection_glue, module) if module.params.get("state") == 'present': create_or_update_glue_connection(connection_glue, connection_ec2, module, glue_connection) else: delete_glue_connection(connection_glue, module, glue_connection)
def setup_module_object(): """ merge argument spec and create Ansible module object :return: Ansible module object """ argument_spec = dict(asn=dict(type='int'), auto_associate=dict(type='bool', default='yes'), auto_attach=dict(type='bool', default='no'), auto_propagate=dict(type='bool', default='yes'), description=dict(type='str'), dns_support=dict(type='bool', default='yes'), purge_tags=dict(type='bool', default='yes'), state=dict(default='present', choices=['present', 'absent']), tags=dict(default=dict(), type='dict'), transit_gateway_id=dict(type='str'), vpn_ecmp_support=dict(type='bool', default='yes'), wait=dict(type='bool', default='yes'), wait_timeout=dict(type='int', default=300)) module = AnsibleAWSModule( argument_spec=argument_spec, required_one_of=[('description', 'transit_gateway_id')], supports_check_mode=True, ) return module
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( name=dict(type='str', required=True), state=dict(type='str', default='present', choices=['present', 'absent']), active=dict(type='bool'), force=dict(type='bool', default=False), ) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) state = module.params.get('state') # SES APIs seem to have a much lower throttling threshold than most of the rest of the AWS APIs. # Docs say 1 call per second. This shouldn't actually be a big problem for normal usage, but # the ansible build runs multiple instances of the test in parallel that's caused throttling # failures so apply a jittered backoff to call SES calls. client = module.client('ses', retry_decorator=AWSRetry.jittered_backoff()) if state == 'absent': remove_rule_set(client, module) else: create_or_update_rule_set(client, module)
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 = ec2_argument_spec() argument_spec.update( dict(role_arn=dict(required=True), role_session_name=dict(required=True), duration_seconds=dict(required=False, default=None, type='int'), external_id=dict(required=False, default=None), policy=dict(required=False, default=None), mfa_serial_number=dict(required=False, default=None), mfa_token=dict(required=False, default=None))) module = AnsibleAWSModule(argument_spec=argument_spec) region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) if region: connection = boto3_conn(module, conn_type='client', resource='sts', region=region, endpoint=ec2_url, **aws_connect_kwargs) else: module.fail_json(msg="region must be specified") assume_role_policy(connection, module)
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( 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(): """ Main entry point. :return dict: ansible facts """ argument_spec = dict( function_name=dict(required=False, default=None, aliases=['function', 'name']), query=dict(required=False, choices=['aliases', 'all', 'config', 'mappings', 'policy', 'versions'], default='all'), event_source_arn=dict(required=False, default=None) ) module = AnsibleAWSModule( argument_spec=argument_spec, supports_check_mode=True, mutually_exclusive=[], required_together=[] ) # validate function_name if present function_name = module.params['function_name'] if function_name: if not re.search(r"^[\w\-:]+$", function_name): module.fail_json( msg='Function name {0} is invalid. Names must contain only alphanumeric characters and hyphens.'.format(function_name) ) if len(function_name) > 64: module.fail_json(msg='Function name "{0}" exceeds 64 character limit'.format(function_name)) try: region, endpoint, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) aws_connect_kwargs.update(dict(region=region, endpoint=endpoint, conn_type='client', resource='lambda' )) client = boto3_conn(module, **aws_connect_kwargs) except ClientError as e: module.fail_json_aws(e, "trying to set up boto connection") this_module = sys.modules[__name__] invocations = dict( aliases='alias_details', all='all_details', config='config_details', mappings='mapping_details', policy='policy_details', versions='version_details', ) this_module_function = getattr(this_module, invocations[module.params['query']]) all_facts = fix_return(this_module_function(client, module)) results = dict(ansible_facts={'lambda_facts': {'function': all_facts}}, changed=False) if module.check_mode: results['msg'] = 'Check mode set but ignored for fact gathering only.' module.exit_json(**results)
def main(): argument_spec = dict( name=dict(required=True, type='str'), metric=dict(type='str'), namespace=dict(type='str'), statistic=dict(type='str', choices=['SampleCount', 'Average', 'Sum', 'Minimum', 'Maximum']), comparison=dict(type='str', choices=['LessThanOrEqualToThreshold', 'LessThanThreshold', 'GreaterThanThreshold', 'GreaterThanOrEqualToThreshold', '<=', '<', '>', '>=']), threshold=dict(type='float'), period=dict(type='int'), unit=dict(type='str', choices=['Seconds', 'Microseconds', 'Milliseconds', 'Bytes', 'Kilobytes', 'Megabytes', 'Gigabytes', 'Terabytes', 'Bits', 'Kilobits', 'Megabits', 'Gigabits', 'Terabits', 'Percent', 'Count', 'Bytes/Second', 'Kilobytes/Second', 'Megabytes/Second', 'Gigabytes/Second', 'Terabytes/Second', 'Bits/Second', 'Kilobits/Second', 'Megabits/Second', 'Gigabits/Second', 'Terabits/Second', 'Count/Second', 'None']), evaluation_periods=dict(type='int'), description=dict(type='str'), dimensions=dict(type='dict', default={}), alarm_actions=dict(type='list', default=[]), insufficient_data_actions=dict(type='list', default=[]), ok_actions=dict(type='list', default=[]), treat_missing_data=dict(type='str', choices=['breaching', 'notBreaching', 'ignore', 'missing'], default='missing'), state=dict(default='present', choices=['present', 'absent']), ) module = AnsibleAWSModule(argument_spec=argument_spec) state = module.params.get('state') connection = module.client('cloudwatch') if state == 'present': create_metric_alarm(connection, module) elif state == 'absent': delete_metric_alarm(connection, module)
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(): module = AnsibleAWSModule( argument_spec={ 'state': dict(type='str', choices=['present', 'absent'], default='present'), 'authorized_account_id': dict(type='str', required=True), 'authorized_aws_region': dict(type='str', required=True), }, supports_check_mode=False, ) result = {'changed': False} params = { 'AuthorizedAccountId': module.params.get('authorized_account_id'), 'AuthorizedAwsRegion': module.params.get('authorized_aws_region'), } client = module.client('config', retry_decorator=AWSRetry.jittered_backoff()) resource_status = resource_exists(client, module, params) if module.params.get('state') == 'present': if not resource_status: create_resource(client, module, params, result) else: update_resource(client, module, params, result) if module.params.get('state') == 'absent': if resource_status: delete_resource(client, module, params, result) module.exit_json(changed=result['changed'])
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(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( name=dict(required=True), managed_policies=dict(default=[], type='list', aliases=['managed_policy']), users=dict(default=[], type='list'), state=dict(choices=['present', 'absent'], required=True), purge_users=dict(default=False, type='bool'), purge_policies=dict(default=False, type='bool', aliases=['purge_policy', 'purge_managed_policies'])) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) connection = module.client('iam') state = module.params.get("state") if state == 'present': create_or_update_group(connection, module) else: destroy_group(connection, module)
def main(): argument_spec = ( dict( allocated_capacity=dict(type='int'), command_name=dict(type='str', default='glueetl'), command_script_location=dict(type='str'), connections=dict(type='list'), default_arguments=dict(type='dict'), description=dict(type='str'), max_concurrent_runs=dict(type='int'), max_retries=dict(type='int'), name=dict(required=True, type='str'), role=dict(type='str'), state=dict(required=True, choices=['present', 'absent'], type='str'), timeout=dict(type='int') ) ) module = AnsibleAWSModule(argument_spec=argument_spec, required_if=[ ('state', 'present', ['role', 'command_script_location']) ] ) connection = module.client('glue') state = module.params.get("state") glue_job = _get_glue_job(connection, module, module.params.get("name")) if state == 'present': create_or_update_glue_job(connection, module, glue_job) else: delete_glue_job(connection, module, glue_job)
def main(): module = AnsibleAWSModule( argument_spec={ 'identity': dict(required=True, type='str'), 'state': dict(default='present', choices=['present', 'absent']), 'policy_name': dict(required=True, type='str'), 'policy': dict(type='json', default=None), }, required_if=[['state', 'present', ['policy']]], supports_check_mode=True, ) # SES APIs seem to have a much lower throttling threshold than most of the rest of the AWS APIs. # Docs say 1 call per second. This shouldn't actually be a big problem for normal usage, but # the ansible build runs multiple instances of the test in parallel that's caused throttling # failures so apply a jittered backoff to call SES calls. connection = module.client('ses', retry_decorator=AWSRetry.jittered_backoff()) state = module.params.get("state") if state == 'present': create_or_update_identity_policy(connection, module) else: delete_identity_policy(connection, module)
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(): 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(): 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 = ec2_argument_spec() argument_spec.update( dict(name=dict(required=True), key_material=dict(), force=dict(type='bool', default=True), state=dict(default='present', choices=['present', 'absent']), wait=dict(type='bool', removed_in_version='2.14'), wait_timeout=dict(type='int', removed_in_version='2.14'))) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True) ec2_client = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params) name = module.params['name'] state = module.params.get('state') key_material = module.params.get('key_material') force = module.params.get('force') if state == 'absent': delete_key_pair(module, ec2_client, name) elif state == 'present': create_key_pair(module, ec2_client, name, key_material, force)
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(): 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(): 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 = dict(name=dict(), group=dict(), path=dict(default='/')) module = AnsibleAWSModule(argument_spec=argument_spec, mutually_exclusive=[['group', 'path']], supports_check_mode=True) connection = module.client('iam') list_iam_users(connection, module)
def main(): argument_spec = dict( api_id=dict(type='str', required=False), state=dict(type='str', default='present', choices=['present', 'absent']), swagger_file=dict(type='path', default=None, aliases=['src', 'api_file']), swagger_dict=dict(type='json', default=None), swagger_text=dict(type='str', default=None), stage=dict(type='str', default=None), deploy_desc=dict(type='str', default="Automatic deployment by Ansible."), ) mutually_exclusive = [['swagger_file', 'swagger_dict', 'swagger_text']] # noqa: F841 module = AnsibleAWSModule( argument_spec=argument_spec, supports_check_mode=False, mutually_exclusive=mutually_exclusive, ) api_id = module.params.get('api_id') state = module.params.get('state') # noqa: F841 swagger_file = module.params.get('swagger_file') swagger_dict = module.params.get('swagger_dict') swagger_text = module.params.get('swagger_text') stage = module.params.get('stage') deploy_desc = module.params.get('deploy_desc') client = module.client('apigateway') changed = True # for now it will stay that way until we can sometimes avoid change conf_res = None dep_res = None del_res = None if state == "present": if api_id is None: api_id = create_empty_api(module, client) api_data = get_api_definitions(module, swagger_file=swagger_file, swagger_dict=swagger_dict, swagger_text=swagger_text) conf_res, dep_res = ensure_api_in_correct_state(module, client, api_id=api_id, api_data=api_data, stage=stage, deploy_desc=deploy_desc) if state == "absent": del_res = delete_rest_api(module, client, api_id) exit_args = {"changed": changed, "api_id": api_id} if conf_res is not None: exit_args['configure_response'] = camel_dict_to_snake_dict(conf_res) if dep_res is not None: exit_args['deploy_response'] = camel_dict_to_snake_dict(dep_res) if del_res is not None: exit_args['delete_response'] = camel_dict_to_snake_dict(del_res) module.exit_json(**exit_args)
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 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)