Skip to content

Commit

Permalink
Merge pull request #96 from joewesch/95_conditional-backup
Browse files Browse the repository at this point in the history
Changes backup_file to be conditional
  • Loading branch information
joewesch authored Aug 10, 2023
2 parents 666d67d + f0dc6fa commit 1378af5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions nornir_nautobot/plugins/tasks/dispatcher/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -333,10 +334,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
Expand Down

0 comments on commit 1378af5

Please sign in to comment.