Riaan's SysAdmin Blog

My tips, howtos, gotchas, snippets and stuff. Use at your own risk!

Ansible

Ansible timezone issue

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 }}'

admin

Bio Info for Riaan