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 <mark.vasi@embedit.com>
Co-authored-by: Ruchi Pakhle <ruchipakhle@gmail.com>
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>
pull/361/head^2
Mark0016 2024-07-25 18:37:08 +02:00 committed by GitHub
parent db14f96453
commit 8cba2c3b9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

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

View File

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