Exemplo n.º 1
0
def main():
    argument_spec = dict(
        uid=dict(type='str', default=None),
        state=dict(type='str', default='published', choices=['published', 'discarded'])
    )

    module = AnsibleModule(argument_spec=argument_spec)
    connection = Connection(module._socket_path)
    code, response = get_session(module, connection)
    result = {'changed': False}

    if code == 200:
        result['changed'] = True
        payload = None

        if module.params['uid']:
            payload = {'uid': module.params['uid']}

        if module.params['state'] == 'published':
            code, response = connection.send_request('/web_api/publish', payload)
        else:
            code, response = connection.send_request('/web_api/discard', payload)
        if code != 200:
            module.fail_json(msg=response)
        result['checkpoint_session'] = response
    else:
        module.fail_json(msg='Check Point device returned error {0} with message {1}'.format(code, response))

    module.exit_json(**result)
Exemplo n.º 2
0
def main():
    argument_spec = dict(
        task_id=dict(type='str'),
    )

    module = AnsibleModule(argument_spec=argument_spec)
    connection = Connection(module._socket_path)
    code, response = get_task(module, connection)
    if code == 200:
        module.exit_json(ansible_facts=dict(checkpoint_tasks=response))
    else:
        module.fail_json(msg='Checkpoint device returned error {0} with message {1}'.format(code, response))
Exemplo n.º 3
0
def main():
    argument_spec = dict(
        uid=dict(type='str', default=None),
        name=dict(type='str', default=None)
    )

    module = AnsibleModule(argument_spec=argument_spec)
    connection = Connection(module._socket_path)

    code, response = get_access_layer(module, connection)

    if code == 200:
        module.exit_json(ansible_facts=dict(checkpoint_access_layers=response))
    else:
        module.fail_json(msg='Check Point device returned error {0} with message {1}'.format(code, response))
Exemplo n.º 4
0
def main():
    argument_spec = dict(script_name=dict(type='str', required=True),
                         script=dict(type='str', required=True),
                         targets=dict(type='list', required=True))

    module = AnsibleModule(argument_spec=argument_spec)
    connection = Connection(module._socket_path)
    code, response = run_script(module, connection)
    result = {'changed': True}

    if code == 200:
        result['checkpoint_run_script'] = response
    else:
        module.fail_json(
            msg='Checkpoint device returned error {0} with message {1}'.format(
                code, response))

    module.exit_json(**result)
Exemplo n.º 5
0
def main():
    argument_spec = dict(uid=dict(type='str', default=None),
                         object_filter=dict(type='str', default=None),
                         ip_only=dict(type='bool', default=False),
                         object_type=dict(type='str', default=None))

    module = AnsibleModule(argument_spec=argument_spec)
    connection = Connection(module._socket_path)

    code, response = get_object(module, connection)

    if code == 200:
        module.exit_json(ansible_facts=dict(
            jctanner.network_checkpoint.checkpoint_objects=response))
    else:
        module.fail_json(
            msg='Check Point device returned error {0} with message {1}'.
            format(code, response))
Exemplo n.º 6
0
def main():
    argument_spec = dict(name=dict(type='str', required=True),
                         ip_address=dict(type='str'),
                         state=dict(type='str', default='present'))
    argument_spec.update(checkpoint_argument_spec)

    required_if = [('state', 'present', 'ip_address')]
    module = AnsibleModule(argument_spec=argument_spec)
    connection = Connection(module._socket_path)
    code, response = get_host(module, connection)
    result = {'changed': False}

    if module.params['state'] == 'present':
        if code == 200:
            if needs_update(module, response):
                code, response = update_host(module, connection)
                if code != 200:
                    module.fail_json(msg=response)
                if module.params['auto_publish_session']:
                    publish(connection)

                    if module.params['auto_install_policy']:
                        install_policy(connection,
                                       module.params['policy_package'],
                                       module.params['targets'])

                result['changed'] = True
                result['checkpoint_hosts'] = response
            else:
                pass
        elif code == 404:
            code, response = create_host(module, connection)
            if code != 200:
                module.fail_json(msg=response)
            if module.params['auto_publish_session']:
                publish(connection)

                if module.params['auto_install_policy']:
                    install_policy(connection, module.params['policy_package'],
                                   module.params['targets'])

            result['changed'] = True
            result['checkpoint_hosts'] = response
    else:
        if code == 200:
            # Handle deletion
            code, response = delete_host(module, connection)
            if code != 200:
                module.fail_json(msg=response)
            if module.params['auto_publish_session']:
                publish(connection)

                if module.params['auto_install_policy']:
                    install_policy(connection, module.params['policy_package'],
                                   module.params['targets'])

            result['changed'] = True
            result['checkpoint_hosts'] = response
        elif code == 404:
            pass

    result['checkpoint_session_uid'] = connection.get_session_uid()
    module.exit_json(**result)
Exemplo n.º 7
0
def main():
    argument_spec = dict(name=dict(type='str', required=True),
                         layer=dict(type='str'),
                         position=dict(type='str'),
                         source=dict(type='str'),
                         destination=dict(type='str'),
                         action=dict(type='str', default='drop'),
                         enabled=dict(type='bool', default=True),
                         state=dict(type='str', default='present'))
    argument_spec.update(checkpoint_argument_spec)

    required_if = [('state', 'present', ('layer', 'position'))]
    module = AnsibleModule(argument_spec=argument_spec,
                           required_if=required_if)
    connection = Connection(module._socket_path)
    code, response = get_access_rule(module, connection)
    result = {'changed': False}

    if module.params['state'] == 'present':
        if code == 200:
            if needs_update(module, response):
                code, response = update_access_rule(module, connection)
                if code != 200:
                    module.fail_json(msg=response)
                if module.params['auto_publish_session']:
                    publish(connection)

                    if module.params['auto_install_policy']:
                        install_policy(connection,
                                       module.params['policy_package'],
                                       module.params['targets'])

                result['changed'] = True
                result['checkpoint_access_rules'] = response
            else:
                pass
        elif code == 404:
            code, response = create_access_rule(module, connection)
            if code != 200:
                module.fail_json(msg=response)
            if module.params['auto_publish_session']:
                publish(connection)

                if module.params['auto_install_policy']:
                    install_policy(connection, module.params['policy_package'],
                                   module.params['targets'])

            result['changed'] = True
            result['checkpoint_access_rules'] = response
    else:
        if code == 200:
            code, response = delete_access_rule(module, connection)
            if code != 200:
                module.fail_json(msg=response)
            if module.params['auto_publish_session']:
                publish(connection)

                if module.params['auto_install_policy']:
                    install_policy(connection, module.params['policy_package'],
                                   module.params['targets'])

            result['changed'] = True
            result['checkpoint_access_rules'] = response
        elif code == 404:
            pass

    result['checkpoint_session_uid'] = connection.get_session_uid()
    module.exit_json(**result)