ARTbio / GalaxyKickStart

Ansible playbooks for Galaxy Server deployment
GNU General Public License v3.0
24 stars 22 forks source link

Adding flavors: best practice #180

Closed afgane closed 8 years ago

afgane commented 8 years ago

We're using this playbook for building VM images on the Jetstream cloud and, in the near future, on the Google Compute Engine. We'd also like to merge these flavors into this upstream repo in case others want to do the same. However, Jetstream in particular, needs some customizations so we put those into its own role. Now, the question is how best to include that role in the upstream codebase without making it verbose? I'd guess one role would even be OK but as we move to GCE and beyond, it's not going to look pretty. Any suggestions of thoughts on this?

Here's an example of what I'm talking about https://github.com/nturaga/ansible-artimed/blob/master/galaxy.yml#L14

mvdbeek commented 8 years ago

Hi Enis,

that is awesome, I'm really happy that you are able to adapt the playbook with a single role! I have to think about how to best include "flavor roles", but I see some parts of the role that can move to upstream roles (or maybe are already ...)

The whole cleanup part can be included as a named include handler, so that you need to include the role only once.

I can see a few potential ways to include community/flavor roles, I guess the difficulty is that you may need to have control over the position in the play in which the role will be executed, right?

So the way you have done this right now is completely OK for me if we're expecting just a few additional roles, and it's probably not worth the additional complexity to have a roles variable.

Not sure if this is possible, but maybe we can have a structure like this:

- hosts: all
  become: yes

  handlers:
    - include: roles/handlers/galaxy.yml
      static: yes

  roles: {{ roles_list}}

where

roles_list:
    - role: galaxyprojectdotorg.galaxy-os
      tags:
        - install_galaxy
        - install_packages

    - role: jetstream
      when: jetstream is defined

    - role: ensure_postgresql_up
      tags:
        - install_galaxy
        - manage_postgres
...

so that flavors can define their own roles list in the inventory.

Do you have any opinion on this, @drosofff ?

afgane commented 8 years ago

Thanks for the comments. I've made a few of these changes and propagated them around, shortening the setup required for Jetstream. I've also locally updated galaxy-os and galaxy-extras roles but haven't committed those yet - things are seemingly continuing to function fine.

The main problem I have is with the cleanup handler. According to this http://stackoverflow.com/questions/31618967/how-do-i-write-an-ansible-handler-with-multiple-tasks, I've added the following to roles/jetstream/handlers/main.yml

- name: instance cleanup
  include: cleanup.yml
  static: yes

but when a task used to notify the handler runs, the run breaks with the following error message ERROR! The requested handler 'instance cleanup' was not found in any of the known handlers. If I change the include line to a simple task (e.g., shell: apt-get clean), everything runs fine. Since cleanup is a composite process, it would need to be an include piece but I'm not sure what I'm missing. Any suggestions?

mvdbeek commented 8 years ago

I think you've hit https://github.com/ansible/ansible/issues/15915. This will be in the next stable release 2.1.2, but in the meantime you could install the 2.1.2.0 rc from https://github.com/ansible/ansible/archive/v2.1.2.0-0.1.rc1.zip

afgane commented 8 years ago

Thanks again; that resolves that problem.

One more question: do you know how to override a portion of a list/composite variable? For example, I'd like to add a few config options to galaxy_config from group_vars/all but not have to keep a complete copy of it in group_vars/jetstream: https://github.com/ARTbio/GalaxyKickStart/compare/master...nturaga:master#diff-fc7cb0a7b647c6ff35b553a10d616c4bL60

afgane commented 8 years ago

I gave up on the idea of merging the two variables (more info here: https://github.com/nturaga/GalaxyKickStart/commit/c424172c25efac0788375ad7465a8ce4e3edbffb)

drosofff commented 8 years ago

@afgane can I close the issue ?