Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ Add support for passing in custom jinja2 environment #97

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nornir_nautobot/plugins/tasks/dispatcher/default.py
Original file line number Diff line number Diff line change
@@ -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.

@@ -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:
@@ -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