cpanm: add return value cpanm_version (#9061)

* add return value version

* add changelog frag

* fix indentation

* fix RV name and tests

* Update plugins/modules/cpanm.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky 2024-11-03 05:49:41 +13:00 committed by GitHub
parent 9553dd9ddf
commit 8a2ac4f1eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 147 additions and 4 deletions

View file

@ -142,7 +142,19 @@ EXAMPLES = """
version: '1.0'
"""
RETURN = """
---
cpanm_version:
description: Version of CPANMinus.
type: str
returned: always
sample: "1.7047"
version_added: 10.0.0
"""
import os
import re
from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt
from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper
@ -175,6 +187,7 @@ class CPANMinus(ModuleHelper):
mirror_only=cmd_runner_fmt.as_bool("--mirror-only"),
installdeps=cmd_runner_fmt.as_bool("--installdeps"),
pkg_spec=cmd_runner_fmt.as_list(),
cpanm_version=cmd_runner_fmt.as_fixed("--version"),
)
use_old_vardict = False
@ -191,6 +204,14 @@ class CPANMinus(ModuleHelper):
self.runner = CmdRunner(self.module, self.command, self.command_args_formats, check_rc=True)
self.vars.binary = self.runner.binary
with self.runner("cpanm_version") as ctx:
rc, out, err = ctx.run()
line = out.split('\n')[0]
match = re.search(r"version\s+([\d\.]+)\s+", line)
if not match:
self.do_raise("Failed to determine version number. First line of output: {0}".format(line))
self.vars.cpanm_version = match.group(1)
def _is_package_installed(self, name, locallib, version):
def process(rc, out, err):
return rc == 0