示例#1
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 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 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 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
        elif code == 404:
            pass

    result['checkpoint_session_uid'] = connection.get_session_uid()
    module.exit_json(**result)
示例#2
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 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 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 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
        elif code == 404:
            pass

    module.exit_json(**result)