Twenty servers, each configured differently. Documentation living inside one admin’s head. When they go on holiday, nobody knows how to set up a server. Infrastructure as Code with Ansible changed that — servers are defined in YAML, versioned in git.
Why Ansible¶
Agentless: Ansible communicates over SSH. No agent on the servers, no daemon, no additional infrastructure. Puppet and Chef require an agent — more software to maintain. YAML: Playbooks in readable YAML. No Ruby (Chef) or DSL (Puppet).
Playbook example¶
---
- hosts: webservers
become: yes
tasks:
- name: Install Nginx
apt: name=nginx state=latest
- name: Deploy config
template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
notify: Restart Nginx
- name: Ensure running
service: name=nginx state=started enabled=yes
handlers:
- name: Restart Nginx
service: name=nginx state=restarted
Idempotence and roles¶
Every task is idempotent — run the playbook 10 times and the result is the same. Roles organise logic into reusable packages: role nginx, role postgresql, role java. Ansible Galaxy for sharing community roles.
Inventory and dynamic inventory¶
Static inventory for fixed servers. For cloud environments, a dynamic inventory script that queries the AWS/Azure API and returns the current list of servers.
Servers as code¶
Ansible is the most accessible path to Infrastructure as Code. Agentless, YAML, SSH. Server documentation lives in git; onboarding means reading the playbook.
Need help with implementation?
Our experts can help with design, implementation, and operations. From architecture to production.
Contact us