DEV Community

Femi
Femi

Posted on

Clean Code for DevOps: Refactoring my Ansible Lab into Roles

As my Ansible project grew, my single master playbook started to get crowded. Today, I decided to 'graduate' my automation by implementing Ansible Roles.
​I’ve moved from a linear script to a modular directory structure:
​/roles/web_servers
​/roles/workstations
​/roles/db_servers
roles/file_servers

​This refactor allows me to treat my infrastructure like LEGO blocks. Need a new web server? Just call the role. Want to update my workstation? The logic is isolated and safe.



​The biggest challenge? Managing file paths and ensuring the tasks/main.yml in each role was perfectly mapped. It’s a bit more setup time initially, but the long-term maintenance is now nearly zero.

Top comments (0)