# Buggy code
def doConfigBackUp(module, prompt, answer):
    host = module.params["host"]
    server = module.params["serverip"]
    username = module.params["serverusername"]
    password = module.params["serverpassword"]
    protocol = module.params["protocol"].lower()
    rcPath = module.params["rcpath"]
    configType = module.params["configType"]
    confPath = rcPath + host + "_" + configType + ".txt"

    retVal = ""

    # config backup command happens here
    command = "copy " + configType + " " + protocol + " " + protocol + "://"
    command = command + username + "@" + server + "/" + confPath
    command = command + " vrf management\n"
    cnos.debugOutput(command + "\n")
    # cnos.checkForFirstTimeAccess(module, command, 'yes/no', 'yes')
    cmd = []
    if protocol == "scp":
        scp_cmd1 = [{"command": command, "prompt": "timeout:", "answer": "0"}]
        scp_cmd2 = [{"command": "\n", "prompt": "Password:", "answer": password}]
        cmd.extend(scp_cmd1)
        cmd.extend(scp_cmd2)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    elif protocol == "sftp":
        sftp_cmd = [{"command": command, "prompt": "Password:", "answer": password}]
        cmd.extend(sftp_cmd)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    elif protocol == "ftp":
        ftp_cmd = [{"command": command, "prompt": "Password:", "answer": password}]
        cmd.extend(ftp_cmd)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    elif protocol == "tftp":
        command = "copy " + configType + " " + protocol + " " + protocol
        command = command + "://" + server + "/" + confPath
        command = command + +" vrf management\n"
        # cnos.debugOutput(command)
        tftp_cmd = [{"command": command, "prompt": None, "answer": None}]
        cmd.extend(tftp_cmd)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    else:
        return "Error-110"

    return retVal


# Traceback (RuntimeError)
Traceback (most recent call last):
File "/home/vagrant/.ansible/tmp/ansible-tmp-1548149534.5508606-278949110624512/AnsiballZ_apt_repository.py", line 113, in <module>
_ansiballz_main()
File "/home/vagrant/.ansible/tmp/ansible-tmp-1548149534.5508606-278949110624512/AnsiballZ_apt_repository.py", line 105, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/vagrant/.ansible/tmp/ansible-tmp-1548149534.5508606-278949110624512/AnsiballZ_apt_repository.py", line 48, in invoke_module
imp.load_module('__main__', mod, module, MOD_DESC)
File "/usr/lib/python3.7/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/usr/lib/python3.7/imp.py", line 169, in load_source
module = _exec(spec, sys.modules[name])
File "<frozen importlib._bootstrap>", line 630, in _exec
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/tmp/ansible_apt_repository_payload_fib2nr65/__main__.py", line 550, in <module>
File "/tmp/ansible_apt_repository_payload_fib2nr65/__main__.py", line 518, in main
File "/tmp/ansible_apt_repository_payload_fib2nr65/__main__.py", line 436, in add_source
File "/tmp/ansible_apt_repository_payload_fib2nr65/__main__.py", line 349, in _add_valid_source
RuntimeError: generator raised StopIteration

# Fixed code
def doConfigBackUp(module, prompt, answer):
    host = module.params["host"]
    server = module.params["serverip"]
    username = module.params["serverusername"]
    password = module.params["serverpassword"]
    protocol = module.params["protocol"].lower()
    rcPath = module.params["rcpath"]
    configType = module.params["configType"]
    confPath = rcPath + host + "_" + configType + ".txt"

    retVal = ""

    # config backup command happens here
    command = "copy " + configType + " " + protocol + " " + protocol + "://"
    command = command + username + "@" + server + "/" + confPath
    command = command + " vrf management\n"
    cnos.debugOutput(command + "\n")
    # cnos.checkForFirstTimeAccess(module, command, 'yes/no', 'yes')
    cmd = []
    if protocol == "scp":
        scp_cmd1 = [{"command": command, "prompt": "timeout:", "answer": "0"}]
        scp_cmd2 = [{"command": "\n", "prompt": "Password:", "answer": password}]
        cmd.extend(scp_cmd1)
        cmd.extend(scp_cmd2)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    elif protocol == "sftp":
        sftp_cmd = [{"command": command, "prompt": "Password:", "answer": password}]
        cmd.extend(sftp_cmd)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    elif protocol == "ftp":
        ftp_cmd = [{"command": command, "prompt": "Password:", "answer": password}]
        cmd.extend(ftp_cmd)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    elif protocol == "tftp":
        command = "copy " + configType + " " + protocol + " " + protocol
        command = command + "://" + server + "/" + confPath
        command = command + " vrf management\n"
        # cnos.debugOutput(command)
        tftp_cmd = [{"command": command, "prompt": None, "answer": None}]
        cmd.extend(tftp_cmd)
        retVal = retVal + str(cnos.run_cnos_commands(module, cmd))
    else:
        return "Error-110"

    return retVal