Add autograde feature for rvm and keep the installer script locally

This commit is contained in:
Nick Janetakis
2014-06-02 19:30:32 -04:00
parent d89fa3434c
commit a9e88356f5
3 changed files with 39 additions and 14 deletions

View File

@@ -10,13 +10,24 @@ ansible-ruby solves this by using rvm to install 1 or more versions of ruby. It
## Role variables ## Role variables
The only variable you need to concern yourself about is `ruby_version` if you're happy with the default download and install path. Below is a list of default values along with a description of what they do.
``` ```
# Set the version of ruby you want to install.
ruby_version: 2.1.1 # X.X.X-pXXX format ruby_version: 2.1.1 # X.X.X-pXXX format
# Where should the rvm-installer and other temp files be downloaded to?
ruby_temp_download_path: /usr/local/src ruby_temp_download_path: /usr/local/src
# Where should rvm be installed to?
ruby_rvm_install_path: /usr/local/rvm ruby_rvm_install_path: /usr/local/rvm
# Force upgrade rvm-installer to the latest stable version.
ruby_rvm_force_upgrade_installer: false
# If you are concerned rvm stable might not be stable then
# you can set this to true so that rvm itself never upgrades.
ruby_rvm_skip_upgrade: false
``` ```
## Example playbook ## Example playbook

View File

@@ -2,4 +2,7 @@
ruby_version: 2.1.1 # X.X.X-pXXX format ruby_version: 2.1.1 # X.X.X-pXXX format
ruby_temp_download_path: /usr/local/src ruby_temp_download_path: /usr/local/src
ruby_rvm_install_path: /usr/local/rvm ruby_rvm_install_path: /usr/local/rvm
ruby_rvm_force_upgrade_installer: false
ruby_rvm_skip_upgrade: false

View File

@@ -1,33 +1,44 @@
--- ---
- name: detect rvm installation - name: detect rvm profile
stat: path=/etc/profile.d/rvm.sh stat: path=/etc/profile.d/rvm.sh
register: rvm_installation register: rvm_profile
- name: detect rvm installer
stat: path={{ ruby_temp_download_path }}/rvm-installer.sh
register: rvm_installer
- name: detect current rvm version
shell: "{{ ruby_rvm_install_path }}/bin/rvm version"
register: rvm_current_version
when: rvm_profile.stat.exists
- name: detect latest rvm version
uri: url=https://raw.githubusercontent.com/wayneeseguin/rvm/master/VERSION return_content=yes
register: rvm_latest_version
- name: ensure rvm installer is downloaded - name: ensure rvm installer is downloaded
get_url: get_url:
url: https://get.rvm.io url: https://get.rvm.io
dest: "{{ ruby_temp_download_path }}/rvm-installer.sh" dest: "{{ ruby_temp_download_path }}/rvm-installer.sh"
when: not rvm_installation.stat.exists when: not rvm_installer.stat.exists or ruby_rvm_force_upgrade_installer
- name: ensure rvm installer is configured - name: ensure rvm installer is configured
file: file:
path: "{{ ruby_temp_download_path }}/rvm-installer.sh" path: "{{ ruby_temp_download_path }}/rvm-installer.sh"
mode: 0755 mode: 0755
when: not rvm_installation.stat.exists when: not rvm_profile.stat.exists or ruby_rvm_force_upgrade_installer
- name: ensure rvm stable is installed - name: ensure rvm stable is installed
command: "{{ ruby_temp_download_path }}/rvm-installer.sh --path {{ ruby_rvm_install_path }} stable" command: "{{ ruby_temp_download_path }}/rvm-installer.sh --path {{ ruby_rvm_install_path }} stable"
when: not rvm_installation.stat.exists when: not rvm_profile.stat.exists
- name: ensure rvm installer is deleted - name: ensure rvm is upgraded
file: shell: "{{ ruby_rvm_install_path }}/bin/rvm get stable && {{ ruby_rvm_install_path }}/bin/rvm reload"
path: "{{ ruby_temp_download_path }}/rvm-installer.sh" when: not rvm_latest_version.content[:-1] in rvm_current_version.stdout and rvm_profile.stat.exists and not ruby_rvm_skip_upgrade
state: absent
when: not rvm_installation.stat.exists
- name: ensure rvm installs ruby dependencies - name: ensure rvm installs ruby dependencies
command: "{{ ruby_rvm_install_path }}/bin/rvm autolibs 3" command: "{{ ruby_rvm_install_path }}/bin/rvm autolibs 3"
when: not rvm_installation.stat.exists when: not rvm_profile.stat.exists
- name: detect if ruby version is installed - name: detect if ruby version is installed
stat: path={{ ruby_rvm_install_path }}/rubies/ruby-{{ ruby_version }} stat: path={{ ruby_rvm_install_path }}/rubies/ruby-{{ ruby_version }}
@@ -43,4 +54,4 @@
- name: ensure default ruby is selected - name: ensure default ruby is selected
shell: source /etc/profile.d/rvm.sh && rvm use ruby-{{ ruby_version }} --default executable=/bin/bash shell: source /etc/profile.d/rvm.sh && rvm use ruby-{{ ruby_version }} --default executable=/bin/bash
when: ruby_selected.stdout == '' or ruby_version not in ruby_selected.stdout when: ruby_selected.stdout == '' or ruby_version not in ruby_selected.stdout