![]() |
VOOZH | about |
We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.
Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.
Follow TNS on your favorite social media networks.
Become a TNS follower on LinkedIn.
Check out the latest featured and trending stories while you wait for your first TNS newsletter.
No one wants to spend an entire day running a manual script on a thousand servers. Fortunately, many processes like this can be automated using Ansible.
For example, imagine you are given a task to run a command to detect the Timezone on 1,000 servers. A quality engineer detected that some transactions are dated in the future, and the engineers suspected that some servers might have incorrect time zones. You are given a file that contains the IP addresses of 1,000 servers.
I will walk through completing this task by running an ad-hoc script to dynamically generate an inventory file using Ansible. All of this code is available on GitHub, and this tutorial assumes you already have an understanding of Python, Ansible and Bash.
Establish a passwordless SSH connection with the target host. This will enable Ansible to securely log into the target host without having to input the password.
Add the IP address to the file servers.txt and ensure the IP address is valid and follows the format in the servers.txt file.
Extract the server’s IP address using Python to dynamically generate the inventory file:
Save the following Ansible playbook as ansible-playbook.yml:
Run the Ansible playbook, which will run a command date on the target servers and display the output in a file called report.txt , with:
Your output should look similar to this screenshot.
👁 Output of running Ansible playbook to detect time zone anomalies
Ansible simplifies complex tasks, such as instance infrastructure provisioning, configuration management and software deployment across a large-scale environment. You can find the full code for this tutorial on GitHub.