Day-13 Refactoring Ansible Playbooks into Roles πŸš€

Published: (December 22, 2025 at 11:40 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

The Playbook

- name: Installing and running apache2
  hosts: all
  roles:
    - httpd

Leveling Up with Roles

I created my first role structure:

roles/
└── my-app/
    β”œβ”€β”€ tasks/
    β”‚   └── main.yml
    β”œβ”€β”€ handlers/
    β”‚   └── main.yml
    └── vars/
        └── main.yml

This makes the code reusable. If I need this configuration again, I just call the role!

The Code

Check it out here: https://github.com/JayanthDasari7/Ansible-Roles

Has anyone else here struggled with the directory structure of Roles initially? Let me know in the comments! πŸ‘‡

Back to Blog

Related posts

Read more Β»