def main(): # # Define parameters for vlag creation entry # 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), vlagArg1=dict(required=True), vlagArg2=dict(required=False), vlagArg3=dict(required=False), vlagArg4=dict(required=False), ), supports_check_mode=False) outputfile = module.params['outputfile'] output = "" # Send the CLi command output = output + str(vlagConfig(module, '(config)#', None)) # Save it into the file file = open(outputfile, "a") file.write(output) file.close() # need to add logic to check when changes occur or not errorMsg = cnos.checkOutputForError(output) if (errorMsg is None): module.exit_json(changed=True, msg="VLAG configurations accomplished") else: module.fail_json(msg=errorMsg)
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), ), supports_check_mode=False) command = 'show running-config' outputfile = module.params['outputfile'] output = '' cmd = [{'command': command, 'prompt': None, 'answer': None}] output = output + str(cnos.run_cnos_commands(module, cmd)) # Save it into the file file = open(outputfile, "a") file.write(output) file.close() errorMsg = cnos.checkOutputForError(output) if (errorMsg is None): module.exit_json(changed=True, msg="Running Configuration saved in file ") else: module.fail_json(msg=errorMsg)
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), ), supports_check_mode=False) command = 'reload' outputfile = module.params['outputfile'] output = '' cmd = [{ 'command': command, 'prompt': 'reboot system? (y/n): ', 'answer': 'y' }] output = output + str(cnos.run_cnos_commands(module, cmd)) # Save it into the file file = open(outputfile, "a") file.write(output) file.close() errorMsg = cnos.checkOutputForError(output) if (errorMsg in "Device Response Timed out"): module.exit_json(changed=True, msg="Device is Reloading. Please wait...") else: module.fail_json(msg=errorMsg)
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),), supports_check_mode=False) command = 'write erase' outputfile = module.params['outputfile'] output = '' cmd = [{'command': command, 'prompt': '[n]', 'answer': 'y'}] output = output + str(cnos.run_cnos_commands(module, cmd)) # Save it into the file file = open(outputfile, "a") file.write(output) file.close() errorMsg = cnos.checkOutputForError(output) if(errorMsg is None): module.exit_json(changed=True, msg="Switch Startup Config is Reset to Factory settings") else: module.fail_json(msg=errorMsg)
def main(): module = AnsibleModule( argument_spec=dict( commandfile=dict(required=True), outputfile=dict(required=True), condition=dict(required=True), flag=dict(required=True), host=dict(required=False), deviceType=dict(required=True), username=dict(required=False), password=dict(required=False, no_log=True), enablePassword=dict(required=False, no_log=True),), supports_check_mode=False) condition = module.params['condition'] flag = module.params['flag'] commandfile = module.params['commandfile'] outputfile = module.params['outputfile'] output = '' if (condition is None or condition != flag): module.exit_json(changed=True, msg="Template Skipped for this switch") return " " # Send commands one by one f = open(commandfile, "r") cmd = [] for line in f: # Omit the comment lines in template file if not line.startswith("#"): # cnos.debugOutput(line) command = line.strip() inner_cmd = [{'command': command, 'prompt': None, 'answer': None}] cmd.extend(inner_cmd) # Write to memory save_cmd = [{'command': 'save', 'prompt': None, 'answer': None}] cmd.extend(save_cmd) output = output + str(cnos.run_cnos_commands(module, cmd)) # Write output to file path = outputfile.rsplit('/', 1) # cnos.debugOutput(path[0]) if not os.path.exists(path[0]): os.makedirs(path[0]) 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="Template Applied") else: module.fail_json(msg=errorMsg)
def main(): module = AnsibleModule(argument_spec=dict( clicommand=dict(required=True), outputfile=dict(required=True), condition=dict(required=True), flag=dict(required=True), host=dict(required=False), deviceType=dict(required=True), username=dict(required=False), password=dict(required=False, no_log=True), enablePassword=dict(required=False, no_log=True), ), supports_check_mode=False) condition = module.params['condition'] flag = module.params['flag'] cliCommand = module.params['clicommand'] outputfile = module.params['outputfile'] output = '' if (condition is None or condition != flag): module.exit_json(changed=True, msg="Command Skipped for this switch") return '' # Send the CLi command cmd = [{'command': cliCommand, 'prompt': None, 'answer': None}] output = output + str(cnos.run_cnos_commands(module, cmd)) # Write to memory save_cmd = [{'command': 'save', 'prompt': None, 'answer': None}] cmd.extend(save_cmd) output = output + str(cnos.run_cnos_commands(module, cmd)) # Save it into the file path = outputfile.rsplit('/', 1) # cnos.debugOutput(path[0]) if not os.path.exists(path[0]): os.makedirs(path[0]) 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="CLI Command executed and results saved in file ") else: module.fail_json(msg=errorMsg)
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), protocol=dict(required=True), serverip=dict(required=True), imgpath=dict(required=True), imgtype=dict(required=True), serverusername=dict(required=False), serverpassword=dict(required=False, no_log=True), ), supports_check_mode=False) outputfile = module.params['outputfile'] protocol = module.params['protocol'].lower() output = '' # Invoke method for image transfer from server if (protocol == "tftp" or protocol == "ftp" or protocol == "sftp" or protocol == "scp"): transfer_status = doImageDownload(module, None, None) else: transfer_status = "Invalid Protocol option" output = output + "\n Image Transfer status \n" + transfer_status # Save it into the file path = outputfile.rsplit('/', 1) if not os.path.exists(path[0]): os.makedirs(path[0]) 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="Image file transferred to device") else: module.fail_json(msg=errorMsg)
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), bgpArg1=dict(required=True), bgpArg2=dict(required=False), bgpArg3=dict(required=False), bgpArg4=dict(required=False), bgpArg5=dict(required=False), bgpArg6=dict(required=False), bgpArg7=dict(required=False), bgpArg8=dict(required=False), asNum=dict(required=True), ), supports_check_mode=False) asNum = module.params['asNum'] outputfile = module.params['outputfile'] deviceType = module.params['deviceType'] output = '' command = 'router bgp ' value = cnos.checkSanityofVariable(deviceType, "bgp_as_number", asNum) if (value == "ok"): # BGP command happens here. It creates if not present command = command + asNum cmd = [{'command': command, 'prompt': None, 'answer': None}] output = output + bgpConfig(module, cmd, '(config)#', None) else: output = "Error-176" # 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="BGP configurations accomplished") else: module.fail_json(msg=errorMsg)
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), configType=dict(required=True), protocol=dict(required=True), serverip=dict(required=True), rcpath=dict(required=True), serverusername=dict(required=False), serverpassword=dict(required=False, no_log=True), ), supports_check_mode=False) outputfile = module.params['outputfile'] protocol = module.params['protocol'].lower() output = '' if protocol in ('tftp', 'ftp', 'sftp', 'scp'): transfer_status = doConfigRollBack(module, None, None) else: transfer_status = 'Invalid Protocol option' output = output + "\n Config Transfer status \n" + transfer_status # Save it into the file if '/' in outputfile: path = outputfile.rsplit('/', 1) # cnos.debugOutput(path[0]) if not os.path.exists(path[0]): os.makedirs(path[0]) file = open(outputfile, "a") file.write(output) file.close() # need to add logic to check when changes occur or not errorMsg = cnos.checkOutputForError(output) if (errorMsg is None): module.exit_json(changed=True, msg="Config file transferred to Device") else: module.fail_json(msg=errorMsg)