0

We can use the following code to set a new timezone on AWS EC2 using Ansible.

---
- hosts: linuxservers proxmoxservers
  remote_user: ansible
  become: yes

  tasks:

  - name: 'Set timezone to Buenos Aires'
    timezone:
      name: America/New_York

  - name: Ansible date fact example
    debug:
      msg="{{ lookup('pipe','date +%Y-%m-%d-%H-%M-%S') }}"

After this,

  • How do we verify if the current timezone is set to the expected value?
  • How to validate the timezone has been changed correctly (to the desired value)?

1 Answer 1

1

How to validate that ... has been changed correctly (to the desired value)?

Since Ansible is a Configuration Management Tool with which you set a Desired State, such validation is part of the modules in general.

For timezone module – Configure timezone setting

It is recommended to restart crond after changing the timezone, otherwise the jobs may run at the wrong time.

After that you may have a look into one the following

For Linux it can use timedatectl or edit /etc/sysconfig/clock or /etc/timezone and hwclock.

or better (re-)gather Ansible Facts

---
- hosts: localhost
  become: false
  gather_facts: true
  gather_subset:
    - "!all"
    - "!min"
    - "date_time"

  tasks:

  - name: Show Facts date_time
    debug:
      msg: "{{ ansible_date_time }}"

since that will contain the timezone settings or updated timezone settings.

Further Readings

Please take note about

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.