Back to Blog
team@tinypod.app

Ansible for Self-Hosted Infrastructure

Ansible automates server configuration. Define your infrastructure as code and never manually configure a server again.

ansibleautomationinfrastructure

What Is Ansible?


Ansible is an automation tool that configures servers over SSH. No agents to install. Write YAML playbooks, run them, servers are configured.


Why Use Ansible?


Reproducibility

Your server configuration is code. Version it in git. Rebuild from scratch in minutes.


Consistency

Every server is configured identically. No manual SSH sessions creating snowflake servers.


Documentation

The playbook IS the documentation. New team member? Read the playbook to understand the server setup.


Basic Concepts


Inventory

List of servers to manage:

[webservers]

web1.example.com

web2.example.com


[databases]

db1.example.com


Playbook

YAML file describing desired state:

  • hosts: webservers
  • tasks:

  • name: Install Caddy
  • apt: name=caddy state=present

  • name: Start Caddy
  • service: name=caddy state=started enabled=yes


    Roles

    Reusable configuration packages. Community roles on Ansible Galaxy.


    Self-Hosting Playbook Example


    A complete playbook to set up a self-hosting server:


    1. Install Podman (container runtime)

    2. Configure firewall (allow 80, 443)

    3. Set up Caddy (reverse proxy)

    4. Create data directories

    5. Pull and start application containers

    6. Configure backups (Restic to S3)

    7. Set up monitoring (node_exporter)


    Ansible vs Alternatives


    Ansible vs Shell Scripts

  • Ansible is idempotent (safe to run multiple times)
  • Shell scripts are fragile and hard to make idempotent
  • Ansible is declarative (what), shell is imperative (how)

  • Ansible vs Terraform

  • Terraform: Infrastructure provisioning (create servers, DNS, load balancers)
  • Ansible: Configuration management (configure what's on the servers)
  • Use both: Terraform creates the server, Ansible configures it

  • Ansible vs Docker

  • Not competing. Ansible can deploy Docker/Podman containers
  • Use Ansible to set up the host, containers to run the apps

  • Getting Started


    1. Install Ansible on your local machine

    2. Add your server to the inventory

    3. Write a simple playbook

    4. Run: ansible-playbook -i inventory.ini playbook.yml

    5. Watch your server configure itself


    Pair Ansible with TinyPod: use Ansible for host-level configuration and TinyPod for application deployment.