Writing Output to a File - Netmiko - Genie Parsers

I hope you guys would be willing to give me some pointers on a piece of code that I’ve been working with. I am trying to write the output of a Netmiko send command into a file using write_file. I have some working code but as soon as I use the Genie Parser then all I get is an empty file. Please be gentle as I am a complete novice and learning the ropes :slight_smile: I suspect what I am inferring on the write_file output is incorrect (i.e. content=) but I can’t figure it out. I’ve put the snippet below but I can post the full configuration if required. Thank you

def collect_config_ciscoxr(task):
config_dir = "configs"
entry_dir = config_dir + "/" + task.host.name
pathlib.Path(config_dir).mkdir(exist_ok=True)
pathlib.Path(entry_dir).mkdir(exist_ok=True)
output = task.run(task=netmiko_send_command, command_string="show interfaces", use_genie=True)
task.run(task=write_file, content=output.host['facts'],
    filename=f"" + str(entry_dir) + "/" + str(dt.datetime.today().strftime('%Y-%m-%d-%H%M%S')) + ".txt")

Hi,

I did manage to sort out my own issue. This now works as expected. I also needed to change the format to JSON to output properly. Anyway chuffed, I could solve my issue and hope this is of use to someone else.

def collect_config_ciscoxr(task):
config_dir = "configs"
entry_dir = config_dir + "/" + task.host.name
pathlib.Path(config_dir).mkdir(exist_ok=True)
pathlib.Path(entry_dir).mkdir(exist_ok=True)
output = task.run(task=netmiko_send_command, command_string="show interfaces", use_genie=True)
jdata=(json.dumps(output.result, indent=4, sort_keys=True))
print(jdata)


task.run(task=write_file, content=jdata, 
    filename=f"" + str(entry_dir) + "/" + str(dt.datetime.today().strftime('%Y-%m-%d-%H%M%S')) + ".txt")s