mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ansible_galaxy_install: use locale C tentatively, else en_US (#5680)
* ansible_galaxy_install: use locale C tentatively, else en_US * use custom exception to signal unsupported locale * add step to remove artefacts at the end of the test * add step to remove artefacts at the beginning of the test * comment out context controller * trying with temporary dir as destination * remove collection before test with reqs file * ensure collections are installed in temp dir in tests + check_force * simplified the change * added extra condition for failing locale * improved exception handling * add changelog fragment
This commit is contained in:
parent
1f49241481
commit
488e828f9b
3 changed files with 32 additions and 12 deletions
|
@ -0,0 +1,3 @@
|
|||
bugfixes:
|
||||
- ansible_galaxy_install - try ``C.UTF-8`` and then fall back to ``en_US.UTF-8`` before failing (https://github.com/ansible-collections/community.general/pull/5680).
|
||||
- ansible_galaxy_install - set default to raise exception if command's return code is different from zero (https://github.com/ansible-collections/community.general/pull/5680).
|
|
@ -20,6 +20,10 @@ notes:
|
|||
- >
|
||||
B(Ansible 2.9/2.10): The C(ansible-galaxy) command changed significantly between Ansible 2.9 and
|
||||
ansible-base 2.10 (later ansible-core 2.11). See comments in the parameters.
|
||||
- >
|
||||
The module will try and run using the C(C.UTF-8) locale.
|
||||
If that fails, it will try C(en_US.UTF-8).
|
||||
If that one also fails, the module will fail.
|
||||
requirements:
|
||||
- Ansible 2.9, ansible-base 2.10, or ansible-core 2.11 or newer
|
||||
options:
|
||||
|
@ -185,7 +189,7 @@ RETURN = """
|
|||
import re
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt as fmt
|
||||
from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper
|
||||
from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper, ModuleHelperException
|
||||
|
||||
|
||||
class AnsibleGalaxyInstall(ModuleHelper):
|
||||
|
@ -226,11 +230,17 @@ class AnsibleGalaxyInstall(ModuleHelper):
|
|||
version=fmt.as_bool("--version"),
|
||||
name=fmt.as_list(),
|
||||
)
|
||||
force_lang = "en_US.UTF-8"
|
||||
check_rc = True
|
||||
|
||||
def _make_runner(self, lang):
|
||||
return CmdRunner(self.module, command=self.command, arg_formats=self.command_args_formats, force_lang=lang, check_rc=True)
|
||||
|
||||
def _get_ansible_galaxy_version(self):
|
||||
class UnsupportedLocale(ModuleHelperException):
|
||||
pass
|
||||
|
||||
def process(rc, out, err):
|
||||
if (rc != 0 and "unsupported locale setting" in err) or (rc == 0 and "cannot change locale" in err):
|
||||
raise UnsupportedLocale(msg=err)
|
||||
line = out.splitlines()[0]
|
||||
match = self._RE_GALAXY_VERSION.match(line)
|
||||
if not match:
|
||||
|
@ -239,12 +249,18 @@ class AnsibleGalaxyInstall(ModuleHelper):
|
|||
version = tuple(int(x) for x in version.split('.')[:3])
|
||||
return version
|
||||
|
||||
with self.runner("version", check_rc=True, output_process=process) as ctx:
|
||||
return ctx.run(version=True)
|
||||
try:
|
||||
runner = self._make_runner("C.UTF-8")
|
||||
with runner("version", check_rc=False, output_process=process) as ctx:
|
||||
return runner, ctx.run(version=True)
|
||||
except UnsupportedLocale as e:
|
||||
runner = self._make_runner("en_US.UTF-8")
|
||||
with runner("version", check_rc=True, output_process=process) as ctx:
|
||||
return runner, ctx.run(version=True)
|
||||
|
||||
def __init_module__(self):
|
||||
self.runner = CmdRunner(self.module, command=self.command, arg_formats=self.command_args_formats, force_lang=self.force_lang)
|
||||
self.ansible_version = self._get_ansible_galaxy_version()
|
||||
# self.runner = CmdRunner(self.module, command=self.command, arg_formats=self.command_args_formats, force_lang=self.force_lang)
|
||||
self.runner, self.ansible_version = self._get_ansible_galaxy_version()
|
||||
if self.ansible_version < (2, 11) and not self.vars.ack_min_ansiblecore211:
|
||||
self.module.deprecate(
|
||||
"Support for Ansible 2.9 and ansible-base 2.10 is being deprecated. "
|
||||
|
@ -339,11 +355,12 @@ class AnsibleGalaxyInstall(ModuleHelper):
|
|||
self._setup210plus()
|
||||
with self.runner("type galaxy_cmd force no_deps dest requirements_file name", output_process=process) as ctx:
|
||||
ctx.run(galaxy_cmd="install")
|
||||
if self.verbosity > 2:
|
||||
self.vars.set("run_info", ctx.run_info)
|
||||
|
||||
|
||||
def main():
|
||||
galaxy = AnsibleGalaxyInstall()
|
||||
galaxy.run()
|
||||
AnsibleGalaxyInstall.execute()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
name: netbox.netbox
|
||||
register: install_c0
|
||||
|
||||
- name: Assert collection was installed
|
||||
- name: Assert collection netbox.netbox was installed
|
||||
assert:
|
||||
that:
|
||||
- install_c0 is changed
|
||||
|
@ -34,7 +34,7 @@
|
|||
name: ansistrano.deploy
|
||||
register: install_r0
|
||||
|
||||
- name: Assert collection was installed
|
||||
- name: Assert collection ansistrano.deploy was installed
|
||||
assert:
|
||||
that:
|
||||
- install_r0 is changed
|
||||
|
@ -52,7 +52,7 @@
|
|||
- install_r1 is not changed
|
||||
|
||||
###################################################
|
||||
- name:
|
||||
- name: Set requirements file path
|
||||
set_fact:
|
||||
reqs_file: '{{ remote_tmp_dir }}/reqs.yaml'
|
||||
|
||||
|
|
Loading…
Reference in a new issue