patroni/tasks/locale.yaml

43 lines
2.1 KiB
YAML
Raw Normal View History

2023-03-29 20:49:37 +00:00
- name: Install glibc-all-langpacks for RedHat
dnf:
name: glibc-all-langpacks
state: present
when: ansible_facts['os_family'] == 'RedHat'
- name: Check if locale exists
shell: "locale -a | grep -i {{ patroni_postgresql_system_locale | regex_replace('-', '') | quote }}"
register: found_locale
changed_when: false
failed_when: false
- name: Create locale
command: "localedef -i {{ patroni_postgresql_system_locale | regex_replace('(.*)\\..*', '\\1') | quote }} -f {{ patroni_postgresql_system_locale | regex_replace('.*\\.(.*)', '\\1') | quote }} {{ patroni_postgresql_system_locale | quote }}"
when: not ansible_check_mode and found_locale.rc != 0
- name: Check if language exists
shell: "locale -a | grep -i {{ patroni_postgresql_system_language | regex_replace('-', '') | quote }}"
register: found_language
changed_when: false
failed_when: false
- name: Create language
command: "localedef -i {{ patroni_postgresql_system_language | regex_replace('(.*)\\..*', '\\1') | quote }} -f {{ patroni_postgresql_system_language | regex_replace('.*\\.(.*)', '\\1') | quote }} {{ patroni_postgresql_system_language | quote }}"
when: not ansible_check_mode and found_language.rc != 0
- name: Get current locale and language configuration
command: localectl status
register: locale_status
changed_when: false
- name: Parse 'LANG' from current locale and language configuration
set_fact:
locale_lang: "{{ locale_status.stdout | regex_search('LANG=([^\n]+)', '\\1') | first }}"
- name: Parse 'LANGUAGE' from current locale and language configuration
set_fact:
locale_language: "{{ locale_status.stdout | regex_search('LANGUAGE=([^\n]+)', '\\1') | default([locale_lang], true) | first }}"
- name: Configure locale to '{{ patroni_postgresql_system_locale }}' and language to '{{ patroni_postgresql_system_language }}'
command: localectl set-locale LANG={{ patroni_postgresql_system_locale }} LANGUAGE={{ patroni_postgresql_system_language }}
changed_when: locale_lang != patroni_postgresql_system_locale or locale_language != patroni_postgresql_system_language