Skip to content
DevOps Automation Ansible

DevOps Automation with Ansible: A Beginner's Guide

Ian David Rossi
Ian David Rossi August 15, 2019 · 4 min read

TL;DR

If your environments are held together by shell history and muscle memory, you do not need more discipline—you need automation you can actually live with. Ansible gives you a way to describe the state of your infrastructure in plain text, run it repeatedly, and trust that a change in Git will become a change in reality.

“If one person’s laptop is the only place where your deployment script exists, you do not have automation—you have a single point of failure with a keyboard.”

Introduction

Most teams discover they need Ansible the day a “quick change” breaks half the fleet and no one remembers exactly what they ran last week.

Manual configuration works right up until:

  • You have more than a handful of servers.
  • You need to roll out a security change consistently.
  • You are asked, “what changed?” after an incident, and the honest answer is “no idea.”

Ansible is not magic, but it does something valuable: it turns the way you think about infrastructure into files that can be versioned, reviewed, and executed repeatedly. From a DevOps point of view, that is the difference between best effort and a real platform.

What is Ansible, Really?

Ansible is an open-source automation tool that uses simple YAML files to define tasks and desired state. It connects over SSH (or APIs) and is agentless, which means you do not have to deploy extra daemons on every host.

Some characteristics that matter in practice:

  • Agentless: You manage keys, not agents; fewer moving parts to patch and debug.
  • Declarative modules: Most modules describe the state you want (“package nginx should be present”), not the exact commands to run.
  • Idempotent: Running the same playbook twice should not break anything; it just converges the system to the desired state.

“Idempotent just means ‘safe to run again.’ That property is why you can sleep at night.”

Getting Started with Ansible

1. Install Ansible

Install Ansible on your control machine—this can be your laptop, a CI runner, or a jump host:

sudo apt update
sudo apt install ansible

2. Create an Inventory File

Define the target machines in an inventory file. This is your source of truth for where things live:

[webservers]
192.168.1.10
192.168.1.11

[dbservers]
192.168.1.20

3. Write a Playbook

Create a playbook to automate tasks. A playbook is a YAML file that describes which hosts to target and what they should look like. For example, to install Nginx:

- name: Install Nginx
  hosts: webservers
  tasks:
    - name: Install Nginx
      apt:
        name: nginx
        state: present

4. Run the Playbook

Execute the playbook and watch Ansible report which tasks changed what:

ansible-playbook -i inventory.ini playbook.yml

From Toy Playbooks to Real Automation

It is one thing to get nginx installed on a test box; it is another to operate a fleet with confidence. A few practices move you along that path.

Use Roles and a Clear Directory Structure

As your playbooks grow, flat files turn into a mess. Ansible roles let you group tasks, templates, and handlers into reusable units—web, database, monitoring, and so on.

Organize your repository so that a new engineer can understand “how we build a web node” just by looking at the roles/web directory.

Keep Secrets Out of Plain Sight

You will eventually need to manage API keys, database passwords, and certificates. Storing them unencrypted in playbooks is how breaches happen.

Use Ansible Vault to encrypt sensitive data at rest, and pair it with a sane process:

  • Who holds vault passwords?
  • How do you rotate them?
  • How do you keep CI/CD systems from leaking them into logs?

Test Like You Mean It

Because Ansible is idempotent, it is tempting to “test in prod” and rely on rollbacks. Resist that.

  • Use ephemeral environments (cloud instances, containers, or CI test runs) to validate playbooks.
  • Run syntax checks and dry runs (--check) in pipelines.
  • Capture before/after state in logs so you can explain what changed during an incident.

“If you do not know which playbook changed a server, you are one outage away from a very long night.”

Where Ansible Fits in a DevOps Toolchain

Ansible shines in a few places:

  • Provisioning and configuration: Building and maintaining IaC-style environments alongside tools like Terraform.
  • Application deployment: For teams not yet on full Kubernetes or where you still have important VM-based services.
  • Runbook automation: Turning common operational fixes into repeatable playbooks instead of copy-pasted command snippets.

It also pairs well with GitOps workflows: store playbooks in a repo, require reviews, and trigger executions from pipelines so humans are not running critical changes by hand.

Conclusion

Ansible will not fix a broken architecture, but it will expose whether you are serious about treating your infrastructure as something you can reason about, change deliberately, and reproduce.

Start small: pick one painful manual process—user onboarding, web node provisioning, log agent rollout—and automate it cleanly with Ansible. Put it in Git, review it like application code, and run it through CI/CD. Once you see the difference in reliability and speed, you will find yourself looking for the next thing to pull out of shell history and into a playbook.


Stay tuned for more DevOps tutorials and best practices that focus on tools that earn their place in your stack.


Stay tuned for more DevOps tutorials and best practices.