Last Updated: February 25, 2016
· Lorin Hochstein

Update locale and timezone on ubuntu

Here's a simple ansible playbook for setting the locale and time zone on an Ubuntu server.

- name: Set the locale and the time zone
  hosts: myhosts
  sudo: True
    locale: en_US.UTF-8
    timezone: America/New_York

    - name: set locale
      command: /usr/sbin/update-locale LANG={{ locale }} LC_ALL=$locale
    - name: set /etc/localtime
      file: src=/usr/share/zoneinfo/{{ timezone }} dest=/etc/localtime state=link
    - name: set /etc/timezone
      template: src=templates/etc/timezone dest=/etc/timezone
      notify: update tzdata

    - name: update tzdata
      command: /usr/sbin/dpkg-reconfigure --frontend noninteractive tzdata

It also needs a template file in ./templates/etc/timezone that looks like this:

{{ timezone }}

Use it like this:

$ ansible-playbook set-locale-and-timezone.yaml

1 Response
Add your response

should you be copying or symlinking these tz files?

over 1 year ago ·