Skip to content

Configuring "locales" in Debian and Ubuntu, using Ansible - Reloaded

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 much.

First of all, the module let's you both set and query values. However because the "locales" package does not use debconf for the list of locales, but stores this list in /etc/locale.gen, things are still unnecessary complicated. But I managed to get it working without having to use an additional file as flag if this step was completed before.

 

The initial situation is still the following problem:

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").

 

But this time the first part of the configuration is done using the "debconf" module:

- name: select default locale
  debconf:
    name: locales
    question: locales/default_environment_locale
    value: en_US.UTF-8
    vtype: select
  notify:
    - rebuild locales database

This task selects the default locale for the system. Next step is selecting all the locales in /etc/locale.gen:

- name: /etc/locale.gen
  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 }
  notify:
    - rebuild locales database

Most entries - if not all - should be already in the file, but commented out. This task will remove the comment in front of the selected entry, or add a new line if the line is not in the file. It is possible to add additional locales, Ansible will not touch them. All it does it make sure that the selected locales are build.

Both tasks notify a trigger if they change something on the system:

- name: rebuild locales database
  command: "{{ item }}"
  with_items:
    - dpkg-reconfigure locales -f noninteractive
    - /usr/sbin/locale-gen

The trigger will in turn also update the debconf database.

 

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

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

Niconil on :

maybe just use item with_items : - 'de_DE ISO8859-1' and so on ... and use the following parameter to lineinfile: regexp: ^#? ?{{ item }} line: "{{ item }}" state: present Thanks for your script (sorry i do not know how to put a newline character in comment)
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