Skip to content

Configuring "locales" in Debian and Ubuntu, using Ansible

Missing locale settings will result in error messages like:

ads@ansible-ubuntu-03:~$ perl --version
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "en_US:en",
        LC_ALL = (unset),
        LC_PAPER = "de_DE.UTF-8",
        LC_ADDRESS = "de_DE.UTF-8",
        LC_MONETARY = "de_DE.UTF-8",
        LC_NUMERIC = "de_DE.UTF-8",
        LC_TELEPHONE = "de_DE.UTF-8",
        LC_IDENTIFICATION = "de_DE.UTF-8",
        LC_MEASUREMENT = "de_DE.UTF-8",
        LC_TIME = "de_DE.UTF-8",
        LC_NAME = "de_DE.UTF-8",
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").

This can be configured, but unfortunately the "locale" package does not use the debconf database. This makes it more complicated to configure the locales settings using Ansible.

 

The solution is to update the file /etc/locale.gen as well, and uncomment any locale you want to have on your system. First, for sake of completeness, let's update the debconf database:

    - name: locales
      command: "{{ item }}"
      with_items:
        - echo locales locales/locales_to_be_generated multiselect     de_DE ISO-8859-1, de_DE ISO-8859-15, de_DE.UTF-8 UTF-8, de_DE@euro ISO-8859-15, en_GB ISO-8859-1, en_GB ISO-8859-15, en_GB.ISO-8859-15 ISO-8859-15, en_GB.UTF-8 UTF-8, en_US ISO-8859-1, en_US ISO-8859-15, en_US.ISO-8859-15 ISO-8859-15, en_US.UTF-8 UTF-8 | debconf-set-selections
        - echo locales locales/default_environment_locale      select  en_US.UTF-8 | debconf-set-selections
        - dpkg-reconfigure locales -f noninteractive
        - touch /root/.locales-updated
      when: ansible_distribution == 'Ubuntu'
      args:
        creates: /root/.locales-updated


    - name: locales
      command: "{{ item }}"
      with_items:
        - echo locales locales/locales_to_be_generated multiselect     de_DE ISO-8859-1, de_DE.UTF-8 UTF-8, de_DE@euro ISO-8859-15, en_GB ISO-8859-1, en_GB.ISO-8859-15 ISO-8859-15, en_GB.UTF-8 UTF-8, en_US ISO-8859-1, en_US.ISO-8859-15 ISO-8859-15, en_US.UTF-8 UTF-8 | debconf-set-selections
        - echo locales locales/default_environment_locale      select  en_US.UTF-8 | debconf-set-selections
        - dpkg-reconfigure locales -f noninteractive
        - touch /root/.locales-updated
      when: ansible_distribution == 'Debian'
      args:
        creates: /root/.locales-updated

This task creates a new file /root/.locales-updated in order to mark this step as completed. Not sure how else this can accomplished here.

In a second step, update /etc/locale.gen and remove comments from all locale lines which are to build:

    - name: locales (for real)
      lineinfile:
        dest: /etc/locale.gen
        regexp: "{{ item.regexp }}"
        line: "{{ item.line }}"
        state: "{{ item.state }}"
      with_items:
        - { regexp: '^#? ?de_DE ISO-8859-1', line: 'de_DE ISO-8859-1', state: present }
        - { regexp: '^#? ?de_DE.UTF-8 UTF-8', line: 'de_DE.UTF-8 UTF-8', state: present }
        - { regexp: '^#? ?de_DE@euro ISO-8859-15', line: 'de_DE@euro ISO-8859-15', state: present }
        - { regexp: '^#? ?en_GB ISO-8859-1', line: 'en_GB ISO-8859-1', state: present }
        - { regexp: '^#? ?en_GB.ISO-8859-15 ISO-8859-15', line: 'en_GB.ISO-8859-15 ISO-8859-15', state: present }
        - { regexp: '^#? ?en_GB.UTF-8 UTF-8', line: 'en_GB.UTF-8 UTF-8', state: present }
        - { regexp: '^#? ?en_US ISO-8859-1', line: 'en_US ISO-8859-1', state: present }
        - { regexp: '^#? ?en_US.ISO-8859-15 ISO-8859-15', line: 'en_US.ISO-8859-15 ISO-8859-15', state: present }
        - { regexp: '^#? ?en_US.UTF-8 UTF-8', line: 'en_US.UTF-8 UTF-8', state: present }
      when: ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian'
      notify:
        - rebuild locales

Note that this task triggers "rebuild locales", if something is changed in the file. Here is the trigger code:

  handlers:
    - name: rebuild locales
      command: /usr/sbin/locale-gen

 

  • Twitter
  • Bookmark Configuring "locales" in Debian and Ubuntu, using Ansible at del.icio.us
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • Digg Configuring "locales" in Debian and Ubuntu, using Ansible
  • Bloglines Configuring "locales" in Debian and Ubuntu, using Ansible
  • Technorati Configuring "locales" in Debian and Ubuntu, using Ansible
  • Fark this: Configuring "locales" in Debian and Ubuntu, using Ansible
  • Bookmark Configuring "locales" in Debian and Ubuntu, using Ansible at YahooMyWeb
  • Bookmark Configuring "locales" in Debian and Ubuntu, using Ansible at Furl.net
  • Bookmark Configuring "locales" in Debian and Ubuntu, using Ansible at reddit.com
  • Bookmark Configuring "locales" in Debian and Ubuntu, using Ansible at blinklist.com
  • Bookmark Configuring "locales" in Debian and Ubuntu, using Ansible at Spurl.net
  • Bookmark Configuring "locales" in Debian and Ubuntu, using Ansible at Simpy.com
  • Bookmark Configuring "locales" in Debian and Ubuntu, using Ansible at blogmarks
  • Bookmark Configuring "locales" in Debian and Ubuntu, using Ansible with wists
  • wong it!
  • Bookmark using any bookmark manager!
  • Stumble It!
  • Identi.ca

Trackbacks

ads' corner on : Configuring "locales" in Debian and Ubuntu, using Ansible - Reloaded

Show preview
Last year I posted about how to configure "locales" in Debian or Ubuntu, using Ansible. Back then I did not know that there is an Ansible "debconf" module available, and I have no idea how I could miss it. Anyway, this makes things a bit easier, but not m Comments ()

Comments

Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.
Form options