Infrastructure as Code with Ansible in the Lathe Era: Learn Domains, Not Skim Past Them
A practical deep dive into Infrastructure as Code with Ansible — real examples, comparisons, and setup guides.
Infrastructure as Code with Ansible in the Lathe Era: Learn Domains, Not Skim Past Them
A few weeks ago I skimmed a post about Lathe—the idea that you should use LLMs to learn a new domain, not skip past it. If you’re reaching for an automation tool because it promises “magic without effort,” that post punches back: you still have to understand the domain you’re automating. Infrastructure as Code (IaC) with Ansible is a perfect test bed for that idea. LLMs can bootstrap playbooks, generate skeleton roles, and translate human intent into tasks, but the real value comes when you own the domain knowledge: idempotence, state, dependencies, and the governance that keeps infra from becoming a spaghetti factory.
In this article I’ll anchor the discussion in the practical reality of 2026: teams are using LLM-assisted tooling to jump-start playbooks, but they’re also re-learning core IaC discipline—to avoid brittle deployments, drift, and security holes. I’ll show you how I structure Ansible code, how to test it, and how to balance the speed of automation with the discipline of traditional configuration management. You’ll find a concrete, runnable example you can copy into your lab, plus a quick comparison table to help you decide when Ansible is the right tool in a multi-tool IaC ecosystem.
Why the news matters to Ansible users
The latent glamour around LLMs isn’t hype if you apply it to infrastructure. Lathe’s premise—learn a new domain rather than gloss over it—maps directly to how I work with Ansible. I don’t want a generic cookbook; I want a domain-aware playbook that understands package managers, OS differences, service states, and idempotence guarantees. LLMs can draft an initial playbook or role skeleton, but you still need to verify:
- Idempotence: Running the play multiple times should converge to the same state without side effects.
- Deterministic outcomes: Given the same inputs, the same result every run.
- Secrets handling: Encrypting sensitive data and avoiding hard-coded credentials.
- Testing: Local dry runs, molecule tests, and CI checks to avoid drift in prod.
- Governance: Role boundaries, access control, and change review so automation doesn’t run wild.
The news items you’ve seen—like “LLMs are eroding my software engineering career and I don’t know what to do” and “Show HN: Lathe—Use LLMs to learn a new domain, not skip past it”—underscore a practical truth: automation must be teachable, auditable, and resilient. Ansible fits that model well because:
- It’s human-readable YAML with a declarative style that maps cleanly to domain concepts.
- It’s heavily modular, so you can codify “domain knowledge” into roles, tasks, and variables.
- It has a mature ecosystem for testing and governance (Molecule, ansible-lint, Ansible Vault, AWX/Automation Platform).
What changed in practice
- The tooling surface has shifted from “one-off scripts” to repeatable, role-based architecture. Ansible Galaxy roles and curated collections are the reusable domain knowledge you want to own.
- Cloud and on-prem environments are converging on similar patterns: you provision infrastructure and then configure it. Ansible can do both in one pipeline, but you should keep those concerns separate for clarity.
- Testing matters more than ever. Molecule (or Testinfra with ansible) helps you prove that your roles are idempotent and that configurations match the desired state.
- Secrets management is non-negotiable. Ansible Vault, environment-based vars, and proper CI secret management are essential.
A practical starter: a minimal Ansible project you can reuse
I’ll walk you through a small, self-contained example you can run in a lab. It configures an Ubuntu host to install Nginx and ensure a basic service is up, a classic but meaningful IaC scenario that tests the core skills: package management, service orchestration, and a simple firewall rule.
What you’ll need
- An Ubuntu host (or a VM) reachable by SSH from your control machine.
- Ansible 2.14+ (or newer) installed on your control machine.
- A basic inventory with at least one host.
Files to create
1) inventory.ini
- This is your target ledger. It can be as simple as:
[web]
ubuntu-web01 ansible_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa
2) site.yml
- The main playbook that installs Nginx, starts the service, and opens port 80 (if you want a firewall step, that can be added with ufw).
- name: Configure web server
hosts: web
become: yes
vars:
nginx_port: 80
tasks:
- name: Update apt cache
apt:
update_cache: yes
cache_valid_time: 3600
- name: Install Nginx
apt:
name: nginx
state: present
- name: Ensure Nginx is running and enabled
service:
name: nginx
state: started
enabled: yes
- name: Create a simple index.html
copy:
dest: /var/www/html/index.html
content: "<h1>Welcome to Ansible-configured server</h1>\n"
3) group_vars/web.yml (optional)
- You can keep domain-specific knobs here to avoid editing site.yml later.
---
nginx_sites:
- server_name: "example.local"
root: "/var/www/html"
4) Run it
- First dry run to catch obvious issues:
```
ansible-playbook