hdul2g
Last Updated: February 25, 2016
·
8.802K
· lorin
Me pixel

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
  vars:
    locale: en_US.UTF-8
    timezone: America/New_York

  tasks:
    - 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

  handlers:
    - 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
Say Thanks
Respond

1 Response
Add your response

15714
537449ba51eeff09dc6a5fc50a0b5d4f

should you be copying or symlinking these tz files?

over 1 year ago ·
Filed Under