Skip to main content

Command Palette

Search for a command to run...

Ansible an Prometheus

Updated
•3 min read•View as Markdown
V

As a technologist passionate about building robust systems, I am deeply engaged with DevOps, cloud-native technologies, and automation. My technical journey is centered on a deep dive into Golang, where I explore everything from concurrency to building system tools. I am also proficient in Python, applying it to machine learning and data science projects. From architecting Kubernetes clusters to exploring cybersecurity principles and the fundamentals of self-improvement, I am a lifelong learner constantly seeking new challenges. This blog is where I document my projects and share insights from the ever-evolving world of technology.

For the past few weeks, I've wanted to learn and use Prometheus and Ansible in some way, but there hasn't been a practical opportunity. Learning Ansible seemed unnecessary because I only have one server, and any management tasks can be handled directly via SSH. I don't need or want more servers for my simple homelab setup.

Prometheus is beneficial for applications receiving traffic or when OS-level metrics are needed. However, I don't require those metrics, and I haven't developed any application receiving organic traffic, so Prometheus remained on project pending.

Everything changed when I began learning API development and started building a simple 3-tier application just to understand APIs.

Suddenly, I had numerous endpoints to access, an app ready for deployment, metrics to expose, OS-level traffic to monitor, and even the possibility of using Kubernetes for scaling.

Prometheus Part

I decided to explore Prometheus first, as Ansible still required more servers. To learn Prometheus, I containerized my application with three services: backend, database, and Prometheus.

The first step was configuring the scraping job and endpoint in prometheus.yaml

Later, along with the fastapi-instrumentator that provides the standard four metrics, I also implemented counters and gauges for successful logins, failed logins, total logins, and more. This experience taught me how to integrate custom metrics into the application code. Although the fastapi-instrumentator offered more than necessary, as I had no specific implementation or custom metrics to expose, learning about counters and gauges helped me understand how to consider metrics at the code level.

The final step involved the UI and PromQL. Honestly, PromQL needed more focus, but once I grasped the basic queries, it was amazing to see the graphs and total counts generated from my own application!

Overall, I gained a solid introduction to Prometheus and am now exploring Node Exporter to deepen my understanding of its functionality.

Ansible Part

When it came to Ansible, I was grateful to iximuz labs for allowing me to spin up multiple VMs at will. This capability enabled me to create my own cluster or pursue any other projects I had in mind.

To begin learning Ansible, I set up four servers, including one home server, and connected them all to the same network using Tailscale.

I installed Ansible on my host machine, configured the host file, and started with the "hello world" command: -m ping. My excitement grew when I saw the successful response. From there, it felt like diving into a rabbit hole, exploring modules like shell, command, lineinfile, apt, yum, and service covering all the basics. The first time I executed these commands, it felt like magic. Installing and starting services, gathering server information, editing files, and installing packages became incredibly easy. I know I've only scratched the surface, but the ease and possibilities amazed me.

Currently, I am learning more about writing playbooks, managing deployments, and specifically writing Dockerfile replacements to test deployments on cloud, bare metal servers, and everything in between.

Conclusion

Honestly, this felt like another aspect of DevOps to me (more like the Ops side, I guess). By learning these skills, I've discovered new opportunities to implement them and simplify my life.