Skip to content

Commit

Permalink
feat: ✨ Add support for passing in custom jinja2 environment
Browse files Browse the repository at this point in the history
  • Loading branch information
cablesquirrel committed Jul 17, 2023
1 parent 5f1236e commit b518b9e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nornir_nautobot/plugins/tasks/dispatcher/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def generate_config(
jinja_root_path: str,
output_file_location: str,
jinja_filters: Optional[dict] = None,
jinja_env: Optional[jinja2.Environment] = None,
) -> Result:
"""A small wrapper around template_file Nornir task.
Expand All @@ -172,6 +173,7 @@ def generate_config(
jinja_template (str): The file location of the actual Jinja template.
jinja_root_path (str): The file folder where the file will be saved to.
jinja_filters (dict): The filters which will be added to the jinja2 environment.
jinja_env (jinja2.Environment): The jinja2 environment to use. If not provided, nornir will create one.
output_file_location (str): The filename where the file will be saved to.
Returns:
Expand All @@ -184,6 +186,7 @@ def generate_config(
template=jinja_template,
path=jinja_root_path,
jinja_filters=jinja_filters,
jinja_env=jinja_env,
)[0].result
except NornirSubTaskError as exc:
if isinstance(exc.result.exception, jinja2.exceptions.UndefinedError): # pylint: disable=no-else-raise
Expand Down

0 comments on commit b518b9e

Please sign in to comment.