# Set Local Timezone with Ansible

You know this annoyance when you install a fresh linux server and it has time in UTC? At least I end up like that with Armbian when I don't access it with interactive shell.

It turns out that there is a very simple way of setting your timezone automatically based in your IP location, especially if you use Ansible for that.

Now, Ansible has two tasks:

* [ipinfoio\_facts](https://docs.ansible.com/ansible/latest/collections/community/general/ipinfoio_facts_module.html): which uses [http://ipinfo.io/](http://ipinfo.io/) to approximate your lacation based on your external IP address;
    
* [timezone](https://docs.ansible.com/ansible/latest/collections/community/general/timezone_module.html): which sets your timezone.
    

Thus everything you need to do, is to have these two tasks sequentially in your playbook

```yaml
---
- hosts: "all"
  become: true
  
  tasks:
    - name: Get IP geolocation data
      ipinfoio_facts:

    - name: "Set timezone to {{ ansible_facts.timezone }}"
      timezone:
        name: "{{ ansible_facts.timezone }}"
      when: ansible_facts.timezone is defined
```

As you can guess from the code, the `ipinfoio_facts` task is going to populate `ansible_facts` with various location datai, and out of which we will use `timezone` to set, well..., the time zone (if it's available).

That's all. I hope I helped someone ☺️
