Best way to organize your playbooks

34 views
Skip to first unread message

Михаил Политаев

unread,
Aug 1, 2019, 1:31:49 AM8/1/19
to Ansible Project
I have a several projects which describing installation 2 different applications. Each directory for application:

app1/roles/common/main.yml
app2/roles/common/main.yml

But application have similar between them tasks which described in "main.yml" of role "common"

What is the best way have only one source to those similar tasks without having 2 or more versions and duplicate them across projects. From my point of view:

It can be separate dir:
playbooks/common_tasks.yml

Which will be imported to those "main.yml" files:
app1/roles/common/main.yml
app2/roles/common/main.yml

But maybe someone else see a better solution?

Sebastian Meyer

unread,
Aug 1, 2019, 1:44:26 AM8/1/19
to ansible...@googlegroups.com
On 01.08.19 07:31, Михаил Политаев wrote:
> I have a several projects which describing installation 2 different
> applications. Each directory for application:
>
> app1/roles/common/main.yml
> app2/roles/common/main.yml
>
> But application have similar between them tasks which described in
> "main.yml" of role "common"
>
> What is the best way have only one source to those similar tasks without
> having 2 or more versions and duplicate them across projects.
You could make use of the roles_path configuration setting [0] and have
a directory structure like this:

ansible/
common/roles/
app1/roles/
app2/roles/

and in the app folders each an ansible.cfg with:

roles_path: ./roles:../common/roles

[0]
https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-roles-path

--
Sebastian Meyer
Linux Consultant & Trainer
Mail: me...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537


-- Deutsche OpenStack Tage 2019 -- 10% Rabatt auf den Ticketpreis ----
------------------------ https://openstack-tage.de (Code DOST-B1) ----

Михаил Политаев

unread,
Aug 1, 2019, 1:50:18 AM8/1/19
to ansible...@googlegroups.com
Awesome! Looks like a plan! Thanks!

чт, 1 авг. 2019 г. в 07:44, Sebastian Meyer <me...@b1-systems.de>:
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/AzH2GwEA9Ls/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8f7c5bb5-aaa6-4de2-7031-c0cdd4a538db%40b1-systems.de.

Andrew Feller

unread,
Aug 1, 2019, 5:51:47 AM8/1/19
to ansible...@googlegroups.com
You might re-examine whether it is appropriate for a role and a playbook as it feels like your playbooks are too heavy.

Roles ideally should be reusable logic for a given context you can apply to multiple situations.  For example, you might have multiple kafka/mysql/etc clusters for different uses that a single role given the necessary info via playbook and inventory can manage.  If you need to build higher order reusable roles, you can have roles with dependent roles that compose them to your ends; leaving your playbooks thinner.  Playbooks ultimately should be highest order orchestration that isn’t bogged down into all of the technical details.

Say what you will about Puppet but I would consider the reasoning behind their roles and profiles and how it applies to Ansible: https://puppet.com/docs/pe/2018.1/the_roles_and_profiles_method.html


Sent from my iPhone
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAKP%3D2uxpjLjmXm9qympt%3DsbDXMg1%3DP1DHxmh%2B0GNv3XGKRYxDg%40mail.gmail.com.

Михаил Политаев

unread,
Aug 1, 2019, 9:36:58 AM8/1/19
to Ansible Project
Think re-examine how i look into the roles is helped to me. Now after i reorganize my roles slightly different is helped for me:

Each role have purpose of install nginx, monitoring, etc. 

And after that high level playbook will combine them together to get application worked. For example distributed wordpress, or ha lamp stack rather than I have before each role to configure application. 

четверг, 1 августа 2019 г., 11:51:47 UTC+2 пользователь Andrew Feller написал:
To unsubscribe from this group and all its topics, send an email to ansible...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages