0

I have next project roles:

hosts
site.yml
/roles
  /proxy
    /tasks
    ...
  /web
    /tasks
    ...
  /worker
    /tasks
    ...
  /db
    /tasks
    ...

I need to install chruby on web and worker. So installed https://github.com/ferrarimarco/ansible-role-chruby from Galaxy, but I don't know how to add tasks from chruby to web and worker roles.

Please advice.

Kirill Salykin
  • 681
  • 6
  • 19

1 Answers1

2

You can not include single tasks from roles. If you install a role, no matter if from Galaxy or any other source, you can use it as it is by adding it to the roles section of your playbook or as a dependency in any of your own roles.

The readme of the chruby role shows an example playbook:

- hosts: all
  roles:
    - ferrarimarco.chruby

I need to install chruby on web and worker

You can add it as a dependency to those roles. The format is the same. Create a file roles/web/meta/main.yml (and the same for the worker role) with the content:

dependencies:
  - ferrarimarco.chruby

If you were looking for tasks to actually use chruby, I have to disappoint you. There is nothing in the role. But it appears to me chruby simply is a command which you can use with the command or shell modules:

- name: Change ruby to 1.9.3
  shell: chruby 1.9.3

A role could provide mechanisms (tags or extra-vars) to trigger specific tasks, for example installing, updating or uninstalling software. Also a role could provide modules to interact with the installed software. But this is not the case with the chruby role. It simply installs chruby and its dependencies via apt.

udondan
  • 57,263
  • 20
  • 190
  • 175
  • Dependencies - this is what I needed. Is there a way to manage order? – Kirill Salykin May 19 '16 at 07:29
  • Dependencies are executed in the order they are referenced. – udondan May 19 '16 at 07:32
  • I mean to run between my tasks (I understand this is not the `dependency`, maybe an inclusion). – Kirill Salykin May 19 '16 at 07:34
  • You can always simply include a tasks file from another role. But this is not the same as running a role. The defaults, vars, files, templates, handlers etc will not be available, only the tasks will be executed. So I don't think this is going to work in the chruby case. – udondan May 19 '16 at 07:44
  • Maybe you can split up your web and worker roles in smaller packages and then implement all the small packages including the chruby role in the order you wish in a main role. – udondan May 19 '16 at 07:45