Exemplo n.º 1
0
def main():
    module = AnsibleModule(argument_spec=dict(
        outputfile=dict(required=True),
        host=dict(required=False),
        username=dict(required=False),
        password=dict(required=False, no_log=True),
        enablePassword=dict(required=False, no_log=True),
        deviceType=dict(required=True),
        interfaceRange=dict(required=False),
        interfaceOption=dict(required=False),
        interfaceArg1=dict(required=True),
        interfaceArg2=dict(required=False),
        interfaceArg3=dict(required=False),
        interfaceArg4=dict(required=False),
        interfaceArg5=dict(required=False),
        interfaceArg6=dict(required=False),
        interfaceArg7=dict(required=False),
    ),
                           supports_check_mode=False)

    interfaceOption = module.params['interfaceOption']
    outputfile = module.params['outputfile']

    output = ''
    # Send the CLi command
    if (interfaceOption is None or interfaceOption == ""):
        output = output + cnos.interfaceConfig(module, "(config)#", None, None)
    elif (interfaceOption == "ethernet"):
        output = output + cnos.interfaceConfig(module, "(config)#", "ethernet",
                                               None)
    elif (interfaceOption == "loopback"):
        output = output + cnos.interfaceConfig(module, "(config)#", "loopback",
                                               None)
    elif (interfaceOption == "mgmt"):
        output = output + cnos.interfaceConfig(module, "(config)#", "mgmt",
                                               None)
    elif (interfaceOption == "port-channel"):
        output = output + cnos.interfaceConfig(module, "(config)#",
                                               "port-channel", None)
    elif (interfaceOption == "vlan"):
        output = output + cnos.interfaceConfig(module, "(config)#", "vlan",
                                               None)
    else:
        output = "Invalid interface option \n"
    # Save it into the file
    file = open(outputfile, "a")
    file.write(output)
    file.close()

    # Logic to check when changes occur or not
    errorMsg = cnos.checkOutputForError(output)
    if (errorMsg is None):
        module.exit_json(changed=True,
                         msg="Interface Configuration is Accomplished")
    else:
        module.fail_json(msg=errorMsg)
Exemplo n.º 2
0
def main():
    module = AnsibleModule(argument_spec=dict(
        outputfile=dict(required=True),
        host=dict(required=True),
        username=dict(required=True),
        password=dict(required=True, no_log=True),
        enablePassword=dict(required=False, no_log=True),
        deviceType=dict(required=True),
        interfaceRange=dict(required=False),
        interfaceArg1=dict(required=True),
        interfaceArg2=dict(required=False),
        interfaceArg3=dict(required=False),
        interfaceArg4=dict(required=False),
        interfaceArg5=dict(required=False),
        interfaceArg6=dict(required=False),
        interfaceArg7=dict(required=False),
    ),
                           supports_check_mode=False)

    outputfile = module.params['outputfile']
    output = ''
    # Send the CLi command
    if (module.params['interfaceArg1'] == "port-channel"):
        output = output + cnos.portChannelConfig(module, "(config)#", None)
    else:
        output = output + cnos.interfaceConfig(module, "(config)#",
                                               "port-channel", None)

    # Save it into the file
    file = open(outputfile, "a")
    file.write(output)
    file.close()

    # Logic to check when changes occur or not
    errorMsg = cnos.checkOutputForError(output)
    if (errorMsg is None):
        module.exit_json(changed=True,
                         msg="Port Channel Configuration is done")
    else:
        module.fail_json(msg=errorMsg)
Exemplo n.º 3
0
def main():
    module = AnsibleModule(argument_spec=dict(
        outputfile=dict(required=True),
        host=dict(required=True),
        username=dict(required=True),
        password=dict(required=True, no_log=True),
        enablePassword=dict(required=False, no_log=True),
        deviceType=dict(required=True),
        interfaceRange=dict(required=False),
        interfaceOption=dict(required=False),
        interfaceArg1=dict(required=True),
        interfaceArg2=dict(required=False),
        interfaceArg3=dict(required=False),
        interfaceArg4=dict(required=False),
        interfaceArg5=dict(required=False),
        interfaceArg6=dict(required=False),
        interfaceArg7=dict(required=False),
    ),
                           supports_check_mode=False)

    username = module.params['username']
    password = module.params['password']
    enablePassword = module.params['enablePassword']
    interfaceRange = module.params['interfaceRange']
    interfaceOption = module.params['interfaceOption']
    interfaceArg1 = module.params['interfaceArg1']
    interfaceArg2 = module.params['interfaceArg2']
    interfaceArg3 = module.params['interfaceArg3']
    interfaceArg4 = module.params['interfaceArg4']
    interfaceArg5 = module.params['interfaceArg5']
    interfaceArg6 = module.params['interfaceArg6']
    interfaceArg7 = module.params['interfaceArg7']
    outputfile = module.params['outputfile']
    hostIP = module.params['host']
    deviceType = module.params['deviceType']

    output = ""
    if not HAS_PARAMIKO:
        module.fail_json(msg='paramiko is required for this module')

    # Create instance of SSHClient object
    remote_conn_pre = paramiko.SSHClient()

    # Automatically add untrusted hosts (make sure okay for security policy in your environment)
    remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    # initiate SSH connection with the switch
    remote_conn_pre.connect(hostIP, username=username, password=password)
    time.sleep(2)

    # Use invoke_shell to establish an 'interactive session'
    remote_conn = remote_conn_pre.invoke_shell()
    time.sleep(2)

    # Enable and enter configure terminal then send command
    output = output + cnos.waitForDeviceResponse("\n", ">", 2, remote_conn)

    output = output + cnos.enterEnableModeForDevice(enablePassword, 3,
                                                    remote_conn)

    # Make terminal length = 0
    output = output + cnos.waitForDeviceResponse("terminal length 0\n", "#", 2,
                                                 remote_conn)

    # Go to config mode
    output = output + cnos.waitForDeviceResponse("configure d\n", "(config)#",
                                                 2, remote_conn)

    # Send the CLi command
    if (interfaceOption is None or interfaceOption == ""):
        output = output + cnos.interfaceConfig(
            remote_conn, deviceType, "(config)#", 2, None, interfaceRange,
            interfaceArg1, interfaceArg2, interfaceArg3, interfaceArg4,
            interfaceArg5, interfaceArg6, interfaceArg7)
    elif (interfaceOption == "ethernet"):
        output = output + cnos.interfaceConfig(
            remote_conn, deviceType, "(config)#", 2, "ethernet",
            interfaceRange, interfaceArg1, interfaceArg2, interfaceArg3,
            interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)
    elif (interfaceOption == "loopback"):
        output = output + cnos.interfaceConfig(
            remote_conn, deviceType, "(config)#", 2, "loopback",
            interfaceRange, interfaceArg1, interfaceArg2, interfaceArg3,
            interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)
    elif (interfaceOption == "mgmt"):
        output = output + cnos.interfaceConfig(
            remote_conn, deviceType, "(config)#", 2, "mgmt", interfaceRange,
            interfaceArg1, interfaceArg2, interfaceArg3, interfaceArg4,
            interfaceArg5, interfaceArg6, interfaceArg7)
    elif (interfaceOption == "port-aggregation"):
        output = output + cnos.interfaceConfig(
            remote_conn, deviceType, "(config)#", 2, "port-aggregation",
            interfaceRange, interfaceArg1, interfaceArg2, interfaceArg3,
            interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)
    elif (interfaceOption == "vlan"):
        output = output + cnos.interfaceConfig(
            remote_conn, deviceType, "(config)#", 2, "vlan", interfaceRange,
            interfaceArg1, interfaceArg2, interfaceArg3, interfaceArg4,
            interfaceArg5, interfaceArg6, interfaceArg7)
    else:
        output = "Invalid interface option \n"
    # Save it into the file
    file = open(outputfile, "a")
    file.write(output)
    file.close()

    # Logic to check when changes occur or not
    errorMsg = cnos.checkOutputForError(output)
    if (errorMsg is None):
        module.exit_json(changed=True, msg="Interface Configuration is done")
    else:
        module.fail_json(msg=errorMsg)
Exemplo n.º 4
0
def main():
    module = AnsibleModule(
        argument_spec=dict(
            outputfile=dict(required=True),
            host=dict(required=True),
            username=dict(required=True),
            password=dict(required=True, no_log=True),
            enablePassword=dict(required=False, no_log=True),
            deviceType=dict(required=True),
            interfaceRange=dict(required=False),
            interfaceArg1=dict(required=True),
            interfaceArg2=dict(required=False),
            interfaceArg3=dict(required=False),
            interfaceArg4=dict(required=False),
            interfaceArg5=dict(required=False),
            interfaceArg6=dict(required=False),
            interfaceArg7=dict(required=False),),
        supports_check_mode=False)

    username = module.params['username']
    password = module.params['password']
    enablePassword = module.params['enablePassword']
    interfaceRange = module.params['interfaceRange']
    interfaceArg1 = module.params['interfaceArg1']
    interfaceArg2 = module.params['interfaceArg2']
    interfaceArg3 = module.params['interfaceArg3']
    interfaceArg4 = module.params['interfaceArg4']
    interfaceArg5 = module.params['interfaceArg5']
    interfaceArg6 = module.params['interfaceArg6']
    interfaceArg7 = module.params['interfaceArg7']
    outputfile = module.params['outputfile']
    hostIP = module.params['host']
    deviceType = module.params['deviceType']
    output = ""
    if not HAS_PARAMIKO:
        module.fail_json(msg='paramiko is required for this module')

    # Create instance of SSHClient object
    remote_conn_pre = paramiko.SSHClient()

    # Automatically add untrusted hosts (make sure okay for security policy in your environment)
    remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    # initiate SSH connection with the switch
    remote_conn_pre.connect(hostIP, username=username, password=password)
    time.sleep(2)

    # Use invoke_shell to establish an 'interactive session'
    remote_conn = remote_conn_pre.invoke_shell()
    time.sleep(2)

    # Enable and enter configure terminal then send command
    output = output + cnos.waitForDeviceResponse("\n", ">", 2, remote_conn)

    output = output + cnos.enterEnableModeForDevice(enablePassword, 3, remote_conn)

    # Make terminal length = 0
    output = output + cnos.waitForDeviceResponse("terminal length 0\n", "#", 2, remote_conn)

    # Go to config mode
    output = output + cnos.waitForDeviceResponse("configure d\n", "(config)#", 2, remote_conn)

    # Send the CLi command
    if(interfaceArg1 == "port-aggregation"):
        output = output + cnos.portChannelConfig(remote_conn, deviceType, "(config)#", 2, interfaceArg1,
                                                 interfaceArg2, interfaceArg3, interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)
    else:
        output = output + cnos.interfaceConfig(remote_conn, deviceType, "(config)#", 2, "port-aggregation", interfaceRange,
                                               interfaceArg1, interfaceArg2, interfaceArg3, interfaceArg4, interfaceArg5, interfaceArg6, interfaceArg7)

    # Save it into the file
    file = open(outputfile, "a")
    file.write(output)
    file.close()

    # Logic to check when changes occur or not
    errorMsg = cnos.checkOutputForError(output)
    if(errorMsg is None):
        module.exit_json(changed=True, msg="Port Aggregation configuration is done")
    else:
        module.fail_json(msg=errorMsg)