postgresql/tasks/locale.yaml

51 lines
2.1 KiB
YAML
Raw Normal View History

2023-02-09 21:49:13 +00:00
- name: Install glibc-all-langpacks for RedHat
dnf:
name: glibc-all-langpacks
state: present
2023-11-22 10:16:10 +00:00
update_cache: true
2023-02-09 21:49:13 +00:00
when: ansible_facts['os_family'] == 'RedHat'
2023-10-03 10:59:37 +00:00
- name: Install locales-all for Debian
apt:
name: locales-all
state: present
2023-11-22 10:16:10 +00:00
update_cache: true
2023-10-03 10:59:37 +00:00
when: ansible_distribution_file_variety == 'Debian'
2023-02-09 21:49:13 +00:00
- name: Check if locale exists
shell: "locale -a | grep -i {{ postgresql_system_locale | regex_replace('-', '') | quote }}"
register: found_locale
changed_when: false
failed_when: false
- name: Create locale
command: "localedef -i {{ postgresql_system_locale | regex_replace('(.*)\\..*', '\\1') | quote }} -f {{ postgresql_system_locale | regex_replace('.*\\.(.*)', '\\1') | quote }} {{ postgresql_system_locale | quote }}"
when: not ansible_check_mode and found_locale.rc != 0
- name: Check if language exists
shell: "locale -a | grep -i {{ postgresql_system_language | regex_replace('-', '') | quote }}"
register: found_language
changed_when: false
failed_when: false
- name: Create language
command: "localedef -i {{ postgresql_system_language | regex_replace('(.*)\\..*', '\\1') | quote }} -f {{ postgresql_system_language | regex_replace('.*\\.(.*)', '\\1') | quote }} {{ 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 '{{ postgresql_system_locale }}' and language to '{{ postgresql_system_language }}'
command: localectl set-locale LANG={{ postgresql_system_locale }} LANGUAGE={{ postgresql_system_language }}
changed_when: locale_lang != postgresql_system_locale or locale_language != postgresql_system_language