From 5f4f84ea15b2654160c2d140a1b013eb36d1d618 Mon Sep 17 00:00:00 2001 From: Maxim Vershinin Date: Mon, 14 Sep 2026 14:39:55 +0400 Subject: [PATCH] feat(role): sets locale for alpine correctly --- .../tasks/set_locale_and_time.yaml | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/roles/base_system/tasks/set_locale_and_time.yaml b/roles/base_system/tasks/set_locale_and_time.yaml index 37eb4f6..786475a 100644 --- a/roles/base_system/tasks/set_locale_and_time.yaml +++ b/roles/base_system/tasks/set_locale_and_time.yaml @@ -1,19 +1,63 @@ --- -- name: Generate locales +- name: Generate locales for Debian-based systems community.general.locale_gen: name: - en_US.UTF-8 - ru_RU.UTF-8 state: present + when: (ansible_facts['distribution'] == "Debian") or + (ansible_facts['distribution'] == "Ubuntu") -- name: Set locale +- name: Set locale for Debian-based systems ansible.builtin.copy: dest: /etc/locale.conf mode: '0644' content: | LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 + when: (ansible_facts['distribution'] == "Debian") or + (ansible_facts['distribution'] == "Ubuntu") +# The same for Alpine +- name: Install musl-locales package for Alpine + community.general.apk: + name: musl-locales + state: present + when: ansible_facts['distribution'] == "Alpine" + +- name: Copy default locale profile to a custom override file for Alpine + ansible.builtin.copy: + src: /etc/profile.d/20locale.sh + dest: /etc/profile.d/locale.sh + remote_src: true + mode: '0644' + owner: root + group: root + force: false # Do not overwrite if the file already exists + when: ansible_facts['distribution'] == "Alpine" + +- name: Set LANG and LC_ALL in the custom locale file for Alpine + ansible.builtin.lineinfile: + path: /etc/profile.d/locale.sh + regexp: "{{ item.regexp }}" + line: "{{ item.line }}" + state: present + loop: + - { regexp: '^export LANG=', line: 'export LANG=en_US.UTF-8' } + - { regexp: '^export LC_ALL=', line: 'export LC_ALL=en_US.UTF-8' } + when: ansible_facts['distribution'] == "Alpine" + +- name: Ensure Unicode is enabled in /etc/rc.conf for Alpine + ansible.builtin.lineinfile: + path: /etc/rc.conf + regexp: '^#?unicode=' + line: 'unicode="YES"' + state: present + when: ansible_facts['distribution'] == "Alpine" + + +# Works fine for all - name: Set time community.general.timezone: name: Europe/Samara +