diff --git a/tasks/main.yml b/tasks/main.yml index 075a013..01551b1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 diff --git a/vars/main.yml b/vars/main.yml index 9daddbb..b8c25f6 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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" \ No newline at end of file +sbt_link_target: "{{ sbt_install_prefix }}/bin/sbt"