Answers: <p><strong>How to validate that ... has been changed correctly (to the desired value)?</strong></p>
  <p>Since Ansible is a Configuration Management Tool with which you set a Desired State, such <a href="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_checkmode.html" rel="nofollow noreferrer">validation is part of the modules</a> in general.</p>
  <p>For <a href="https://docs.ansible.com/ansible/latest/collections/community/general/timezone_module.html" rel="nofollow noreferrer"><code>timezone</code> module – Configure timezone setting</a></p>
  <blockquote>
  <p><em>It is recommended to restart <code>crond</code> after changing the timezone, otherwise the jobs may run at the wrong time.</em></p>
  </blockquote>
  <p>After that you may have a look into one the following</p>
  <blockquote>
  <p><em>For Linux it can use <code>timedatectl</code> or edit <code>/etc/sysconfig/clock</code> or <code>/etc/timezone</code> and <code>hwclock</code>.</em></p>
  </blockquote>
  <p>or better (re-)gather <a href="https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_vars_facts.html#ansible-facts" rel="nofollow noreferrer">Ansible Facts</a></p>
  <pre class="lang-yaml prettyprint-override"><code>---
  - hosts: localhost
    become: false
    gather_facts: true
    gather_subset:
      - &quot;!all&quot;
      - &quot;!min&quot;
      - &quot;date_time&quot;
  
    tasks:
  
    - name: Show Facts date_time
      debug:
        msg: &quot;{{ ansible_date_time }}&quot;
  </code></pre>
  <p>since that will contain the timezone settings or updated timezone settings.</p>
  <p><strong>Further Readings</strong></p>
  <p>Please take note about</p>
  <ul>
  <li><a href="https://stackoverflow.com/a/71061125/6771046">What is the exact list of Ansible <code>setup</code> <code>min</code>?</a>.</li>
  <li><a href="https://www.redhat.com/sysadmin/configuration-verification-ansible" rel="nofollow noreferrer">Using Ansible to verify configurations</a></li>
  </ul>
  
Answers: CC BY-SA 4.0
Answers: 2023-01-06T08:17:18.807Z
Answers: 2023-01-09T10:39:09.607Z
Answers: 2023-01-09T10:39:09.607Z
Answers: U880D
Body: <p>We can use the following code to set a new timezone on AWS EC2 using Ansible.</p>
  <pre class="lang-yaml prettyprint-override"><code>---
  - 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=&quot;{{ lookup('pipe','date +%Y-%m-%d-%H-%M-%S') }}&quot;
  </code></pre>
  <p>After this,</p>
  <ul>
  <li>How do we verify if the current timezone is set to the expected value?</li>
  <li>How to validate the timezone has been changed correctly (to the desired value)?</li>
  </ul>
  
Tags: <amazon-web-services><ansible><amazon-ec2>
Title: How to verify the time zone change is correct on AWS EC2 using Ansible?
UserDisplayName: Biju
ThreadText: # How to verify the time zone change is correct on AWS EC2 using Ansible?
  
  (Asked by: username_0 on 2023-01-05)
  
  We can use the following code to set a new timezone on AWS EC2 using Ansible.
  
  ```yaml
  ---
  - 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)?
  
  **Tags:** amazon-web-services, ansible, amazon-ec2
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-01-06. Score: 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](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_checkmode.html) in general.
  
  For [`timezone` module – Configure timezone setting](https://docs.ansible.com/ansible/latest/collections/community/general/timezone_module.html)
  
  > *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](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_vars_facts.html#ansible-facts)
  
  ```yaml
  ---
  - 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
  
  * [What is the exact list of Ansible `setup` `min`?](https://stackoverflow.com/a/71061125/6771046).
  * [Using Ansible to verify configurations](https://www.redhat.com/sysadmin/configuration-verification-ansible)
  
  
  ---
  
  