VOOZH about

URL: https://thenewstack.io/automate-routine-tasks-with-an-ad-hoc-ansible-script/

⇱ Automate Routine Tasks With an Ad-Hoc Ansible Script - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

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.

What’s next?

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.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2024-07-15 11:31:21
Automate Routine Tasks With an Ad-Hoc Ansible Script
sponsor-andela,sponsored-post-contributed,
Infrastructure as Code / Operations / Python

Automate Routine Tasks With an Ad-Hoc Ansible Script

Dynamically generate inventory files to simplify everyday tasks using Ansible and Python.
Jul 15th, 2024 11:31am by Adetokunbo Ige
👁 Featued image for: Automate Routine Tasks With an Ad-Hoc Ansible Script
Featured image by Unsplash+ in collaboration with Ave Calvar.
Andela sponsored this post.

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.

Step 1

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.

Step 2

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.

Step 3

Extract the server’s IP address using Python to dynamically generate the inventory file:

Step 4

Save the following Ansible playbook as ansible-playbook.yml:

Step 5

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:

Step 6

Your output should look similar to this screenshot.

👁 Output of running Ansible playbook to detect time zone anomalies

Conclusion

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.

Andela provides the world’s largest private marketplace for global remote tech talent driven by an AI-powered platform to manage the complete contract hiring lifecycle. Andela helps companies scale teams & deliver projects faster via specialized areas: App Engineering, AI, Cloud, Data & Analytics.
Learn More
The latest from Andela
Hear more from our sponsor
TRENDING STORIES
Adetokunbo Ige is a technologist for Andela, a private global talent marketplace. A seasoned platform engineer and a Certified ISO 22301 Lead Implementer in Business Continuity, he brings a wealth of experience in software engineering, enterprise application management, server infrastructure...
Read more from Adetokunbo Ige
Andela sponsored this post.
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.