From 8cba2c3b9edf653170fd523adbe99e02707f9ecf Mon Sep 17 00:00:00 2001 From: Mark0016 Date: Thu, 25 Jul 2024 18:37:08 +0200 Subject: [PATCH] cli_parse: Fix finding relative template_path when used inside role/collection (#333) * Fix finding relative template_path when provided This allows parser.template_path to behave as expected inside roles or collections when a path relative to the role/collection directory is provided. * add tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update tests * add working tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * updates * minor changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Delete tests/integration/inventory * add tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add netcommon dependency * changes * delete tests as CI is failing * changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Mark Vasi Co-authored-by: Ruchi Pakhle Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ruchi Pakhle <72685035+Ruchip16@users.noreply.github.com> --- changelogs/fragments/add_template_path.yaml | 3 +++ plugins/action/cli_parse.py | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/add_template_path.yaml diff --git a/changelogs/fragments/add_template_path.yaml b/changelogs/fragments/add_template_path.yaml new file mode 100644 index 0000000..c408d40 --- /dev/null +++ b/changelogs/fragments/add_template_path.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - Allows the cli_parse module to find parser.template_path inside roles or collections when a path relative to the role/collection directory is provided. diff --git a/plugins/action/cli_parse.py b/plugins/action/cli_parse.py index 68a02b6..97f94b9 100644 --- a/plugins/action/cli_parse.py +++ b/plugins/action/cli_parse.py @@ -165,8 +165,11 @@ class ActionModule(ActionBase): cmd_as_fname = self._task.args.get("parser").get("command").replace(" ", "_") fname = "{os}_{cmd}.{ext}".format(os=oper_sys, cmd=cmd_as_fname, ext=template_extension) source = self._find_needle("templates", fname) - self._debug("template_path in task args updated to {source}".format(source=source)) - self._task.args["parser"]["template_path"] = source + else: + source = self._task.args.get("parser").get("template_path") + source = self._find_needle("templates", source) + self._debug("template_path in task args updated to {source}".format(source=source)) + self._task.args["parser"]["template_path"] = source def _get_template_contents(self): """Retrieve the contents of the parser template