From cf8ac7736c3d17ff4182fa82bfce1bcf5a10478c Mon Sep 17 00:00:00 2001 From: Nick Janetakis Date: Sat, 3 May 2014 13:42:45 -0400 Subject: [PATCH] Initial commit --- .gitignore | 6 ++++++ README.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++ defaults/main.yml | 5 +++++ meta/main.yml | 17 +++++++++++++++ tasks/main.yml | 46 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fab7220 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.DS_Store +*/**.DS_Store +._* +.*.sw* +*~ +.idea/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..aaf3061 --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +## What is ansible-ruby? + +It is an [Ansible](http://www.ansible.com/home) role to install a specific version of ruby without having to compile ruby on the machine you're setting up. It does this by using rvm under the hood. + +### What problem does it solve and why is it useful? + +I wasn't happy with any of the solutions that existed because they required you to either compile ruby on your server or they were not idempotent. Compiling ruby on a low end VPS/instance could easily take 10 minutes and during that time your CPU is going to be pegged at 100%. + +ansible-ruby solves this by using rvm to install 1 or more versions of ruby. It makes installing and upgrading ruby versions very easy. + +## 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. + +``` +ruby_version: 2.1.1 # X.X.X-pXXX format + +ruby_temp_download_path: /usr/local/src +ruby_rvm_install_path: /usr/local/rvm +``` + +## Example playbook + +For the sake of this mini example let's assume you have a group called **app** and you have a typical `site.yml` file. + +To use this role edit your `site.yml` file to look something like this: + +``` +--- +- name: ensure app servers are configured +- hosts: app + + roles: + - { role: nickjj.ruby, tags: ruby } +``` + +Let's say you want to edit the default version, you can do this by opening or creating `yourplaybook/group_vars/app.yml` and then making it look something like this: + +``` +--- +ruby_version: 2.0.0 +``` + +## Installation + +`$ ansible-galaxy install nickjj.ruby` + +## Requirements + +Tested on ubuntu 12.04 LTS but it should work on other versions that are similar. + +## License + +MIT \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..298529f --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,5 @@ +--- +ruby_version: 2.1.1 # X.X.X-pXXX format + +ruby_temp_download_path: /usr/local/src +ruby_rvm_install_path: /usr/local/rvm \ No newline at end of file diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..d5692f7 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,17 @@ +--- +galaxy_info: + author: Nick Janetakis + description: Install a specific version of ruby using rvm. + company: + license: license (MIT) + min_ansible_version: 1.5 + + platforms: + - name: Ubuntu + versions: + - all + + categories: + - development + +dependencies: [] \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..9113726 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,46 @@ +--- +- name: detect rvm installation + stat: path=/etc/profile.d/rvm.sh + register: rvm_installation + +- name: ensure rvm installer is downloaded + get_url: + url: https://get.rvm.io + dest: "{{ ruby_temp_download_path }}/rvm-installer.sh" + when: not rvm_installation.stat.exists + +- name: ensure rvm installer is configured + file: + path: "{{ ruby_temp_download_path }}/rvm-installer.sh" + mode: 0755 + when: not rvm_installation.stat.exists + +- name: ensure rvm stable is installed + command: "{{ ruby_temp_download_path }}/rvm-installer.sh --path {{ ruby_rvm_install_path }} stable" + when: not rvm_installation.stat.exists + +- name: ensure rvm installer is deleted + file: + path: "{{ ruby_temp_download_path }}/rvm-installer.sh" + state: absent + when: not rvm_installation.stat.exists + +- name: ensure rvm installs ruby dependencies + command: "{{ ruby_rvm_install_path }}/bin/rvm autolibs 3" + when: not rvm_installation.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_path }}/bin/rvm install ruby-{{ ruby_version }}" + when: not installed_ruby_version.stat.exists + +- name: detect default ruby version + command: /usr/local/rvm/bin/rvm alias list default + register: ruby_selected + +- name: ensure default ruby is selected + 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