Example #1
0
def main():
    """ main entry point for module execution
    """
    interfaces_spec = dict(
        name=dict(type='list'),
        state=dict(choices=['present', 'absent', 'enabled', 'disabled']))

    argument_spec = dict(
        interfaces=dict(type='list', elements='dict', options=interfaces_spec),
        state=dict(choices=['present', 'absent', 'enabled', 'disabled']),
        check_running_config=dict(
            default=True,
            type='bool',
            fallback=(env_fallback, ['ANSIBLE_CHECK_ICX_RUNNING_CONFIG'])))

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

    warnings = list()

    result = {'changed': False}

    if warnings:
        result['warnings'] = warnings

    if module.params['check_running_config'] is False:
        HAS_LLDP = None
    else:
        HAS_LLDP = has_lldp(module)

    commands = []
    state = module.params['state']

    if state is None:
        if HAS_LLDP:
            map_obj_to_commands(module, commands)
        else:
            module.fail_json(msg='LLDP is not running')
    else:
        if state == 'absent' and HAS_LLDP is None:
            commands.append('no lldp run')

        if state == 'absent' and HAS_LLDP:
            commands.append('no lldp run')

        elif state == 'present':
            if not HAS_LLDP:
                commands.append('lldp run')
            if module.params.get('interfaces'):
                map_obj_to_commands(module, commands)

    result['commands'] = commands

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

        result['changed'] = True

    module.exit_json(**result)
Example #2
0
def main():
    """ main entry point for module execution
    """
    element_spec = dict(prefix=dict(type='str'),
                        mask=dict(type='str'),
                        next_hop=dict(type='str'),
                        admin_distance=dict(type='int'),
                        state=dict(default='present',
                                   choices=['present', 'absent']),
                        check_running_config=dict(
                            default=True,
                            type='bool',
                            fallback=(env_fallback,
                                      ['ANSIBLE_CHECK_ICX_RUNNING_CONFIG'])))

    aggregate_spec = deepcopy(element_spec)
    aggregate_spec['prefix'] = dict(required=True)

    remove_default_spec(aggregate_spec)

    argument_spec = dict(aggregate=dict(type='list',
                                        elements='dict',
                                        options=aggregate_spec),
                         purge=dict(default=False, type='bool'))

    argument_spec.update(element_spec)

    required_one_of = [['aggregate', 'prefix']]
    required_together = [['prefix', 'next_hop']]
    mutually_exclusive = [['aggregate', 'prefix']]

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

    if not HAS_IPADDRESS:
        module.fail_json(msg="ipaddress python package is required")

    warnings = list()

    result = {'changed': False}
    if warnings:
        result['warnings'] = warnings

    want = map_params_to_obj(module, required_together=required_together)
    have = map_config_to_obj(module)

    commands = map_obj_to_commands(want, have, module)
    result['commands'] = commands

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

        result['changed'] = True

    module.exit_json(**result)
Example #3
0
def main():
    """entry point for module execution
    """
    element_spec = dict(name=dict(),
                        configured_password=dict(no_log=True),
                        nopassword=dict(type='bool', default=False),
                        update_password=dict(default='always',
                                             choices=['on_create', 'always']),
                        privilege=dict(type='str', choices=['0', '4', '5']),
                        access_time=dict(type='str'),
                        state=dict(default='present',
                                   choices=['present', 'absent']),
                        check_running_config=dict(
                            default=True,
                            type='bool',
                            fallback=(env_fallback,
                                      ['ANSIBLE_CHECK_ICX_RUNNING_CONFIG'])))
    aggregate_spec = deepcopy(element_spec)
    aggregate_spec['name'] = dict(required=True)

    remove_default_spec(aggregate_spec)

    argument_spec = dict(aggregate=dict(type='list',
                                        elements='dict',
                                        options=aggregate_spec,
                                        aliases=['users', 'collection']),
                         purge=dict(type='bool', default=False))

    argument_spec.update(element_spec)

    mutually_exclusive = [('name', 'aggregate')]

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

    result = {'changed': False}
    exec_command(module, 'skip')
    want = map_params_to_obj(module)
    have = map_config_to_obj(module)
    commands = map_obj_to_commands(update_objects(want, have), module)

    if module.params['purge']:
        want_users = [x['name'] for x in want]
        have_users = [x['name'] for x in have]
        for item in set(have_users).difference(want_users):
            if item != 'admin':
                commands.append(user_del_cmd(item))

    result["commands"] = commands

    if commands:
        if not module.check_mode:
            load_config(module, commands)
        result['changed'] = True
    module.exit_json(**result)
Example #4
0
def main():
    element_spec = dict(group=dict(type='int'),
                        name=dict(type='str'),
                        mode=dict(choices=['dynamic', 'static']),
                        members=dict(type='list'),
                        state=dict(default='present',
                                   choices=['present', 'absent']),
                        check_running_config=dict(
                            default=True,
                            type='bool',
                            fallback=(env_fallback,
                                      ['ANSIBLE_CHECK_ICX_RUNNING_CONFIG'])))

    aggregate_spec = deepcopy(element_spec)
    aggregate_spec['group'] = dict(required=True, type='int')

    required_one_of = [['group', 'aggregate']]
    required_together = [['name', 'group']]
    mutually_exclusive = [['group', 'aggregate']]

    remove_default_spec(aggregate_spec)

    argument_spec = dict(aggregate=dict(type='list',
                                        elements='dict',
                                        options=aggregate_spec,
                                        required_together=required_together),
                         purge=dict(default=False, type='bool'))

    argument_spec.update(element_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           required_one_of=required_one_of,
                           required_together=required_together,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=True)

    warnings = list()
    result = {'changed': False}
    exec_command(module, 'skip')
    if warnings:
        result['warnings'] = warnings

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

    result["commands"] = commands

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

    module.exit_json(**result)
Example #5
0
def main():
    """entry point for module execution
    """
    argument_spec = dict(banner=dict(required=True,
                                     choices=['motd', 'exec', 'incoming']),
                         text=dict(),
                         enterkey=dict(type='bool'),
                         state=dict(default='present',
                                    choices=['present', 'absent']),
                         check_running_config=dict(
                             default=True,
                             type='bool',
                             fallback=(env_fallback,
                                       ['ANSIBLE_CHECK_ICX_RUNNING_CONFIG'])))

    required_one_of = [['text', 'enterkey', 'state']]
    module = AnsibleModule(argument_spec=argument_spec,
                           required_one_of=required_one_of,
                           supports_check_mode=True)

    warnings = list()
    results = {'changed': False}

    want = map_params_to_obj(module)
    have = map_config_to_obj(module)
    commands = map_obj_to_commands((want, have), module)
    results['commands'] = commands

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

        results['changed'] = True

    module.exit_json(**results)
def main():
    """ main entry point for module execution
    """
    element_spec = dict(
        name=dict(),
        ipv4=dict(),
        ipv6=dict(),
        replace=dict(choices=['yes', 'no']),
        mode=dict(choices=['dynamic', 'ospf-ignore', 'ospf-passive']),
        secondary=dict(choices=['yes', 'no']),
        check_running_config=dict(
            default=True,
            type='bool',
            fallback=(env_fallback, ['ANSIBLE_CHECK_ICX_RUNNING_CONFIG'])),
        state=dict(default='present', choices=['present', 'absent']),
    )

    aggregate_spec = deepcopy(element_spec)
    aggregate_spec['name'] = dict(required=True)

    remove_default_spec(aggregate_spec)

    argument_spec = dict(
        aggregate=dict(type='list', elements='dict', options=aggregate_spec))

    argument_spec.update(element_spec)

    required_one_of = [['name', 'aggregate']]
    mutually_exclusive = [['name', 'aggregate'], ['secondary', 'replace'],
                          ['secondary', 'mode']]
    module = AnsibleModule(argument_spec=argument_spec,
                           required_one_of=required_one_of,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=True)

    warnings = list()

    result = {'changed': False}
    exec_command(module, 'skip')
    want = map_params_to_obj(module)
    have = map_config_to_obj(module)
    commands = map_obj_to_commands((want, have), module)

    if commands:
        if not module.check_mode:
            resp = load_config(module, commands)
            warnings.extend((out for out in resp if out))

        result['changed'] = True

    if warnings:
        result['warnings'] = warnings

    result['commands'] = commands

    module.exit_json(**result)
Example #7
0
def main():
    """ main entry point for module execution
    """
    element_spec = dict(
        dest=dict(type='str',
                  choices=[
                      'on', 'host', 'console', 'buffered', 'persistence',
                      'rfc5424'
                  ]),
        name=dict(type='str'),
        udp_port=dict(),
        level=dict(type='list',
                   choices=[
                       'alerts', 'critical', 'debugging', 'emergencies',
                       'errors', 'informational', 'notifications', 'warnings'
                   ]),
        facility=dict(type='str',
                      choices=[
                          'auth', 'cron', 'daemon', 'kern', 'local0', 'local1',
                          'local2', 'local3', 'local4', 'local5', 'local6',
                          'local7', 'user', 'lpr', 'mail', 'news', 'syslog',
                          'sys9', 'sys10', 'sys11', 'sys12', 'sys13', 'sys14',
                          'user', 'uucp'
                      ]),
        state=dict(default='present', choices=['present', 'absent']),
        check_running_config=dict(
            default=True,
            type='bool',
            fallback=(env_fallback, ['ANSIBLE_CHECK_ICX_RUNNING_CONFIG'])))

    aggregate_spec = deepcopy(element_spec)

    remove_default_spec(aggregate_spec)

    argument_spec = dict(aggregate=dict(type='list',
                                        elements='dict',
                                        options=aggregate_spec), )

    argument_spec.update(element_spec)
    required_if = [('dest', 'host', ['name']), ('dest', 'buffered', ['level'])]
    module = AnsibleModule(argument_spec=argument_spec,
                           required_if=required_if,
                           supports_check_mode=True)

    result = {'changed': False}
    warnings = list()

    exec_command(module, 'skip')
    if warnings:
        result['warnings'] = warnings

    want = map_params_to_obj(module, required_if=required_if)
    have = map_config_to_obj(module)
    result['want'] = want
    result['have'] = have

    commands = map_obj_to_commands((want, have))
    result['commands'] = commands
    if commands:
        if not module.check_mode:
            load_config(module, commands)
        result['changed'] = True
    module.exit_json(**result)
def main():
    """ main entry point for module execution
    """
    stp_spec = dict(
        type=dict(default='802-1w', choices=['802-1w', 'rstp']),
        priority=dict(),
        enabled=dict(type='bool'),
    )
    inter_spec = dict(name=dict(type='list'), purge=dict(type='bool'))
    tagged_spec = dict(name=dict(type='list'), purge=dict(type='bool'))
    element_spec = dict(vlan_id=dict(type='int'),
                        name=dict(),
                        interfaces=dict(type='dict', options=inter_spec),
                        tagged=dict(type='dict', options=tagged_spec),
                        ip_dhcp_snooping=dict(type='bool'),
                        ip_arp_inspection=dict(type='bool'),
                        associated_interfaces=dict(type='list'),
                        associated_tagged=dict(type='list'),
                        delay=dict(default=10, type='int'),
                        stp=dict(type='dict', options=stp_spec),
                        state=dict(default='present',
                                   choices=['present', 'absent']),
                        check_running_config=dict(
                            default=True,
                            type='bool',
                            fallback=(env_fallback,
                                      ['ANSIBLE_CHECK_ICX_RUNNING_CONFIG'])))
    aggregate_spec = deepcopy(element_spec)
    aggregate_spec['vlan_id'] = dict(required=True)

    remove_default_spec(aggregate_spec)

    argument_spec = dict(aggregate=dict(type='list',
                                        elements='dict',
                                        options=aggregate_spec),
                         purge=dict(default=False, type='bool'))
    argument_spec.update(element_spec)
    required_one_of = [['vlan_id', 'aggregate']]
    mutually_exclusive = [['vlan_id', 'aggregate']]

    module = AnsibleModule(argument_spec=argument_spec,
                           required_one_of=required_one_of,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=True)
    warnings = list()
    result = {}
    result['changed'] = False
    if warnings:
        result['warnings'] = warnings
    exec_command(module, 'skip')
    want = map_params_to_obj(module)
    if module.params['check_running_config'] is False:
        have = []
    else:
        have = map_config_to_obj(module)
    commands = map_obj_to_commands((want, have), module)
    result['commands'] = commands

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

    check_declarative_intent_params(want, module, result)

    module.exit_json(**result)