Support installing multiple rubies in 1 run and refactor a bit

This commit is contained in:
Nick Janetakis
2014-07-01 13:31:01 -04:00
parent b71810ebca
commit 797739c17c
6 changed files with 82 additions and 67 deletions

View File

@@ -13,9 +13,11 @@ ansible-ruby solves this by using rvm to install 1 or more versions of ruby. It
Below is a list of default values along with a description of what they do. Below is a list of default values along with a description of what they do.
``` ```
# Set the version of ruby you want to install. # Install 1 or more versions of ruby, just add them to the list.
# # X.X.X-pXXX format. # The last version listed will be set as the default ruby.
ruby_version: '2.1.2' # Change it to `ruby_rubies:` if you want no rubies installed.
ruby_rubies:
- 'ruby-2.1.2'
# Where should the rvm-installer and other temp files be downloaded to? # Where should the rvm-installer and other temp files be downloaded to?
ruby_rvm_temp_download_path: '/usr/local/src' ruby_rvm_temp_download_path: '/usr/local/src'
@@ -43,6 +45,9 @@ ruby_rvm_force_upgrade_installer: false
You will likely want to use various ruby related commands in other roles. This role exposes a number of popular paths for easy access. You will likely want to use various ruby related commands in other roles. This role exposes a number of popular paths for easy access.
- `ruby_default_ruby_version`
- The default ruby version that is selected
- `ruby_rvm` - `ruby_rvm`
- The path to the rvm binary - The path to the rvm binary

View File

@@ -1,5 +1,6 @@
--- ---
ruby_version: '2.1.2' ruby_rubies:
- 'ruby-2.1.2'
ruby_rvm_temp_download_path: '/usr/local/src' ruby_rvm_temp_download_path: '/usr/local/src'
ruby_rvm_install_path: '/usr/local/rvm' ruby_rvm_install_path: '/usr/local/rvm'

View File

@@ -1,64 +1,3 @@
--- ---
- name: detect rvm binary - include: 'rvm.yml'
stat: path='{{ ruby_rvm }}' - include: 'rubies.yml'
register: rvm_binary
- name: detect rvm installer
stat: path='{{ ruby_rvm_temp_download_path }}/rvm-installer.sh'
register: rvm_installer
- name: detect current rvm version
command: '{{ ruby_rvm }} version'
changed_when: false
register: rvm_current_version
when: rvm_binary.stat.exists
- name: detect stable rvm version from url
uri: url='{{ ruby_rvm_stable_version_number }}' return_content=yes
register: rvm_stable_version_number
when: '"://" in ruby_rvm_stable_version_number'
- name: ensure rvm installer is copied from url
get_url:
url: '{{ ruby_rvm_latest_installer }}'
dest: '{{ ruby_rvm_temp_download_path }}/rvm-installer.sh'
when: '"://" in ruby_rvm_latest_installer and not rvm_installer.stat.exists or ruby_rvm_force_upgrade_installer'
- name: ensure rvm installer is copied from local file
copy: src='{{ ruby_rvm_latest_installer }}' dest='{{ ruby_rvm_temp_download_path }}/rvm-installer.sh'
when: not '://' in ruby_rvm_latest_installer and not rvm_installer.stat.exists or ruby_rvm_force_upgrade_installer
- name: ensure rvm installer is configured
file:
path: "{{ ruby_rvm_temp_download_path }}/rvm-installer.sh"
mode: 0755
when: not rvm_binary.stat.exists or ruby_rvm_force_upgrade_installer
- name: ensure rvm stable is installed
command: '{{ ruby_rvm_temp_download_path }}/rvm-installer.sh --path {{ ruby_rvm_install_path }} stable'
when: not rvm_binary.stat.exists
- name: ensure rvm is upgraded
shell: '{{ ruby_rvm }} get stable && {{ ruby_rvm }} reload'
when: rvm_binary.stat.exists and rvm_stable_version_number.content|default(ruby_rvm_stable_version_number)|replace('\n', '') > rvm_current_version.stdout.split()[1]
- name: ensure rvm installs ruby dependencies
command: '{{ ruby_rvm }} autolibs 3'
when: not rvm_binary.stat.exists
- name: detect if ruby version is installed
stat: path='{{ ruby_rvm_install_path }}/rubies/ruby-{{ ruby_version }}'
register: installed_ruby_version
- name: ensure ruby is installed
command: '{{ ruby_rvm }} install ruby-{{ ruby_version }}'
when: not installed_ruby_version.stat.exists
- name: detect default ruby version
command: '{{ ruby_rvm }} alias list default'
changed_when: false
register: ruby_selected
- name: ensure default ruby is selected
command: '{{ ruby_rvm }} alias create default ruby-{{ ruby_version }}'
when: ruby_selected.stdout == '' or ruby_version not in ruby_selected.stdout

22
tasks/rubies.yml Normal file
View File

@@ -0,0 +1,22 @@
---
- name: detect if rubies are installed
command: '{{ ruby_rvm }} {{ item }} do true'
changed_when: false
failed_when: false
register: detect_rubies
with_items: ruby_rubies
when: ruby_rubies
- name: ensure rubies are installed
command: '{{ ruby_rvm }} install {{ item.item }}'
when: ruby_rubies and item.rc != 0
with_items: detect_rubies.results
- name: detect default ruby version
command: '{{ ruby_rvm }} alias list default'
changed_when: false
register: detect_default_ruby_version
- name: ensure default ruby is selected
command: '{{ ruby_rvm }} alias create default {{ ruby_default_ruby_version }}'
when: detect_default_ruby_version.stdout == '' or ruby_default_ruby_version not in detect_default_ruby_version.stdout

47
tasks/rvm.yml Normal file
View File

@@ -0,0 +1,47 @@
---
- name: detect rvm binary
stat: path='{{ ruby_rvm }}'
register: rvm_binary
- name: detect rvm installer
stat: path='{{ ruby_rvm_temp_download_path }}/rvm-installer.sh'
register: rvm_installer
- name: detect current rvm version
command: '{{ ruby_rvm }} version'
changed_when: false
register: rvm_current_version
when: rvm_binary.stat.exists
- name: detect stable rvm version from url
uri: url='{{ ruby_rvm_stable_version_number }}' return_content=yes
register: rvm_stable_version_number
when: '"://" in ruby_rvm_stable_version_number'
- name: ensure rvm installer is copied from url
get_url:
url: '{{ ruby_rvm_latest_installer }}'
dest: '{{ ruby_rvm_temp_download_path }}/rvm-installer.sh'
when: '"://" in ruby_rvm_latest_installer and not rvm_installer.stat.exists or ruby_rvm_force_upgrade_installer'
- name: ensure rvm installer is copied from local file
copy: src='{{ ruby_rvm_latest_installer }}' dest='{{ ruby_rvm_temp_download_path }}/rvm-installer.sh'
when: not '://' in ruby_rvm_latest_installer and not rvm_installer.stat.exists or ruby_rvm_force_upgrade_installer
- name: ensure rvm installer is configured
file:
path: "{{ ruby_rvm_temp_download_path }}/rvm-installer.sh"
mode: 0755
when: not rvm_binary.stat.exists or ruby_rvm_force_upgrade_installer
- name: ensure rvm stable is installed
command: '{{ ruby_rvm_temp_download_path }}/rvm-installer.sh --path {{ ruby_rvm_install_path }} stable'
when: not rvm_binary.stat.exists
- name: ensure rvm is upgraded
shell: '{{ ruby_rvm }} get stable && {{ ruby_rvm }} reload'
when: rvm_binary.stat.exists and rvm_stable_version_number.content | default(ruby_rvm_stable_version_number) | replace('\n', '') > rvm_current_version.stdout.split()[1]
- name: ensure rvm installs ruby dependencies
command: '{{ ruby_rvm }} autolibs 3'
when: not rvm_binary.stat.exists

View File

@@ -1,4 +1,5 @@
--- ---
ruby_default_ruby_version: '{{ ruby_rubies | last if ruby_rubies and ruby_rubies is iterable else "" }}'
ruby_rvm: '{{ ruby_rvm_install_path }}/bin/rvm' ruby_rvm: '{{ ruby_rvm_install_path }}/bin/rvm'
ruby_rvm_default_wrappers: '{{ ruby_rvm_install_path }}/wrappers/default' ruby_rvm_default_wrappers: '{{ ruby_rvm_install_path }}/wrappers/default'
ruby: '{{ ruby_rvm_default_wrappers }}/ruby' ruby: '{{ ruby_rvm_default_wrappers }}/ruby'