Raspberry Pi Experiments: Ansible playbook to set timezone
In my home I have 3 Raspberry Pis which are hooked to my LAN and 3 more in standby. One issue that I have always faced setting up any Raspberry Pi is, how to sync their timezone. While setting timezone for each Raspberry pi may sound a one time job but when one has to do it for multiple systems, it calls for automation. Ansible seemed a good option for this job.I found a very helpful role to do just this setup.
Since last few weeks I have been playing with Ansible and one issue I have faced with Ansible Roles is that while there are many good reusable roles out there, but for Raspberry PI most of them needed tweaking at role level. But with this role I had no such issues.
The first thing I did was to install the role. Since I have roles installed under my playbooks folder I used the following command.
ansible-galaxy install anxs.timezone -p playbooks/roles
The playbook was pretty simple, I just wanted to setup the timezone and wanted to test if the timezone really changed. For that I wrote the below playbook.
Here host raspi consists of the host address for all the Raspberry Pi in my network. And the timezone is referred by the below statement.
timezone_zone: Asia/Kolkata
In the below post task ansible_default_ipv4.address refers to the ip address of the Raspberry server and tz_op captures the output of date shell command which is run on each server.
Finally I ran the playbook with the following command
ansible-playbook playbooks/set_in_tz.yml -i inventory