From f0dc6fadb2d0b2f75eea39b3437e505aff59a59f Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Mon, 17 Jul 2023 09:01:55 -0500 Subject: [PATCH] Changes backup_file to be conditional --- .../plugins/tasks/dispatcher/default.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/nornir_nautobot/plugins/tasks/dispatcher/default.py b/nornir_nautobot/plugins/tasks/dispatcher/default.py index 46c2941..7d5cafb 100644 --- a/nornir_nautobot/plugins/tasks/dispatcher/default.py +++ b/nornir_nautobot/plugins/tasks/dispatcher/default.py @@ -76,10 +76,11 @@ def get_config( logger.log_debug("Substitute lines from configuration based on `substitute_lines` definition") running_config = sanitize_config(running_config, substitute_lines) - make_folder(os.path.dirname(backup_file)) + if backup_file: + make_folder(os.path.dirname(backup_file)) - with open(backup_file, "w", encoding="utf8") as filehandler: - filehandler.write(running_config) + with open(backup_file, "w", encoding="utf8") as filehandler: + filehandler.write(running_config) return Result(host=task.host, result={"config": running_config}) @staticmethod @@ -330,10 +331,11 @@ def get_config( logger.log_debug("Substitute lines from configuration based on `substitute_lines` definition") running_config = sanitize_config(running_config, substitute_lines) - make_folder(os.path.dirname(backup_file)) + if backup_file: + make_folder(os.path.dirname(backup_file)) - with open(backup_file, "w", encoding="utf8") as filehandler: - filehandler.write(running_config) + with open(backup_file, "w", encoding="utf8") as filehandler: + filehandler.write(running_config) return Result(host=task.host, result={"config": running_config}) @staticmethod