From 4171418e37d9eeab4fa0005528f8ee12008949de Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Thu, 20 Apr 2023 16:56:21 +1200 Subject: [PATCH] snap_alias: fix regex expression when listing aliases (#6361) * snap_alias: fix regex expression when listing aliases * simplify regex, add changelog --- changelogs/fragments/6361-snap-alias-regex-bugfix.yml | 2 ++ plugins/modules/snap_alias.py | 7 +++++-- tests/integration/targets/snap_alias/aliases | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/6361-snap-alias-regex-bugfix.yml diff --git a/changelogs/fragments/6361-snap-alias-regex-bugfix.yml b/changelogs/fragments/6361-snap-alias-regex-bugfix.yml new file mode 100644 index 0000000000..712ef1893d --- /dev/null +++ b/changelogs/fragments/6361-snap-alias-regex-bugfix.yml @@ -0,0 +1,2 @@ +bugfixes: + - snap_alias - module would only recognize snap names containing letter, numbers or the underscore character, failing to identify valid snap names such as ``lxd.lxc`` (https://github.com/ansible-collections/community.general/pull/6361). diff --git a/plugins/modules/snap_alias.py b/plugins/modules/snap_alias.py index 71869b6ee0..19fbef003f 100644 --- a/plugins/modules/snap_alias.py +++ b/plugins/modules/snap_alias.py @@ -98,7 +98,7 @@ _state_map = dict( class SnapAlias(StateModuleHelper): - _RE_ALIAS_LIST = re.compile(r"^(?P[\w-]+)\s+(?P[\w-]+)\s+.*$") + _RE_ALIAS_LIST = re.compile(r"^(?P\S+)\s+(?P[\w-]+)\s+.*$") module = dict( argument_spec={ @@ -142,7 +142,10 @@ class SnapAlias(StateModuleHelper): return results with self.runner("state name", check_rc=True, output_process=process) as ctx: - return ctx.run(state="info") + aliases = ctx.run(state="info") + if self.verbosity >= 4: + self.vars.get_aliases_run_info = ctx.run_info + return aliases def _get_aliases_for(self, name): return self._get_aliases().get(name, []) diff --git a/tests/integration/targets/snap_alias/aliases b/tests/integration/targets/snap_alias/aliases index a50e25cc5c..b209bbc015 100644 --- a/tests/integration/targets/snap_alias/aliases +++ b/tests/integration/targets/snap_alias/aliases @@ -11,4 +11,3 @@ skip/freebsd skip/osx skip/macos skip/docker -skip/ubuntu # FIXME!