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

Check installed sbt version, install in /usr/local, retry on downloads #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 67 additions & 9 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,73 @@
- name: Create /opt/src
file: path=/opt/src state=directory recurse=yes

- name: Create lib dir
file: path={{sbt_lib_path_target}} state=directory recurse=yes
- name: Check installed sbt version
command: "'{{ sbt_link_target }}' -no-colors sbtVersion"
ignore_errors: yes
args:
strip_empty_ends: yes
register: sbt_version_check_result

- name: Download sbt v{{sbt_version}}
get_url: url={{sbt_download_url}}
dest=/opt/src/{{sbt_archive_file}}
- set_fact:
installed_sbt_version: ""

- name: Unpack sbt
unarchive: src=/opt/src/{{sbt_archive_file}} dest={{sbt_lib_path_target}} copy=no
- debug:
msg: "sbt_version_check_result.stdout={{ sbt_version_check_result.stdout }}"
when: sbt_version_check_result.rc == 0

- name: Link sbt
file: state=link src={{sbt_lib_path_target}}/sbt/bin/sbt dest={{sbt_link_target}}
- set_fact:
installed_sbt_version: "{{ sbt_version_check_result.stdout | regex_search('(?<= )[0-9]+[.][0-9]+[.][0-9]+$') }}"
when: sbt_version_check_result.rc == 0

- set_fact:
correct_version_of_sbt_already_installed: "{{ installed_sbt_version == sbt_version }}"

- debug:
msg:
- "installed_sbt_version={{ installed_sbt_version }}"
- "sbt version we want to install: {{ sbt_version }}"
- "correct_version_of_sbt_already_installed={{ correct_version_of_sbt_already_installed }}"

- block:
- name: Create lib dir
file:
path: "{{sbt_lib_path_target}}"
state: directory
recurse: yes

- name: Download sbt v{{sbt_version}}
get_url:
url: "{{sbt_download_url}} "
dest: "/opt/src/{{sbt_archive_file}}"
checksum: "{{ sbt_archive_checksum }}"

- name: Unpack sbt
unarchive:
src: "/opt/src/{{sbt_archive_file}}"
dest: "{{sbt_lib_path_target}}"
copy: no

- name: Link sbt
file:
state: link
src: "{{sbt_lib_path_target}}/sbt/bin/sbt"
dest: "{{sbt_link_target}}"

- name: Validate installed sbt version
command: "'{{ sbt_link_target }}' -no-colors sbtVersion"
register: sbt_version_validation
retries: 5
delay: 10
until: sbt_version_validation is not failed

- set_fact:
finally_installed_sbt_version: "{{ sbt_version_validation.stdout | regex_search('(?<= )[0-9]+[.][0-9]+[.][0-9]+$') }}"

- debug:
msg: "finally_installed_sbt_version={{ finally_installed_sbt_version }}"

- assert:
that:
- finally_installed_sbt_version == sbt_version

when: not correct_version_of_sbt_already_installed
12 changes: 7 additions & 5 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
sbt_playbook_version: "0.2.0"
sbt_version: "0.13.7"
sbt_version: "0.13.18"
sbt_archive_name: "sbt-{{sbt_version}}"
sbt_archive_file: "{{sbt_archive_name}}.tgz"
sbt_download_url: "https://dl.bintray.com/sbt/native-packages/sbt/{{sbt_version}}/{{sbt_archive_file}}"

sbt_lib_path: "/usr/share/sbt"
sbt_url_prefix: "https://github.com/sbt/sbt/releases/download"
sbt_download_url: "{{ sbt_url_prefix }}/v{{ sbt_version }}/{{ sbt_archive_file }}"
sbt_archive_checksum: "sha256:afe82322ca8e63e6f1e10fc1eb515eb7dc6c3e5a7f543048814072a03d83b331"
sbt_install_prefix: /usr/local
sbt_lib_path: "{{ sbt_install_prefix }}/share/sbt"
sbt_lib_path_target: "{{sbt_lib_path}}/{{sbt_version}}"
sbt_link_target: "/usr/bin/sbt"
sbt_link_target: "{{ sbt_install_prefix }}/bin/sbt"