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”