Ansible template Role – easy way of creating projects

Ansible template treeWorking with Ansible is a real pleasure. You can build your own roles and big projects with many combinations and configurations. But sometimes you only want to quickly deploy a whole project with specified roles. When your automation needs to run many roles in different configurations, you face the problem of flexibility and fast deployment. Admittedly, Ansible community created tons of solutions, but maybe this one would be helpful for some of you. Especially with fast or temporary provisioning projects on the nodes without fully configured Ansible environment.

Ansible template Role is my fork of the Mohamed Boufnichel’s ansible_project_template Role. I have added some improvements, which extends the role possibilities. Also I have changed the way of the role creation. In Mohamed’s Role it was created by the making directory and copying files. I use an Ansible Galaxy init for that. Here you have a full (but short) list of changes and improvements:

  • change the way of the Role creation,
  • add possibility of the creation multiple Roles,
  • add possibility of the installation multiple Galaxy Roles.
How to run Ansible template

You can see below that use is very easy. In the playbook you need to specify only three variables. Of course, you can use a default values and run playbook only with specified hosts and role. Example of playbook:

The result of the Ansible template Role is a full project in line with Ansible Best Practices. It contains roles which you choose. Also you can limit playbook to the only one job (create an empty role or install with Galaxy) with tags. Installation of this role is simple – you can clone the repository from my GitHub or use Galaxy Ansible for it:

I hope you find my role useful and it will step up your automation in some cases.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.