예제 #1
0
def main():
    module = create_snapshot_ansible_module()

    if not HAS_BOTO:
        module.fail_json(msg='boto required for this module')

    volume_id = module.params.get('volume_id')
    snapshot_id = module.params.get('snapshot_id')
    description = module.params.get('description')
    instance_id = module.params.get('instance_id')
    device_name = module.params.get('device_name')
    wait = module.params.get('wait')
    wait_timeout = module.params.get('wait_timeout')
    last_snapshot_min_age = module.params.get('last_snapshot_min_age')
    snapshot_tags = module.params.get('snapshot_tags')
    state = module.params.get('state')

    ec2 = ec2_connect(module)

    create_snapshot(module=module,
                    state=state,
                    description=description,
                    wait=wait,
                    wait_timeout=wait_timeout,
                    ec2=ec2,
                    volume_id=volume_id,
                    instance_id=instance_id,
                    snapshot_id=snapshot_id,
                    device_name=device_name,
                    snapshot_tags=snapshot_tags,
                    last_snapshot_min_age=last_snapshot_min_age)
예제 #2
0
def main():
    module = AnsibleAWSModule(
        argument_spec={},
        supports_check_mode=True,
        check_boto3=False,
    )

    try:
        client = ec2_connect(module)
    except boto.exception.NoAuthHandlerFound as e:
        module.fail_json_aws(e, msg='Failed to get connection')

    filters = {'name': 'amzn2-ami-hvm-2.0.202006*-x86_64-gp2'}

    try:
        images = client.get_all_images(image_ids=[],
                                       filters=filters,
                                       owners=['amazon'],
                                       executable_by=[])
    except boto.exception.BotoServerError as e:
        module.fail_json_aws(e, msg='Fail JSON AWS')

    images_out = []
    for image in images:
        images_out.append(image.id)

    # Return something, just because we can.
    module.exit_json(changed=False, images=images_out)
def ec2_win_password(module):
    instance_id = module.params.get('instance_id')
    key_file = module.params.get('key_file')
    if module.params.get('key_passphrase') is None:
        b_key_passphrase = None
    else:
        b_key_passphrase = to_bytes(module.params.get('key_passphrase'),
                                    errors='surrogate_or_strict')
    if module.params.get('key_data') is None:
        b_key_data = None
    else:
        b_key_data = to_bytes(module.params.get('key_data'),
                              errors='surrogate_or_strict')
    wait = module.params.get('wait')
    wait_timeout = module.params.get('wait_timeout')

    ec2 = ec2_connect(module)

    if wait:
        start = datetime.datetime.now()
        end = start + datetime.timedelta(seconds=wait_timeout)

        while datetime.datetime.now() < end:
            data = ec2.get_password_data(instance_id)
            decoded = b64decode(data)
            if not decoded:
                time.sleep(5)
            else:
                break
    else:
        data = ec2.get_password_data(instance_id)
        decoded = b64decode(data)

    if wait and datetime.datetime.now() >= end:
        module.fail_json(msg="wait for password timeout after %d seconds" %
                         wait_timeout)

    if key_file is not None and b_key_data is None:
        try:
            with open(key_file, 'rb') as f:
                key = load_pem_private_key(f.read(), b_key_passphrase,
                                           default_backend())
        except IOError as e:
            # Handle bad files
            module.fail_json(msg="I/O error (%d) opening key file: %s" %
                             (e.errno, e.strerror))
        except (ValueError, TypeError) as e:
            # Handle issues loading key
            module.fail_json(msg="unable to parse key file")
    elif b_key_data is not None and key_file is None:
        try:
            key = load_pem_private_key(b_key_data, b_key_passphrase,
                                       default_backend())
        except (ValueError, TypeError) as e:
            module.fail_json(msg="unable to parse key data")

    try:
        decrypted = key.decrypt(decoded, PKCS1v15())
    except ValueError as e:
        decrypted = None

    if decrypted is None:
        module.exit_json(win_password='', changed=False)
    else:
        if wait:
            elapsed = datetime.datetime.now() - start
            module.exit_json(win_password=decrypted,
                             changed=True,
                             elapsed=elapsed.seconds)
        else:
            module.exit_json(win_password=decrypted, changed=True)
예제 #4
0
def main():
    argument_spec = ec2_argument_spec()
    argument_spec.update(
        dict(
            instance_id=dict(required=True),
            key_file=dict(required=False, default=None, type='path'),
            key_passphrase=dict(no_log=True, default=None, required=False),
            key_data=dict(no_log=True, default=None, required=False),
            wait=dict(type='bool', default=False, required=False),
            wait_timeout=dict(default=120, required=False, type='int'),
        ))
    module = AnsibleModule(argument_spec=argument_spec)

    if not HAS_BOTO:
        module.fail_json(msg='Boto required for this module.')

    if not HAS_CRYPTOGRAPHY:
        module.fail_json(msg='cryptography package required for this module.')

    instance_id = module.params.get('instance_id')
    key_file = module.params.get('key_file')
    key_data = module.params.get('key_data')
    if module.params.get('key_passphrase') is None:
        b_key_passphrase = None
    else:
        b_key_passphrase = to_bytes(module.params.get('key_passphrase'),
                                    errors='surrogate_or_strict')
    wait = module.params.get('wait')
    wait_timeout = module.params.get('wait_timeout')

    ec2 = ec2_connect(module)

    if wait:
        start = datetime.datetime.now()
        end = start + datetime.timedelta(seconds=wait_timeout)

        while datetime.datetime.now() < end:
            data = ec2.get_password_data(instance_id)
            decoded = b64decode(data)
            if not decoded:
                time.sleep(5)
            else:
                break
    else:
        data = ec2.get_password_data(instance_id)
        decoded = b64decode(data)

    if wait and datetime.datetime.now() >= end:
        module.fail_json(msg="wait for password timeout after %d seconds" %
                         wait_timeout)

    if key_file is not None and key_data is None:
        try:
            with open(key_file, 'rb') as f:
                key = load_pem_private_key(f.read(), b_key_passphrase,
                                           default_backend())
        except IOError as e:
            # Handle bad files
            module.fail_json(msg="I/O error (%d) opening key file: %s" %
                             (e.errno, e.strerror))
        except (ValueError, TypeError) as e:
            # Handle issues loading key
            module.fail_json(msg="unable to parse key file")
    elif key_data is not None and key_file is None:
        try:
            key = load_pem_private_key(key_data, b_key_passphrase,
                                       default_backend())
        except (ValueError, TypeError) as e:
            module.fail_json(msg="unable to parse key data")

    try:
        decrypted = key.decrypt(decoded, PKCS1v15())
    except ValueError as e:
        decrypted = None

    if decrypted is None:
        module.exit_json(win_password='', changed=False)
    else:
        if wait:
            elapsed = datetime.datetime.now() - start
            module.exit_json(win_password=decrypted,
                             changed=True,
                             elapsed=elapsed.seconds)
        else:
            module.exit_json(win_password=decrypted, changed=True)