skip to Main Content

I found the locale_gen module to make sure that locales are present on the system and tried it like described here:

- name: Install EN locale
  locale_gen:
    name: "de_DE.UTF-8"
    state: present

- name: Install DE locale
  locale_gen:
    name: "en_US.UTF-8"
    state: present

This throws an error:

/etc/locale.gen and /var/lib/locales/supported.d/local are missing. Is the package “locales” installed?

So I tried to install it:

- name: Install locales package
  become: yes
  yum:
    name: locales
    state: present

Both Ansible and manual install using sudo yum install locales doesn’t work. I also tried enabling the EPEL repo without success.

How can I make sure that the requestes languages are present on the target system?

2

Answers


  1. There is an open bug report since Aug 27 2018 for centos support. I suggest you vote for it so we get a chance it climbs up the priority list (or submit a PR if you have the required skills and enough time)

    Until this is fixed, you can probably apply the workarround proposed by @wojciech-kopras on april 2019 adapted below from your question (tested successfully against a docker centos:7 container):

    - name: Define needed locales (for example, can be set in vars or inventory)
      set_fact:
        system_settings_locales:
          - en_US.UTF-8
          - de_DE.UTF-8
    
    - name: Check existing locales
      shell: "locale -a | grep -i {{ item | regex_replace('-', '') | quote }}"
      register: found_locales
      changed_when: false
      failed_when: false
      loop: "{{ system_settings_locales }}"
    
    - name: Create missing locales
      command: "localedef -i {{ item.item | regex_replace('(.*)\..*', '\1') | quote }} -f {{ item.item | regex_replace('.*\.(.*)', '\1') | quote }} {{ item.item | quote }}"
      when: item.rc != 0
      loop: "{{ found_locales.results }}"
    
    Login or Signup to reply.
  2. Also, for some added context there’s no package named locales which is why original task for yum is failing. The package name containing locale data is glibc-common (at least on RHEL/CentOS 7, should be the same for 8). However, as noted by the first commenter, there appears to be a bug.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search