Beispiel #1
0
def gce_connect(module, provider=Provider.GCE):
    """Return a GCP connection for Google Compute Engine."""
    if not HAS_LIBCLOUD_BASE:
        module.fail_json(msg='libcloud must be installed to use this module')

    return gcp_connect(module, provider, get_driver, USER_AGENT_PRODUCT,
                       USER_AGENT_VERSION)
Beispiel #2
0
def gce_connect(module, provider=None):
    """Return a GCP connection for Google Compute Engine."""
    if not HAS_LIBCLOUD_BASE:
        module.fail_json(msg='libcloud must be installed to use this module')
    provider = provider or Provider.GCE

    return gcp_connect(module, provider, get_driver, USER_AGENT_PRODUCT, USER_AGENT_VERSION)
Beispiel #3
0
def gcdns_connect(module, provider=None):
    """Return a GCP connection for Google Cloud DNS."""
    if not HAS_LIBCLOUD_BASE:
        module.fail_json(msg='libcloud must be installed to use this module')

    provider = provider or Provider.GOOGLE
    return gcp_connect(module, provider, get_driver, USER_AGENT_PRODUCT,
                       USER_AGENT_VERSION)
Beispiel #4
0
def main():
    module = AnsibleModule(argument_spec=dict(
        name=dict(required=True),
        state=dict(choices=['absent', 'present'], default='present'),
        region=dict(required=True),
        service_account_email=dict(),
        service_account_permissions=dict(type='list'),
        pem_file=dict(type='path'),
        credentials_file=dict(type='path'),
        project_id=dict(), ), )

    if not HAS_PYTHON26:
        module.fail_json(
            msg="GCE module requires python's 'ast' module, python v2.6+")
    if not HAS_LIBCLOUD:
        module.fail_json(
            msg='libcloud with GCE support (+0.19) required for this module.')

    gce = gcp_connect(module, Provider.GCE, get_driver,
                      USER_AGENT_PRODUCT, USER_AGENT_VERSION)

    params = {}
    params['state'] = module.params.get('state')
    params['name'] = module.params.get('name')
    params['region'] = module.params.get('region')

    changed = False
    json_output = {'state': params['state']}
    address = get_address(gce, params['name'], region=params['region'])

    if params['state'] == 'absent':
        if not address:
            # Doesn't exist in GCE, and state==absent.
            changed = False
            module.fail_json(
                msg="Cannot delete unknown address: %s" %
                (params['name']))
        else:
            # Delete
            (changed, json_output['address']) = delete_address(address)
    else:
        if not address:
            # Create
            (changed, json_output['address']) = create_address(gce,
                                                               params)
        else:
            changed = False
            json_output['address'] = address.address

    json_output['changed'] = changed
    json_output.update(params)
    module.exit_json(**json_output)
Beispiel #5
0
def main():
    module = AnsibleModule(argument_spec=dict(
        name=dict(required=True),
        state=dict(choices=['absent', 'present'], default='present'),
        region=dict(required=True),
        service_account_email=dict(),
        service_account_permissions=dict(type='list'),
        pem_file=dict(type='path'),
        credentials_file=dict(type='path'),
        project_id=dict(), ), )

    if not HAS_PYTHON26:
        module.fail_json(
            msg="GCE module requires python's 'ast' module, python v2.6+")
    if not HAS_LIBCLOUD:
        module.fail_json(
            msg='libcloud with GCE support (+0.19) required for this module.')

    gce = gcp_connect(module, Provider.GCE, get_driver,
                      USER_AGENT_PRODUCT, USER_AGENT_VERSION)

    params = {}
    params['state'] = module.params.get('state')
    params['name'] = module.params.get('name')
    params['region'] = module.params.get('region')

    changed = False
    json_output = {'state': params['state']}
    address = get_address(gce, params['name'], region=params['region'])

    if params['state'] == 'absent':
        if not address:
            # Doesn't exist in GCE, and state==absent.
            changed = False
            module.fail_json(
                msg="Cannot delete unknown address: %s" %
                (params['name']))
        else:
            # Delete
            (changed, json_output['address']) = delete_address(address)
    else:
        if not address:
            # Create
            (changed, json_output['address']) = create_address(gce,
                                                               params)
        else:
            changed = False
            json_output['address'] = address.address

    json_output['changed'] = changed
    json_output.update(params)
    module.exit_json(**json_output)