mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
[PR #9598/f27d5e7a backport][stable-10] snap: add RV version (#9606)
snap: add RV version (#9598)
* snap: add RV version
* add chglog frag
* fix typo
* fix docs
* add missing import
* fix sanity
* more fixes
* Update plugins/modules/snap.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/modules/snap_alias.py
Co-authored-by: Felix Fontein <felix@fontein.de>
---------
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit f27d5e7a42
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
ed472d8291
commit
45f7661249
5 changed files with 57 additions and 11 deletions
|
@ -41,8 +41,15 @@ def snap_runner(module, **kwargs):
|
|||
options=cmd_runner_fmt.as_list(),
|
||||
info=cmd_runner_fmt.as_fixed("info"),
|
||||
dangerous=cmd_runner_fmt.as_bool("--dangerous"),
|
||||
version=cmd_runner_fmt.as_fixed("version"),
|
||||
),
|
||||
check_rc=False,
|
||||
**kwargs
|
||||
)
|
||||
return runner
|
||||
|
||||
|
||||
def get_version(runner):
|
||||
with runner("version") as ctx:
|
||||
rc, out, err = ctx.run()
|
||||
return dict(x.split() for x in out.splitlines() if len(x.split()) == 2)
|
||||
|
|
|
@ -167,6 +167,11 @@ options_changed:
|
|||
type: list
|
||||
returned: When any options have been changed/set
|
||||
version_added: 4.4.0
|
||||
version:
|
||||
description: Versions of snap components as reported by C(snap version).
|
||||
type: dict
|
||||
returned: always
|
||||
version_added: 10.3.0
|
||||
"""
|
||||
|
||||
import re
|
||||
|
@ -176,7 +181,7 @@ import numbers
|
|||
from ansible.module_utils.common.text.converters import to_native
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
||||
from ansible_collections.community.general.plugins.module_utils.snap import snap_runner
|
||||
from ansible_collections.community.general.plugins.module_utils.snap import snap_runner, get_version
|
||||
|
||||
|
||||
class Snap(StateModuleHelper):
|
||||
|
@ -210,6 +215,7 @@ class Snap(StateModuleHelper):
|
|||
|
||||
def __init_module__(self):
|
||||
self.runner = snap_runner(self.module)
|
||||
self.vars.version = get_version(self.runner)
|
||||
# if state=present there might be file names passed in 'name', in
|
||||
# which case they must be converted to their actual snap names, which
|
||||
# is done using the names_from_snaps() method calling 'snap info'.
|
||||
|
|
|
@ -80,13 +80,18 @@ snap_aliases:
|
|||
type: list
|
||||
elements: str
|
||||
returned: always
|
||||
version:
|
||||
description: Versions of snap components as reported by C(snap version).
|
||||
type: dict
|
||||
returned: always
|
||||
version_added: 10.3.0
|
||||
"""
|
||||
|
||||
|
||||
import re
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.module_helper import StateModuleHelper
|
||||
from ansible_collections.community.general.plugins.module_utils.snap import snap_runner
|
||||
from ansible_collections.community.general.plugins.module_utils.snap import snap_runner, get_version
|
||||
|
||||
|
||||
class SnapAlias(StateModuleHelper):
|
||||
|
@ -112,6 +117,7 @@ class SnapAlias(StateModuleHelper):
|
|||
|
||||
def __init_module__(self):
|
||||
self.runner = snap_runner(self.module)
|
||||
self.vars.version = get_version(self.runner)
|
||||
self.vars.set("snap_aliases", self._aliases(), change=True, diff=True)
|
||||
|
||||
def __quit_module__(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue