Пример #1
0
def main():

    argument_spec = dict(
        lines=dict(aliases=['commands'], required=True, type='list'),

        before=dict(type='list'),
        after=dict(type='list'),

        match=dict(default='line', choices=['line', 'strict', 'exact']),
        replace=dict(default='line', choices=['line', 'block']),

        force=dict(default=False, type='bool'),
        config=dict()
    )

    argument_spec.update(asa_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    lines = module.params['lines']

    result = {'changed': False}

    candidate = NetworkConfig(indent=1)
    candidate.add(lines)

    acl_name = parse_acl_name(module)

    if not module.params['force']:
        contents = get_acl_config(module, acl_name)
        config = NetworkConfig(indent=1, contents=contents)

        commands = candidate.difference(config)
        commands = dumps(commands, 'commands').split('\n')
        commands = [str(c) for c in commands if c]
    else:
        commands = str(candidate).split('\n')

    if commands:
        if module.params['before']:
            commands[:0] = module.params['before']

        if module.params['after']:
            commands.extend(module.params['after'])

        if not module.check_mode:
            load_config(module, commands)

        result['changed'] = True

    result['updates'] = commands

    module.exit_json(**result)
Пример #2
0
def main():

    argument_spec = dict(
        lines=dict(aliases=['commands'], required=True, type='list'),

        before=dict(type='list'),
        after=dict(type='list'),

        match=dict(default='line', choices=['line', 'strict', 'exact']),
        replace=dict(default='line', choices=['line', 'block']),

        force=dict(default=False, type='bool'),
        config=dict()
    )

    argument_spec.update(asa_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    lines = module.params['lines']

    result = {'changed': False}

    candidate = NetworkConfig(indent=1)
    candidate.add(lines)

    acl_name = parse_acl_name(module)

    if not module.params['force']:
        contents = get_acl_config(module, acl_name)
        config = NetworkConfig(indent=1, contents=contents)

        commands = candidate.difference(config)
        commands = dumps(commands, 'commands').split('\n')
        commands = [str(c) for c in commands if c]
    else:
        commands = str(candidate).split('\n')

    if commands:
        if module.params['before']:
            commands[:0] = module.params['before']

        if module.params['after']:
            commands.extend(module.params['after'])

        if not module.check_mode:
            load_config(module, commands)

        result['changed'] = True

    result['updates'] = commands

    module.exit_json(**result)
Пример #3
0
def run(module, result):
    match = module.params['match']
    replace = module.params['replace']
    path = module.params['parents']

    candidate = get_candidate(module)
    if match != 'none':
        contents = module.params['config']
        if not contents:
            contents = get_config(module)
            config = NetworkConfig(indent=1, contents=contents)
            configobjs = candidate.difference(config,
                                              path=path,
                                              match=match,
                                              replace=replace)

    else:
        configobjs = candidate.items

    if configobjs:
        commands = dumps(configobjs, 'commands').split('\n')

        if module.params['lines']:
            if module.params['before']:
                commands[:0] = module.params['before']

            if module.params['after']:
                commands.extend(module.params['after'])

        result['updates'] = commands

        # send the configuration commands to the device and merge
        # them with the current running config
        if not module.check_mode:
            load_config(module, commands)
        result['changed'] = True

    if module.params['save']:
        if not module.check_mode:
            run_commands(module, 'write mem')
        result['changed'] = True
Пример #4
0
def run(module, result):
    match = module.params['match']
    replace = module.params['replace']
    path = module.params['parents']

    candidate = get_candidate(module)
    if match != 'none':
        contents = module.params['config']
        if not contents:
            contents = get_config(module)
            config = NetworkConfig(indent=1, contents=contents)
            configobjs = candidate.difference(config, path=path, match=match,
                                              replace=replace)

    else:
        configobjs = candidate.items

    if configobjs:
        commands = dumps(configobjs, 'commands').split('\n')

        if module.params['lines']:
            if module.params['before']:
                commands[:0] = module.params['before']

            if module.params['after']:
                commands.extend(module.params['after'])

        result['updates'] = commands

        # send the configuration commands to the device and merge
        # them with the current running config
        if not module.check_mode:
            load_config(module, commands)
        result['changed'] = True

    if module.params['save']:
        if not module.check_mode:
            run_commands(module, 'write mem')
        result['changed'] = True
Пример #5
0
def main():

    argument_spec = dict(
        name=dict(required=True),
        group_type=dict(choices=['network-object', 'service-object', 'port-object'], required=True),
        protocol=dict(choices=['udp', 'tcp', 'tcp-udp']),
        host_ip=dict(type='list'),
        description=dict(),
        group_object=dict(type='list'),
        ip_mask=dict(type='list'),
        port_range=dict(type='list'),
        port_eq=dict(type='list'),
        service_cfg=dict(type='list'),
        state=dict(choices=['present', 'absent', 'replace'], default='present')
    )

    required_if = [('group_type', 'port-object', ['protocol']),
                   ('group_type', 'service-object', ['service_cfg'])]

    module = AnsibleModule(argument_spec=argument_spec,
                           required_if=required_if,
                           supports_check_mode=True)

    result = {'changed': False}

    want = map_params_to_obj(module)
    have = map_config_to_obj(module)
    config_commans = map_obj_to_commands(want, have, module)

    result['commands'] = config_commans

    if config_commans:
        if not module.check_mode:
            load_config(module, config_commans)
        result['changed'] = True

    module.exit_json(**result)