How to Build Low‑Cost Automated Ops with Prometheus, Ansible & Jenkins
This article shares a step‑by‑step experience of a small team that built a low‑cost automated operations pipeline using Prometheus for monitoring, Ansible for configuration management, and Jenkins for CI/CD, covering monitoring, alerting, versioned configs, and scalable deployment practices.
Why Start with Monitoring and Alerting
Even a small team needs to know the current state of its services before planning further automation, so the first step is to set up monitoring and alerting.
Choosing a Monitoring System
Among Zabbix, Open‑Falcon and Prometheus, the author selected Prometheus because it uses a pull model, stores configuration as text for easy versioning, and offers many ready‑made exporters.
Deploying Prometheus with Ansible
The deployment is fully automated with Ansible and stored in Git. The architecture looks like this:
The main components are:
Prometheus Server – collects and stores metrics.
Alertmanager – evaluates alert rules and forwards alerts.
node‑exporter – exposes host metrics via HTTP; many other exporters are available.
Ansible role prometheus-ansible is used for installation.
Visualization with Grafana
Grafana integrates tightly with Prometheus. The Grafana dashboard is deployed as follows:
Example node‑exporter metrics view:
Alert Integration
Prometheus supports many alert channels; DingTalk integration is added via the open‑source prometheus-webhook-dingtalk component.
Configuration Versioning with Ansible
All configuration files are stored as plain text in a separate Git repository, enabling version control and future migration to Consul. Example directory layout:
├── environments/
│ ├── dev/
│ │ ├── group_vars/
│ │ │ ├── all
│ │ │ ├── db
│ │ │ └── web
│ │ └── hosts
│ ├── prod/
│ │ ├── group_vars/
│ │ │ ├── all
│ │ │ ├── db
│ │ │ └── web
│ │ └── hosts
│ └── stage/
│ ├── group_vars/
│ │ ├── all
│ │ ├── db
│ │ └── web
│ └── hostsLater the team plans to switch to Consul as a configuration center, which Ansible 2.0+ supports natively.
Jenkins for CI/CD
All projects are packaged and built by Jenkins. Ansible roles automate Jenkins installation and plugin management, requiring only a jenkins_plugins variable.
---
- hosts: all
vars:
jenkins_plugins:
- blueocean
- ghprb
- greenballs
- workflow-aggregator
jenkins_plugin_timeout: 120
pre_tasks:
- include_tasks: java-8.yml
roles:
- geerlingguy.java
- ansible-role-jenkinsThe Jenkinsfile, stored alongside the source code, defines the pipeline:
pipeline {
agent any
stages {
stage('Build') {
steps {
sh './gradlew clean build'
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
}
}
}
}Jenkins executes Ansible playbooks via the ansiblePlaybook step, using credentials and Ansible Vault for sensitive data.
withCredentials([sshUserPrivateKey(keyFileVariable:"deploy_private",credentialsId:"deploy"),
file(credentialsId: 'vault_password', variable: 'vault_password')]) {
ansiblePlaybook vaultCredentialsId: 'vault_password',
inventory: "environments/prod",
playbook: "playbook.yaml",
extraVars:[
ansible_ssh_private_key_file: [value:"${deploy_private}", hidden:true],
build_number: [value:"${params.build_number}", hidden:false]
]
}Organizing Scripts
Each project contains its own Jenkinsfile and an ansible directory with playbooks, which are zipped during the build and unpacked at deployment time.
Automating Script Generation
To avoid repetitive work, the team uses cookiecutter to generate Jenkinsfiles and Ansible scripts for new projects.
Summary of the Automation Roadmap
Deploy basic monitoring (Prometheus + Grafana).
Set up GitLab for source control.
Install Jenkins and integrate with GitLab.
Use Jenkins for automated build and packaging.
Run Ansible playbooks from Jenkins for deployment.
From this foundation, the team can evolve toward more advanced architectures such as CMDB generation with ansible-cmdb, sophisticated release management, auto‑scaling via Prometheus alerts, and ChatOps.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
