Dependencies among roles with pluggability

Hi

Let’s say I have an editor role which contains a list (in form of a variable, let’s call it plugins) of programming-language-agnostic plugins plus an editor_type variable, and additional roles for each language like python, C++, etc.

What is the most elegant way of organizing these roles and their tasks such that:

  1. some of the tasks of python are only run only when the global entrypoint playbook site.yml also includes the editor role
  2. the role python is able to append its editor plugins to editor’s plugins variable prior to the execution of editor’s tasks
  3. the order in which roles are added or removed to/from the global site.yml does not matter, the execution of any combination of roles should lead to the execution of all the tasks that fit, e.g. initially I have editor_type=vim (editor_type is a variable in the editor role) with the plugins python and c++, but then I switch to editor_type=emacs, in which case the roles python and C++ would not normally be executed, but they have to, because they have to inject their functionality into editor, which has changed its editor_type

?

I’m using ansible 2 and I’m a beginner in ansible, so a concrete example would be highly appreciated.

For 1. I could use register: editor_exists in the editor role, and in the language plugins I could check when: exitor_exists exists, but how about problems 2. and 3.?

I do know python, so I could extend ansible with it, but I still need an outline of best practices to follow, as I’ve never used ansible before (just puppet).

Please use concrete yaml keywords and/or concrete class/method names where necessary, so I know exactly what to research further.

Regards,
Flavius Aspra