def main():
    module = AnsibleModule(
        argument_spec=dict(
            host=dict(required=True),
            version=dict(required=True, choices=['2c', '3']),
            community=dict(required=False, default=False),
            username=dict(required=False),
            level=dict(required=False, choices=['authNoPriv', 'authPriv']),
            integrity=dict(required=False, choices=['md5', 'sha']),
            privacy=dict(required=False, choices=['des', '3des', 'aes', 'aes192', 'aes256']),
            authkey=dict(required=False),
            privkey=dict(required=False),
            mode=dict(required=True, choices=['access', 'trunk', 'desireable', 'auto', 'trunk-nonegotiate']),
            interface_id=dict(required=False),
            interface_name=dict(required=False),
            access_vlan=dict(required=False),
            native_vlan=dict(required=False),
            removeplaceholder=dict(required=False),
        ),
        mutually_exclusive=(['interface_id', 'interface_name'],),
        required_one_of=(['interface_id', 'interface_name'],),
        required_together=(
            ['username','level','integrity','authkey'],['privacy','privkey'],
        ),
        supports_check_mode=False)

    m_args = module.params

    if not has_nelsnmp:
        module.fail_json(msg='Missing required nelsnmp module (check docs)')

    # Verify that we receive a community when using snmp v2
    if m_args['version'] == "2c":
        if m_args['community'] == False:
            module.fail_json(msg='Community not set when using snmp version 2')

    if m_args['version'] == "3":
        if m_args['username'] == None:
            module.fail_json(msg='Username not set when using snmp version 3')

        if m_args['level'] == "authPriv" and m_args['privacy'] == None:
            module.fail_json(msg='Privacy algorithm not set when using authPriv')

    nelsnmp_args = {}
    for key in m_args:
        if key in NELSNMP_PARAMETERS and m_args[key] != None:
            nelsnmp_args[key] = m_args[key]

    try:
        dev = SnmpHandler(**nelsnmp_args)
    except Exception, err:
        module.fail_json(msg=str(err))

    #return_status = { 'changed': False }
    has_changed = False

    if m_args['interface_name']:
        # Do this through cache in the future
        try:
            interface = False
            vartable = dev.getnext(o.ifDescr)

            for varbinds in vartable:
                for oid, val in varbinds:
                    if m_args['interface_name'] == val:
                        interface = oid.rsplit('.', 1)[-1]

            if interface == False:
                module.fail_json(msg='Unable to find interface')
        except Exception, err:
            module.fail_json(msg=str(err))

    # Check how to get the interface value
    if m_args['interface_id']:
        interface = m_args['interface_id']

    if m_args['mode']:
        oid = o.vlanTrunkPortDynamicState + "." + str(interface)
        desired_state = PORT_MODE[m_args['mode']]
        changed = set_state(dev, oid, desired_state, module)
        has_changed = changed_status(changed, has_changed)

    if m_args['access_vlan']:
        oid = o.vmVlan + "." + str(interface)
        desired_state = int(m_args['access_vlan'])
        changed = set_state(dev, oid, desired_state, module)
        has_changed = changed_status(changed, has_changed)

    if m_args['native_vlan']:
        oid = o.vlanTrunkPortNativeVlan + "." + str(interface)
        desired_state = int(m_args['native_vlan'])
        changed = set_state(dev, oid, desired_state, module)
        has_changed = changed_status(changed, has_changed)

    return_status = { 'changed': has_changed }

    module.exit_json(**return_status)
dataset/ETHPy150Open networklore/ansible-cisco-snmp/library/cisco_snmp_switchport.py/main/original