commit 904dc01e5a31c4b95342a9ce50a17a150fe8adbc Author: Guillaume Dott Date: Mon Apr 18 01:40:27 2022 +0200 First commit diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..0eca706 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,4 @@ +--- +ruby_version: 3.0.2 +ruby_install_version: 0.8.2 +chruby_version: 0.3.9 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..6bbba58 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,82 @@ +--- +- name: Install ruby-install dependencies + apt: + name: + - bash + - grep + - curl + - tar + - bzip2 + - patch + - build-essential + +- name: Check if ruby-install is installed + shell: which ruby-install && ruby-install --version + register: ruby_install_check + failed_when: false + changed_when: "ruby_install_check.stdout.find('ruby-install: ' + ruby_install_version) == -1" + +- when: "ruby_install_check.stdout.find('ruby-install: ' + ruby_install_version) == -1" + block: + - name: Download ruby-install + get_url: + url: https://github.com/postmodern/ruby-install/archive/refs/tags/v{{ ruby_install_version }}.tar.gz + dest: /tmp/ruby-install-v{{ ruby_install_version }}.tar.gz + + - name: Extract ruby-install + unarchive: + src: /tmp/ruby-install-v{{ ruby_install_version }}.tar.gz + dest: /tmp/ + copy: no + + - name: Install ruby-install + become: yes + command: + chdir: /tmp/ruby-install-{{ ruby_install_version }} + cmd: make install + +- name: Check if chruby is installed + shell: which chruby-exec && chruby-exec --version + register: chruby_check + failed_when: false + changed_when: "chruby_check.stdout.find('chruby version ' + chruby_version) == -1" + +- when: "chruby_check.stdout.find('chruby version ' + chruby_version) == -1" + block: + - name: Download chruby + get_url: + url: https://github.com/postmodern/chruby/archive/refs/tags/v{{ chruby_version }}.tar.gz + dest: /tmp/chruby-v{{ chruby_version }}.tar.gz + + - name: Extract chruby + unarchive: + src: /tmp/chruby-v{{ chruby_version }}.tar.gz + dest: /tmp/ + copy: no + + - name: Install chruby + become: yes + command: + chdir: /tmp/chruby-{{ chruby_version }} + cmd: make install + + - name: Setup chruby + become: yes + command: + chdir: /tmp/chruby-{{ chruby_version }} + cmd: ./scripts/setup.sh + +- name: Check if ruby is installed + shell: test -x /opt/rubies/ruby-{{ ruby_version }}/bin/ruby && /opt/rubies/ruby-{{ ruby_version }}/bin/ruby --version + register: ruby_check + failed_when: false + changed_when: ruby_check.rc != 0 + +- name: Set fact for ruby installation + set_fact: + ruby_installed: "{{ ruby_check.rc != 0 }}" + +- name: Install ruby + become: yes + command: ruby-install ruby {{ ruby_version }} + when: ruby_installed