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
|
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.
|
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:
|
requirements:
|
||||||
- Ansible 2.9, ansible-base 2.10, or ansible-core 2.11 or newer
|
- Ansible 2.9, ansible-base 2.10, or ansible-core 2.11 or newer
|
||||||
options:
|
options:
|
||||||
|
@ -185,7 +189,7 @@ RETURN = """
|
||||||
import re
|
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.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):
|
class AnsibleGalaxyInstall(ModuleHelper):
|
||||||
|
@ -226,11 +230,17 @@ class AnsibleGalaxyInstall(ModuleHelper):
|
||||||
version=fmt.as_bool("--version"),
|
version=fmt.as_bool("--version"),
|
||||||
name=fmt.as_list(),
|
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):
|
def _get_ansible_galaxy_version(self):
|
||||||
|
class UnsupportedLocale(ModuleHelperException):
|
||||||
|
pass
|
||||||
|
|
||||||
def process(rc, out, err):
|
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]
|
line = out.splitlines()[0]
|
||||||
match = self._RE_GALAXY_VERSION.match(line)
|
match = self._RE_GALAXY_VERSION.match(line)
|
||||||
if not match:
|
if not match:
|
||||||
|
@ -239,12 +249,18 @@ class AnsibleGalaxyInstall(ModuleHelper):
|
||||||
version = tuple(int(x) for x in version.split('.')[:3])
|
version = tuple(int(x) for x in version.split('.')[:3])
|
||||||
return version
|
return version
|
||||||
|
|
||||||
with self.runner("version", check_rc=True, output_process=process) as ctx:
|
try:
|
||||||
return ctx.run(version=True)
|
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):
|
def __init_module__(self):
|
||||||
self.runner = CmdRunner(self.module, command=self.command, arg_formats=self.command_args_formats, force_lang=self.force_lang)
|
# 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, self.ansible_version = self._get_ansible_galaxy_version()
|
||||||
if self.ansible_version < (2, 11) and not self.vars.ack_min_ansiblecore211:
|
if self.ansible_version < (2, 11) and not self.vars.ack_min_ansiblecore211:
|
||||||
self.module.deprecate(
|
self.module.deprecate(
|
||||||
"Support for Ansible 2.9 and ansible-base 2.10 is being deprecated. "
|
"Support for Ansible 2.9 and ansible-base 2.10 is being deprecated. "
|
||||||
|
@ -339,11 +355,12 @@ class AnsibleGalaxyInstall(ModuleHelper):
|
||||||
self._setup210plus()
|
self._setup210plus()
|
||||||
with self.runner("type galaxy_cmd force no_deps dest requirements_file name", output_process=process) as ctx:
|
with self.runner("type galaxy_cmd force no_deps dest requirements_file name", output_process=process) as ctx:
|
||||||
ctx.run(galaxy_cmd="install")
|
ctx.run(galaxy_cmd="install")
|
||||||
|
if self.verbosity > 2:
|
||||||
|
self.vars.set("run_info", ctx.run_info)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
galaxy = AnsibleGalaxyInstall()
|
AnsibleGalaxyInstall.execute()
|
||||||
galaxy.run()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
name: netbox.netbox
|
name: netbox.netbox
|
||||||
register: install_c0
|
register: install_c0
|
||||||
|
|
||||||
- name: Assert collection was installed
|
- name: Assert collection netbox.netbox was installed
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- install_c0 is changed
|
- install_c0 is changed
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
name: ansistrano.deploy
|
name: ansistrano.deploy
|
||||||
register: install_r0
|
register: install_r0
|
||||||
|
|
||||||
- name: Assert collection was installed
|
- name: Assert collection ansistrano.deploy was installed
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- install_r0 is changed
|
- install_r0 is changed
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
- install_r1 is not changed
|
- install_r1 is not changed
|
||||||
|
|
||||||
###################################################
|
###################################################
|
||||||
- name:
|
- name: Set requirements file path
|
||||||
set_fact:
|
set_fact:
|
||||||
reqs_file: '{{ remote_tmp_dir }}/reqs.yaml'
|
reqs_file: '{{ remote_tmp_dir }}/reqs.yaml'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue