0
votes

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.

1

1 Answers

2
votes

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.