0

I have a big role i am looking to pack in a collection, and i want to create a plugin that does calls the role, instead of doing "include_role". so, i am looking for my customers to be able to put something like:

- name: call my plugin
  my_plugin:
    param1: "mmm"
    param2: 42

and that will, internally, run some verifications, but eventually it will call on the entire role to execute (contrary to just calling a module).

all the documentation i found seem to call modules from the plugin, but nothing seems to be able to call a role (or a playbook). is there a way to achieve that?

Ehud Kaldor
  • 753
  • 1
  • 7
  • 20

1 Answers1

1

If you really want to go this way, you can look into include_role source code. (f.e. here https://github.com/ansible/ansible/blob/2cbfd1e350cbe1ca195d33306b5a9628667ddda8/lib/ansible/playbook/role_include.py). It doesn't look to me like a normal pugin, though.

But there is a more serious issue here: If you create something like that, it would totally obscure the role content from the user. Roles aren't 'python modules', and isolation is very weak for roles. By hiding role content (and execution) from users, you create, basically, your own version of ansible, with fresh and unknown list of bugs and quirks.

If you want to control the way code is executed, the strategy plugin may be a more reasonable place. You still allow users to see the usual execution workflow, but you'll have a great deal of control on how things are executed.

But writing strategy plugins is crazy hard. I know only one third party strategy plugin (mitogen).

George Shuklin
  • 6,952
  • 10
  • 39
  • 80
  • you are most probably right. the context is i'm using a collection as a distribution mechanism, with a main role and some optional aux roles i was looking to let the user control via task params. i guess that's not the way, and neither is a module. any other idea would be appreciated... – Ehud Kaldor May 06 '21 at 17:05
  • Try to distribute playbooks as well. You can't ship a box product with ansible (as there are to many connections between inventory and plays/roles though variables), but shipping a set of roles with playbooks (or playbook examples) is a usual way. Try to look into ceph-ansible and kubespray projects for inspiration and ideas. – George Shuklin May 07 '21 at 18:10