Skip to content

Ansible timezone issue

wordpress meta

title: 'Ansible timezone issue'
date: '2017-01-26T13:16:52-06:00'
status: publish
permalink: /ansible-timezone-issue
author: admin
excerpt: ''
type: post
id: 1043
category:
    - Ansible
tag: []
post_format: []

It appears like there is a bug with setting the timezone with ansible. Maybe it will be fixed soon but a workaround like below worked for me.

Issue:
Timezone module cannot set timezone in not systemd based system #19745
https://github.com/ansible/ansible/issues/19745

Should work like this:

   - name: set timezone to New_York
     timezone:
      name: America/New_York

Workaround like this:

  vars:
   - timezone: America/New_York


   - name: Check current timezone
     shell: awk -F\" '{ print $2}' /etc/sysconfig/clock
     register: current_zone
     changed_when: False

   - name: Set EST timezone
     file: src=/usr/share/zoneinfo/{{ timezone }}  dest=/etc/localtime state=link force=yes
     when: current_zone.stdout != '{{ timezone }}'