Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make galaxyproject.gxadmin role install its own dependencies #11

Closed
wants to merge 3 commits into from

Conversation

kysrpex
Copy link
Contributor

@kysrpex kysrpex commented Dec 11, 2023

Add tasks that invoke the system's package manager to install all packages the role needs to run.

From my experience as a Galaxy admin, I would say I'd rather have the roles install the packages they need to run rather than having to install them separately the hard way by discovering which ones are missing by trial and error. After all, I am forced to install them anyways.

I have added a couple of boolean role variables to disable this behavior (for edge cases).

I think it makes sense to request a review both from @hexylena and from admins the other main Galaxy instances (@natefoo, @cat-bro) since this is an important role for all of us and I might have missed something when considering what may go wrong.

I have tested this with #10.

Add tasks that invoke the system's package manager to install all packages the role needs to run.

Let said tasks be disabled via boolean role variables (they default to enabled).
tasks/main.yml Outdated
Comment on lines 2 to 18
- name: Update apt cache (Debian derivatives)
become: true
ansible.builtin.apt:
cache_valid_time: "{{ gxadmin_apt_cache_valid_time }}"
when: >-
ansible_os_family == "Debian"
and gxadmin_manage_dependencies
and gxadmin_manage_apt_cache

- name: Ensure role and gxadmin dependencies are installed
become: true
ansible.builtin.package:
name:
- git
- make
state: present
when: gxadmin_manage_dependencies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why are you doing this with apt rather than preferred package?
  2. I don't love having a flag for manaing the apt cache, that's so weirdly debian specific and not relevant for "download a simple package"

Copy link
Contributor Author

@kysrpex kysrpex Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using ansible.builtin.apt because updating the APT cache is Debian-specific. ansible.builtin.package does not update the repository metadata.

I think we do not need to do the same for EL because DNF is smarter than APT in this regard.

I agree with (2) and would also prefer not having this thing in the role variables. Let's say whatever I did, there was a 50% chance that you would disagree, and removing lines is easier than adding them haha

I proceed to remove gxadmin_manage_apt_cache and gxadmin_apt_cache_valid_time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm aware apt cache is debian specific, and the differences between the two.

However, the point was the rationale for forcing a cache update for installing git: A cache update should only be required in cases of adding a new repository, where the packages in the newly added repo won't be known to the cache. (Or in cases of e.g. a docker container where the cache can be ancient, but this isn't relevant for 99% of users, and everyone starts their docker containers with a big 'update the cache' stanza anyway.) Since we're not adding a new apt repository, it thus shouldn't be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, why should this role not work on the official Ubuntu Docker image...? In general it is unknown whether the cache is ancient or not. That's why I said DNF is smarter 😅.

tasks/main.yml Outdated Show resolved Hide resolved
@hexylena
Copy link
Member

From my experience as a Galaxy admin, I would say I'd rather have the roles install the packages they need to run rather than having to install them separately the hard way by discovering which ones are missing by trial and error. After all, I am forced to install them anyways.

So we (some other role developers) avoid this; the reason being that this role now must run as root unless the user figures out they can toggle off the dependency management, so they can run as an unprivileged user which is relevant for some of our environments.

That's why ansible-galaxy doesn't install system packages for you.

Remove the `gxadmin_manage_apt_cache` and `gxadmin_apt_cache_valid_time` role variables.
@hexylena
Copy link
Member

(Just adding on further, I can definitely see an argument for both, and a rationale for it, but this package was designed in keeping with other galaxyproject packages which tend to avoid dependencies.)

@kysrpex
Copy link
Contributor Author

kysrpex commented Dec 11, 2023

the reason being that this role now must run as root

Thanks, this is the kind of feedback I was looking for. If I can think of a good alternative I will reopen this PR.

@kysrpex kysrpex closed this Dec 11, 2023
@hexylena
Copy link
Member

So I don't think we need to close this, I'd be very happy for other admins to have input on this, maybe times are changing. That said at least we should have it default to not manage dependencies, to keep it in the same default behaviour as other galaxyproject roles.

(Alternatively we can do something like gxadmin_manage_dependencies: {{ galaxy_manage_dependencies | false }} to have it inherit the value from galaxy and provide a nicer UX. That said this option is maybe worse given that it produces strange behaviour for users that may not be expected for them.)

@hexylena hexylena reopened this Dec 11, 2023
@kysrpex
Copy link
Contributor Author

kysrpex commented Dec 11, 2023

So I don't think we need to close this, I'd be very happy for other admins to have input on this, maybe times are changing. That said at least we should have it default to not manage dependencies, to keep it in the same default behaviour as other galaxyproject roles.

(Alternatively we can do something like gxadmin_manage_dependencies: {{ galaxy_manage_dependencies | false }} to have it inherit the value from galaxy and provide a nicer UX. That said this option is maybe worse given that it produces strange behaviour for users that may not be expected for them.)

Ok, let's keep this open to let other admins have a say as well :)

@kysrpex
Copy link
Contributor Author

kysrpex commented Dec 11, 2023

Related #3.

Copy link
Member

@natefoo natefoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default to disabled but settable to enabled is the way to go imo. I am fine with the role doing this as long as it's controllable for the reasons @hexylena mentioned.

@@ -1,4 +1,21 @@
---
- name: Update apt cache (Debian derivatives)
become: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably also needs become_user: root because the role may already be running under become: true, become_user: someone_else.

@kysrpex
Copy link
Contributor Author

kysrpex commented Dec 15, 2023

I have thought about this for a few days, and I still think this is a bad idea and I want to close the PR. This approach simply does not scale, be it because of the different requirements or more importantly, because this discussion would need to take place for every Ansible role that exists.

I think this should be managed either by Ansible itself or by role that checks what roles are imported in a play or lets you install packages for specific roles. In the latter case, a list of the packages each role depends on can be maintained in group_vars/all.yml. I tried making a proof of concept of such a role and while it has shortcomings, it would still work much better at scale.

@kysrpex kysrpex closed this Dec 15, 2023
kysrpex added a commit to kysrpex/usegalaxy-eu-ansible that referenced this pull request Dec 15, 2023
…rently

It is a time sink and very annoying to have to re-run playbooks until no more "command not found" errors appear because of forgetting to install role dependencies (meaning system packages, not other roles). See issue galaxyproject/ansible-gxadmin#3 for an example of someone complaining about this recurring problem.

I thought of creating a role called "usegalaxy_eu.packages" that alleviates this problem. The idea is to define a list of the packages each role depends on in group_vars/all.yml (see the example below), then have the role check what other roles are imported in a play and install the corresponding dependencies.

```yaml
# Ansible role package dependencies (managed by usegalaxy_eu.packages)
packages:
  usegalaxy_eu.handy.os_setup:
    - findutils
  galaxyproject.gxadmin:
    - git
    - make
    - "postgresql{{ '-client' if ansible_os_family == 'Debian' }}"
  usegalaxy-eu.bashrc:
    - python3-psycopg2
    - python3-pyyaml
```

The idea to create this role stems just from stumbling upon the problem. See galaxyproject/ansible-gxadmin#11 for an additional discussion on the topic.
@kysrpex kysrpex deleted the install_dependencies branch December 15, 2023 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants