Use Ansible to Check and Configure Timezone to you area


Support you are staying in Singapore and your time zone is “Asia/Singapore”. How do you check and configure the Timezone?

- hosts: all
  tasks:

  - name: Check current Timezone
    command: timedatectl show --property=Timezone --value
    register: timezone_output
    changed_when: false

  - name: Configure Timezone to Asia/Singapore
    command: timedatectl set-timezone Asia/Singapore
    when: timezone_output.stdout != "Asia/Singapore"

The command module is used to execute the timedatectl command and retrieve the current timezone and registered as timezone_output

The 2nd command is to configure the timedatectl if the timezone_output is not your desired “Asia/Singapore”

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.