def main(): argument_spec = ec2_argument_spec() argument_spec.update( dict(source_region=dict(required=True), source_image_id=dict(required=True), name=dict(), description=dict(default=""), encrypted=dict(type='bool', required=False), kms_key_id=dict(type='str', required=False), wait=dict(type='bool', default=False), wait_timeout=dict(default=1200), tags=dict(type='dict'))) module = AnsibleModule(argument_spec=argument_spec) if not HAS_BOTO: module.fail_json(msg='boto required for this module') try: ec2 = ec2_connect(module) except fcu_boto.exception.NoAuthHandlerFound as e: module.fail_json(msg=str(e)) try: region, ec2_url, boto_params = get_aws_connection_info(module) except fcu_boto.exception.NoAuthHandlerFound as e: module.fail_json(msg=str(e)) if not region: module.fail_json(msg="region must be specified") copy_image(module, ec2)
def main(): argument_spec = ec2_argument_spec() argument_spec.update( dict(snapshot_ids=dict(default=[], type='list'), owner_ids=dict(default=[], type='list'), restorable_by_user_ids=dict(default=[], type='list'), filters=dict(default={}, type='dict'))) module = AnsibleModule(argument_spec=argument_spec, mutually_exclusive=[[ 'snapshot_ids', 'owner_ids', 'restorable_by_user_ids', 'filters' ]]) if not HAS_BOTO3: module.fail_json(msg='boto3 required for this module') region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True) if region: connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params) else: module.fail_json(msg="region must be specified") list_ec2_snapshots(connection, module)
def main(): argument_spec = ec2_argument_spec() argument_spec.update( dict(eni_id=dict(default=None, type='str'), instance_id=dict(default=None, type='str'), private_ip_address=dict(type='str'), subnet_id=dict(type='str'), description=dict(type='str'), security_groups=dict(default=[], type='list'), device_index=dict(default=0, type='int'), state=dict(default='present', choices=['present', 'absent']), force_detach=dict(default='no', type='bool'), source_dest_check=dict(default=None, type='bool'), delete_on_termination=dict(default=None, type='bool'), secondary_private_ip_addresses=dict(default=None, type='list'), secondary_private_ip_address_count=dict(default=None, type='int'), attached=dict(default=None, type='bool'))) module = AnsibleModule(argument_spec=argument_spec, mutually_exclusive=[[ 'secondary_private_ip_addresses', 'secondary_private_ip_address_count' ]], required_if=([('state', 'present', ['subnet_id']), ('state', 'absent', ['eni_id']), ('attached', True, ['instance_id'])])) if not HAS_BOTO: module.fail_json(msg='boto required for this module') region, ec2_url, aws_connect_params = get_aws_connection_info(module) if region: try: connection = connect_to_aws(fcu_boto.ec2, region, **aws_connect_params) vpc_connection = connect_to_aws(fcu_boto.vpc, region, **aws_connect_params) except (fcu_boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e: module.fail_json(msg=str(e)) else: module.fail_json(msg="region must be specified") state = module.params.get("state") eni_id = module.params.get("eni_id") private_ip_address = module.params.get('private_ip_address') if state == 'present': subnet_id = module.params.get("subnet_id") vpc_id = _get_vpc_id(vpc_connection, module, subnet_id) eni = find_eni(connection, module) if eni is None: create_eni(connection, vpc_id, module) else: modify_eni(connection, vpc_id, module, eni) elif state == 'absent': delete_eni(connection, module)
def main(): argument_spec = ec2_argument_spec() argument_spec.update( dict(az=dict(default=None, required=False), cidr=dict(default=None, required=True), state=dict(default='present', choices=['present', 'absent']), tags=dict(default=None, required=False, type='dict', aliases=['resource_tags']), vpc_id=dict(default=None, required=True))) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) if not HAS_BOTO: module.fail_json(msg='boto is required for this module') region, ec2_url, aws_connect_params = get_aws_connection_info(module) if region: try: connection = connect_to_aws(fcu_boto.vpc, region, **aws_connect_params) except (fcu_boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e: module.fail_json(msg=str(e)) else: module.fail_json(msg="region must be specified") vpc_id = module.params.get('vpc_id') tags = module.params.get('tags') cidr = module.params.get('cidr') az = module.params.get('az') state = module.params.get('state') try: if state == 'present': result = ensure_subnet_present(connection, vpc_id, cidr, az, tags, check_mode=module.check_mode) elif state == 'absent': result = ensure_subnet_absent(connection, vpc_id, cidr, check_mode=module.check_mode) except AnsibleVPCSubnetException as e: module.fail_json(msg=str(e)) module.exit_json(**result)
def main(): argument_spec = ec2_argument_spec() argument_spec.update( dict(lookup=dict(default='tag', required=False, choices=['tag', 'id']), propagating_vgw_ids=dict(default=None, required=False, type='list'), route_table_id=dict(default=None, required=False), routes=dict(default=[], required=False, type='list'), state=dict(default='present', choices=['present', 'absent']), subnets=dict(default=None, required=False, type='list'), tags=dict(default=None, required=False, type='dict', aliases=['resource_tags']), vpc_id=dict(default=None, required=True))) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) if not HAS_BOTO: module.fail_json(msg='boto is required for this module') region, ec2_url, aws_connect_params = get_aws_connection_info(module) if region: try: connection = connect_to_aws(fcu_boto.vpc, region, **aws_connect_params) except (fcu_boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e: module.fail_json(msg=str(e)) else: module.fail_json(msg="region must be specified") lookup = module.params.get('lookup') route_table_id = module.params.get('route_table_id') state = module.params.get('state', 'present') if lookup == 'id' and route_table_id is None: module.fail_json( "You must specify route_table_id if lookup is set to id") try: if state == 'present': result = ensure_route_table_present(connection, module) elif state == 'absent': result = ensure_route_table_absent(connection, module) except AnsibleRouteTableException as e: module.fail_json(msg=str(e)) module.exit_json(**result)
def main(): argument_spec = ec2_argument_spec() argument_spec.update(dict(filters=dict(default=None, type='dict'))) module = AnsibleModule(argument_spec=argument_spec) if not HAS_BOTO: module.fail_json(msg='boto required for this module') if HAS_BOTO3: region, ec2_url, aws_connect_params = get_aws_connection_info( module, boto3=True) if region: connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params) else: module.fail_json(msg="region must be specified") list_ec2_snapshots_boto3(connection, module) else: region, ec2_url, aws_connect_params = get_aws_connection_info(module) if region: try: connection = connect_to_aws(fcu_boto.ec2, region, **aws_connect_params) except (fcu_boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e: module.fail_json(msg=str(e)) else: module.fail_json(msg="region must be specified") list_eni(connection, module)
def __init__(self, module): self.module = module try: region, ec2_url, aws_connect_kwargs = get_aws_connection_info( module, boto3=True) if not region: module.fail_json( msg= "Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file" ) self.ec2 = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_kwargs) except ClientError as e: module.fail_json(msg=e.message)
def main(): argument_spec = ec2_argument_spec() argument_spec.update(dict(filters=dict(default=None, type='dict'))) module = AnsibleModule(argument_spec=argument_spec) if not HAS_BOTO: module.fail_json(msg='boto required for this module') region, ec2_url, aws_connect_params = get_aws_connection_info(module) if region: try: connection = connect_to_aws(fcu_boto.vpc, region, **aws_connect_params) except (fcu_boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e: module.fail_json(msg=str(e)) else: module.fail_json(msg="region must be specified") list_ec2_vpc_route_tables(connection, 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 = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) if not HAS_BOTO: module.fail_json(msg='boto is required for this module') region, ec2_url, aws_connect_params = get_aws_connection_info(module) if region: try: connection = connect_to_aws(fcu_boto.vpc, region, **aws_connect_params) except (fcu_boto.exception.NoAuthHandlerFound, AnsibleAWSError) as e: module.fail_json(msg=str(e)) else: module.fail_json(msg="region must be specified") vpc_id = module.params.get('vpc_id') state = module.params.get('state', 'present') try: if state == 'present': result = ensure_igw_present(connection, vpc_id, check_mode=module.check_mode) elif state == 'absent': result = ensure_igw_absent(connection, vpc_id, check_mode=module.check_mode) except AnsibleIGWException as e: module.fail_json(msg=str(e)) module.exit_json(**result)
def main(): argument_spec = ec2_argument_spec() argument_spec.update( dict( vpc_id=dict(required=True), name=dict(required=True), subnets=dict(required=False, type='list', default=list()), tags=dict(required=False, type='dict'), ingress=dict(required=False, type='list', default=list()), egress=dict( required=False, type='list', default=list(), ), state=dict(default='present', choices=['present', 'absent']), ), ) module = AnsibleModule(argument_spec=argument_spec) if not HAS_BOTO3: module.fail_json(msg='json, botocore and boto3 are required.') state = module.params.get('state').lower() try: region, ec2_url, aws_connect_kwargs = get_aws_connection_info( module, boto3=True) client = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_kwargs) except botocore.exceptions.NoCredentialsError as e: module.fail_json(msg="Can't authorize connection - %s" % str(e)) invocations = {"present": setup_network_acl, "absent": remove_network_acl} (changed, results) = invocations[state](client, module) module.exit_json(changed=changed, nacl_id=results)