Beispiel #1
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)
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)
def main():
    """ Main entry point for Ansible module execution
    """
    server_spec = dict(type=dict(choices=['radius', 'tacacs']),
                       hostname=dict(),
                       auth_port_type=dict(choices=['auth-port']),
                       auth_port_num=dict(),
                       acct_port_num=dict(),
                       acct_type=dict(choices=[
                           'accounting-only', 'authentication-only',
                           'authorization-only', 'default'
                       ]),
                       auth_key=dict(),
                       auth_key_type=dict(
                           type='list',
                           choices=['dot1x', 'mac-auth', 'web-auth']))
    argument_spec = dict(hostname=dict(),
                         domain_name=dict(type='list'),
                         domain_search=dict(type='list'),
                         name_servers=dict(type='list'),
                         aaa_servers=dict(type='list',
                                          elements='dict',
                                          options=server_spec),
                         state=dict(choices=['present', 'absent'],
                                    default='present'),
                         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)

    result = {'changed': False}

    warnings = list()

    result['warnings'] = warnings
    exec_command(module, 'skip')
    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)
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)
Beispiel #5
0
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)
def main():
    """ main entry point for module execution
    """
    power_spec = dict(by_class=dict(choices=['0', '1', '2', '3', '4']),
                      limit=dict(type='str'),
                      priority=dict(choices=['1', '2', '3']),
                      enabled=dict(type='bool'))
    neighbors_spec = dict(host=dict(), port=dict())
    element_spec = dict(
        name=dict(),
        description=dict(),
        enabled=dict(default=True, type='bool'),
        speed=dict(type='str',
                   choices=[
                       '10-full', '10-half', '100-full', '100-half',
                       '1000-full', '1000-full-master', '1000-full-slave',
                       '10g-full', '10g-full-master', '10g-full-slave',
                       '2500-full', '2500-full-master', '2500-full-slave',
                       '5g-full', '5g-full-master', '5g-full-slave', 'auto'
                   ]),
        stp=dict(type='bool'),
        tx_rate=dict(),
        rx_rate=dict(),
        neighbors=dict(type='list', elements='dict', options=neighbors_spec),
        delay=dict(default=10, type='int'),
        state=dict(default='present',
                   choices=['present', 'absent', 'up', 'down']),
        power=dict(type='dict', options=power_spec),
        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), )
    argument_spec.update(element_spec)

    required_one_of = [['name', 'aggregate']]
    mutually_exclusive = [['name', '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)
    have = map_config_to_obj(module)
    commands = map_obj_to_commands((want, have))
    result['commands'] = commands

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

    failed_conditions = check_declarative_intent_params(module, want, result)

    if failed_conditions:
        msg = 'One or more conditional statements have not been satisfied'
        module.fail_json(msg=msg, failed_conditions=failed_conditions)

    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)
Beispiel #8
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)