Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locale_gen: fix: use glibc_ubuntu mode only if files for that exists #9735

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "locale_gen - use ``glibc`` mode only if files for that exists. In other case use ``other_glibc`` mode (https://github.com/ansible-collections/community.general/pull/9735)."
10 changes: 9 additions & 1 deletion plugins/modules/locale_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
choices:
- glibc
- ubuntu_legacy
- other_glibc
returned: success
sample: glibc
version_added: 10.2.0
Expand Down Expand Up @@ -123,11 +124,18 @@ def __init_module__(self):
available=SUPPORTED_LOCALES,
apply_change=self.apply_change_glibc,
),
other_glibc=dict(
available=ETC_LOCALE_GEN,
apply_change=self.apply_change_glibc,
),
)

if os.path.exists(ETC_LOCALE_GEN):
if os.path.exists(ETC_LOCALE_GEN) and os.path.exists(SUPPORTED_LOCALES):
self.vars.ubuntu_mode = False
self.vars.mechanism = "glibc"
elif os.path.exists(ETC_LOCALE_GEN):
self.vars.ubuntu_mode = False
self.vars.mechanism = "other_glibc"
elif os.path.exists(VAR_LIB_LOCALES):
self.vars.ubuntu_mode = True
self.vars.mechanism = "ubuntu_legacy"
Expand Down
13 changes: 11 additions & 2 deletions tests/integration/targets/locale_gen/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@

- name: Bail out if not supported
ansible.builtin.meta: end_play
when: ansible_distribution not in ('Ubuntu', 'Debian')
when:
- "ansible_os_family not in ('Debian', 'Archlinux', 'RedHat')"

- name: Run tests auto-detecting mechanism
- name: Run tests auto-detecting mechanism [Debian]
ansible.builtin.include_tasks: basic.yml
loop: "{{ locale_list_basic }}"
loop_control:
loop_var: locale_basic
when:
- ansible_os_family == 'Debian'

- name: Run tests auto-detecting mechanism [Archlinux, RedHat]
ansible.builtin.include_tasks:
file: "non_debian.yml"
when:
- "ansible_os_family in ('RedHat', 'Archlinux')"
44 changes: 44 additions & 0 deletions tests/integration/targets/locale_gen/tasks/non_debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

- name: "Non dnf RedHat system are not supported"
ansible.builtin.meta: "end_play"
when:
- ansible_pkg_mgr == 'yum'

- name: "Install locale packages for RedHat"
ansible.builtin.dnf:
name:
- "glibc-langpack-pl"
- "glibc-langpack-en"
state: "present"
when:
- "ansible_os_family == 'RedHat'"

- name: "Prepare locale.gen file for RedHat"
ansible.builtin.template:
src: "locale_gen.j2"
dest: "/etc/locale.gen"
owner: "root"
group: "root"
mode: "0644"
force: true
when:
- "ansible_os_family == 'RedHat'"

- name: "Check for locale that pack are not installed"
locale_gen:
name: "ansible.UTF-8"
state: "present"
register: "locale_gen_locale_missed_result"
ignore_errors: true

- name: "Deploy locales"
locale_gen:
name: "{{ item['locale'] + '.' + item['charset'] }}"
state: "present"
loop: "{{ vars['locale_list_simple'] | flatten(levels=1) }}"
loop_control:
label: "{{ 'Deploy locale: ' + item['locale'] }}"
9 changes: 9 additions & 0 deletions tests/integration/targets/locale_gen/templates/locale_gen.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{#
Copyright (c) Ansible Project
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
SPDX-License-Identifier: GPL-3.0-or-later
#}

{% for l in vars['locale_list_simple'] %}
{{ l['locale'] + '.' + l['charset'] + ' ' + l['charset'] }}
{% endfor %}
8 changes: 8 additions & 0 deletions tests/integration/targets/locale_gen/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ locale_list_basic:
- localegen: de_CH.UTF-8
locales: [de_CH.utf8]
skip_removal: false

# Simple locales list for non Debian distro

locale_list_simple:
- locale: 'en_US'
charset: 'UTF-8'
- locale: 'pl_PL'
charset: 'UTF-8'
Loading