Comcast / ansible-sdkman

An Ansible role that installs, configures, and manages SDKMAN
https://galaxy.ansible.com/Comcast/sdkman/
Apache License 2.0
58 stars 28 forks source link

Feature: Update Alternatives #43

Closed danielpoonwj closed 5 years ago

danielpoonwj commented 5 years ago

Purpose

One of the limitations of SDKMAN is that it requires an interactive shell to work. Or through manually sourcing the initialization script and setting various environment variables.

For example, this makes it difficult to work with a systemd service that uses Java. A common approach around this is to use update-alternatives to manage linking Java installations to /usr/bin/java. Under the hood, it is managing symlinks from /usr/bin/java to various alternatives.

Note that this does not directly interface with SDKMAN, but helps candidates installed via SDKMAN to be accessed more easily.

Approach

This PR uses the Ansible alternatives module to accomplish this. Multiple entries can be set within the sdkman_update_alternatives list, defining for example:

- candidate: java
  name: java
  link: /usr/bin/java
- candidate: java
  name: javac
  link: /usr/bin/javac

This allows access to the java and javac binaries in the default Java version via /usr/bin/java and /usr/bin/javac respectively. Note that they are referencing the same candidate but different names, as java and javac are installed via the SDKMAN java candidate.

Compatibility Caveats

elliotweiser commented 5 years ago

@danielpoonwj Can you document example usage in the README? There's already some sample YAML that you can append to.

danielpoonwj commented 5 years ago

@elliotweiser thanks for your feedback! i've made the requested changes

elliotweiser commented 5 years ago

Great work @danielpoonwj! I'm really psyched to see this role getting more usage and that the feature list is growing. I'll merge and release this ASAP. Thanks for your contributions!

danielpoonwj commented 5 years ago

Thanks @elliotweiser! This role has been a great addition to our provisioning and deployment processes. I definitely hope to continue contributing as we use this more extensively moving forward