Part 5: Building a Complete Ansible Automation Workflow (From Inventory to Deployment)

You’ve come a long way — from your first playbook to roles, templates, and encrypted secrets. Now it’s time to put all the pieces together and build a complete, real-world Ansible workflow that you can reuse at work or home.

In this final part of the series, we’ll:

  • Define a real use case
  • Structure a full project layout
  • Walk through the key components
  • Run the playbook and verify success

Use Case: Deploy a Web Server with Apache

Let’s say you’ve spun up one or more virtual machines and you want to:

  • Create a new user
  • Install and configure Apache
  • Deploy a custom Apache config using a template
  • Use a secret (admin email) stored securely in Vault
  • Start and enable Apache

Project Layout

Here’s how the project directory is structured:

webserver-automation/
├── inventory.ini
├── site.yml
├── group_vars/
│   └── web.yml
├── secrets.yml  (Vault-encrypted)
└── roles/
    └── apache_setup/
        ├── tasks/
        │   └── main.yml
        ├── handlers/
        │   └── main.yml
        ├── templates/
        │   └── apache.conf.j2
        └── vars/
            └── main.yml

Step-by-Step Breakdown

inventory.ini

[web]
192.168.1.50

group_vars/web.yml

admin_email: webmaster@example.com

secrets.yml (Vault encrypted)

apache_admin_password: supersecretpassword

Encrypt it using:

ansible-vault encrypt secrets.yml

roles/apache_setup/tasks/main.yml

- name: Create web user
  user:
    name: webadmin
    state: present

- name: Install Apache
  apt:
    name: apache2
    state: present

- name: Deploy Apache config
  template:
    src: apache.conf.j2
    dest: /etc/apache2/sites-available/000-default.conf
  notify: Restart Apache

roles/apache_setup/handlers/main.yml

- name: Restart Apache
  service:
    name: apache2
    state: restarted

roles/apache_setup/templates/apache.conf.j2

<VirtualHost *:80>
    ServerAdmin {{ admin_email }}
    DocumentRoot /var/www/html
    ServerName {{ inventory_hostname }}
</VirtualHost>

site.yml

---
- name: Full Web Server Automation
  hosts: web
  become: true
  vars_files:
    - secrets.yml
  roles:
    - apache_setup

Running the Workflow

To execute your full automation:

ansible-playbook site.yml -i inventory.ini --ask-vault-pass

You’ll be prompted for the Vault password. Once entered, Ansible will:

  • Connect to your server
  • Create a new user
  • Install Apache
  • Deploy a templated config
  • Restart Apache

Verifying the Results

You can check:

  • Apache is running:
systemctl status apache2
  • The deployed config:
cat /etc/apache2/sites-available/000-default.conf
  • Apache is enabled on boot:
systemctl is-enabled apache2

Final Recap

In this series, you’ve learned how to:

  1. Install Ansible and run basic playbooks
  2. Structure tasks with variables, handlers, and tags
  3. Automate real admin work with core modules
  4. Organize with roles, templates, and Vault
  5. Build a practical, full-stack automation workflow

Whether you’re managing servers at work or tinkering in your home lab — you now have a foundation to automate reliably and at scale.

What’s Next?

This is just the beginning. From here, you can:

  • Explore Ansible Collections and Galaxy roles
  • Integrate with CI/CD and ServiceNow
  • Use Ansible Automation Platform for large-scale deployments

Thanks for joining this series on Green Codexa — and happy automating!

Share the Post:

Related Posts

Join the Codexa Crew – It’s free!

Stay Updated with the Latest in Tech & Automation

Be the first to know when new content drops on Green Codexa!