Expose popular ruby paths and refactor a bit
This commit is contained in:
16
.travis.yml
16
.travis.yml
@@ -1,16 +1,16 @@
|
|||||||
---
|
---
|
||||||
language: "python"
|
language: 'python'
|
||||||
python: "2.7"
|
python: '2.7'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- SITE_AND_INVENTORY="tests/test.yml -i tests/inventory"
|
- SITE_AND_INVENTORY='tests/test.yml -i tests/inventory'
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- "__rvm_unload ; rm -rf ~/.rvm"
|
- '__rvm_unload ; rm -rf ~/.rvm'
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- "pip install ansible==1.6.2"
|
- 'pip install ansible==1.6.2'
|
||||||
- "printf '[defaults]\nroles_path = ../' > ansible.cfg"
|
- 'printf "[defaults]\nroles_path = ../" > ansible.cfg'
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- >
|
- >
|
||||||
@@ -18,8 +18,8 @@ script:
|
|||||||
| grep -q 'ruby'
|
| grep -q 'ruby'
|
||||||
&& (echo 'No ruby test: pass' && exit 1)
|
&& (echo 'No ruby test: pass' && exit 1)
|
||||||
|| (echo 'No ruby test: fail' && exit 0)
|
|| (echo 'No ruby test: fail' && exit 0)
|
||||||
- "ansible-playbook $SITE_AND_INVENTORY --syntax-check"
|
- 'ansible-playbook $SITE_AND_INVENTORY --syntax-check'
|
||||||
- "ansible-playbook $SITE_AND_INVENTORY --connection=local -vvvv"
|
- 'ansible-playbook $SITE_AND_INVENTORY --connection=local -vvvv'
|
||||||
- >
|
- >
|
||||||
ansible-playbook $SITE_AND_INVENTORY --connection=local
|
ansible-playbook $SITE_AND_INVENTORY --connection=local
|
||||||
| grep -q 'changed=0.*failed=0'
|
| grep -q 'changed=0.*failed=0'
|
||||||
|
|||||||
42
README.md
42
README.md
@@ -1,6 +1,6 @@
|
|||||||
## What is ansible-ruby? [](http://travis-ci.org/nickjj/ansible-ruby)
|
## What is ansible-ruby? [](http://travis-ci.org/nickjj/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.
|
It is an [ansible](http://www.ansible.com/home) role to install and manage ruby versions using rvm.
|
||||||
|
|
||||||
### What problem does it solve and why is it useful?
|
### What problem does it solve and why is it useful?
|
||||||
|
|
||||||
@@ -14,17 +14,18 @@ Below is a list of default values along with a description of what they do.
|
|||||||
|
|
||||||
```
|
```
|
||||||
# Set the version of ruby you want to install.
|
# Set the version of ruby you want to install.
|
||||||
ruby_version: 2.1.2 # X.X.X-pXXX format
|
# # X.X.X-pXXX format.
|
||||||
|
ruby_version: '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_temp_download_path: /usr/local/src
|
ruby_rvm_temp_download_path: '/usr/local/src'
|
||||||
|
|
||||||
# Where should rvm be installed to?
|
# Where should rvm be installed to?
|
||||||
ruby_rvm_install_path: /usr/local/rvm
|
ruby_rvm_install_path: '/usr/local/rvm'
|
||||||
|
|
||||||
# Which url or local path contains the rvm-installer script?
|
# Which url or local path contains the rvm-installer script?
|
||||||
# If you use a url, it must include http:// or https:// at the start.
|
# If you use a url, it must include http:// or https:// at the start.
|
||||||
ruby_rvm_latest_installer: https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer
|
ruby_rvm_latest_installer: 'https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer'
|
||||||
|
|
||||||
# Which url or value contains the stable version number of rvm?
|
# Which url or value contains the stable version number of rvm?
|
||||||
# If you use a url, it must include http:// or https:// at the start.
|
# If you use a url, it must include http:// or https:// at the start.
|
||||||
@@ -32,11 +33,36 @@ ruby_rvm_latest_installer: https://raw.githubusercontent.com/wayneeseguin/rvm/ma
|
|||||||
|
|
||||||
# If you want to lock rvm to a specific version you could enter in the version number
|
# If you want to lock rvm to a specific version you could enter in the version number
|
||||||
# that you have installed and the role would assume you always have the latest stable version.
|
# that you have installed and the role would assume you always have the latest stable version.
|
||||||
ruby_rvm_stable_version_number: https://raw.githubusercontent.com/wayneeseguin/rvm/master/VERSION
|
ruby_rvm_stable_version_number: 'https://raw.githubusercontent.com/wayneeseguin/rvm/master/VERSION'
|
||||||
|
|
||||||
# Force upgrade the rvm-installer to the latest installer.
|
# Force upgrade the rvm-installer to the latest version.
|
||||||
ruby_rvm_force_upgrade_installer: false
|
ruby_rvm_force_upgrade_installer: false
|
||||||
```
|
|
||||||
|
## Exposed variables for use in other roles
|
||||||
|
|
||||||
|
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_rvm`:
|
||||||
|
- The path to the rvm binary
|
||||||
|
|
||||||
|
- `ruby_rvm_default_wrappers`:
|
||||||
|
- The path containing all of the wrapped ruby related binaries
|
||||||
|
|
||||||
|
- `ruby`:
|
||||||
|
- The path to the ruby binary
|
||||||
|
|
||||||
|
- `ruby_gem`:
|
||||||
|
- The path to the gem binary
|
||||||
|
|
||||||
|
- `ruby_bundle`:
|
||||||
|
- The path to the bundle binary
|
||||||
|
|
||||||
|
- `ruby_rake`:
|
||||||
|
- The path to the rake binary with bundle exec already applied
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
If you wanted to run a database migration in rails you would use `{{ ruby_rake }} db:migrate`.
|
||||||
|
|
||||||
## Example playbook
|
## Example playbook
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
---
|
---
|
||||||
ruby_version: 2.1.2 # X.X.X-pXXX format
|
ruby_version: '2.1.2'
|
||||||
|
|
||||||
ruby_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'
|
||||||
|
ruby_rvm_latest_installer: 'https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer'
|
||||||
ruby_rvm_latest_installer: https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer
|
ruby_rvm_stable_version_number: 'https://raw.githubusercontent.com/wayneeseguin/rvm/master/VERSION'
|
||||||
ruby_rvm_stable_version_number: https://raw.githubusercontent.com/wayneeseguin/rvm/master/VERSION
|
|
||||||
|
|
||||||
ruby_rvm_force_upgrade_installer: false
|
ruby_rvm_force_upgrade_installer: false
|
||||||
ruby_rvm_skip_upgrade: false
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
galaxy_info:
|
galaxy_info:
|
||||||
author: Nick Janetakis
|
author: Nick Janetakis
|
||||||
description: Install a specific version of ruby using rvm.
|
description: The official rvm role to install and manage your ruby versions.
|
||||||
company:
|
company:
|
||||||
license: license (MIT)
|
license: license (MIT)
|
||||||
min_ansible_version: 1.5
|
min_ansible_version: 1.5
|
||||||
|
|||||||
@@ -1,64 +1,64 @@
|
|||||||
---
|
---
|
||||||
- name: detect rvm binary
|
- name: detect rvm binary
|
||||||
stat: path={{ ruby_rvm_install_path }}/bin/rvm
|
stat: path='{{ ruby_rvm }}'
|
||||||
register: rvm_binary
|
register: rvm_binary
|
||||||
|
|
||||||
- name: detect rvm installer
|
- name: detect rvm installer
|
||||||
stat: path={{ ruby_temp_download_path }}/rvm-installer.sh
|
stat: path='{{ ruby_rvm_temp_download_path }}/rvm-installer.sh'
|
||||||
register: rvm_installer
|
register: rvm_installer
|
||||||
|
|
||||||
- name: detect current rvm version
|
- name: detect current rvm version
|
||||||
command: "{{ ruby_rvm_install_path }}/bin/rvm version"
|
command: '{{ ruby_rvm }} version'
|
||||||
changed_when: false
|
changed_when: false
|
||||||
register: rvm_current_version
|
register: rvm_current_version
|
||||||
when: rvm_binary.stat.exists
|
when: rvm_binary.stat.exists
|
||||||
|
|
||||||
- name: detect stable rvm version from url
|
- name: detect stable rvm version from url
|
||||||
uri: url={{ ruby_rvm_stable_version_number }} return_content=yes
|
uri: url='{{ ruby_rvm_stable_version_number }} return_content=yes'
|
||||||
register: rvm_stable_version_number
|
register: rvm_stable_version_number
|
||||||
when: "'://' in ruby_rvm_stable_version_number"
|
when: '"://" in ruby_rvm_stable_version_number'
|
||||||
|
|
||||||
- name: ensure rvm installer is copied from url
|
- name: ensure rvm installer is copied from url
|
||||||
get_url:
|
get_url:
|
||||||
url: "{{ ruby_rvm_latest_installer }}"
|
url: '{{ ruby_rvm_latest_installer }}'
|
||||||
dest: "{{ ruby_temp_download_path }}/rvm-installer.sh"
|
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"
|
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
|
- name: ensure rvm installer is copied from local file
|
||||||
copy: src="{{ ruby_rvm_latest_installer }}" dest="{{ ruby_temp_download_path }}/rvm-installer.sh"
|
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
|
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
|
- name: ensure rvm installer is configured
|
||||||
file:
|
file:
|
||||||
path: "{{ ruby_temp_download_path }}/rvm-installer.sh"
|
path: "{{ ruby_rvm_temp_download_path }}/rvm-installer.sh"
|
||||||
mode: 0755
|
mode: 0755
|
||||||
when: not rvm_binary.stat.exists or ruby_rvm_force_upgrade_installer
|
when: not rvm_binary.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_rvm_temp_download_path }}/rvm-installer.sh --path {{ ruby_rvm_install_path }} stable'
|
||||||
when: not rvm_binary.stat.exists
|
when: not rvm_binary.stat.exists
|
||||||
|
|
||||||
- name: ensure rvm is upgraded
|
- name: ensure rvm is upgraded
|
||||||
shell: "{{ ruby_rvm_install_path }}/bin/rvm get stable && {{ ruby_rvm_install_path }}/bin/rvm reload"
|
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]
|
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
|
- name: ensure rvm installs ruby dependencies
|
||||||
command: "{{ ruby_rvm_install_path }}/bin/rvm autolibs 3"
|
command: '{{ ruby_rvm }} autolibs 3'
|
||||||
when: not rvm_binary.stat.exists
|
when: not rvm_binary.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 }}'
|
||||||
register: installed_ruby_version
|
register: installed_ruby_version
|
||||||
|
|
||||||
- name: ensure ruby is installed
|
- name: ensure ruby is installed
|
||||||
command: "{{ ruby_rvm_install_path }}/bin/rvm install ruby-{{ ruby_version }}"
|
command: '{{ ruby_rvm }} install ruby-{{ ruby_version }}'
|
||||||
when: not installed_ruby_version.stat.exists
|
when: not installed_ruby_version.stat.exists
|
||||||
|
|
||||||
- name: detect default ruby version
|
- name: detect default ruby version
|
||||||
command: "{{ ruby_rvm_install_path }}/bin/rvm alias list default"
|
command: '{{ ruby_rvm }} alias list default'
|
||||||
changed_when: false
|
changed_when: false
|
||||||
register: ruby_selected
|
register: ruby_selected
|
||||||
|
|
||||||
- name: ensure default ruby is selected
|
- name: ensure default ruby is selected
|
||||||
command: "{{ ruby_rvm_install_path }}/bin/rvm alias create default ruby-{{ ruby_version }}"
|
command: '{{ ruby_rvm }} alias create default ruby-{{ ruby_version }}'
|
||||||
when: ruby_selected.stdout == '' or ruby_version not in ruby_selected.stdout
|
when: ruby_selected.stdout == '' or ruby_version not in ruby_selected.stdout
|
||||||
|
|||||||
7
vars/main.yml
Normal file
7
vars/main.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
ruby_rvm: '{{ ruby_rvm_install_path }}/bin/rvm'
|
||||||
|
ruby_rvm_default_wrappers: '{{ ruby_rvm_install_path }}/wrappers/default'
|
||||||
|
ruby: '{{ ruby_rvm_default_wrappers }}/ruby'
|
||||||
|
ruby_gem: '{{ ruby_rvm_default_wrappers }}/gem'
|
||||||
|
ruby_bundle: '{{ ruby_rvm_default_wrappers }}/bundle'
|
||||||
|
ruby_rake: '{{ ruby_bundle }} exec {{ ruby_rvm_default_wrappers }}/rake'
|
||||||
Reference in New Issue
Block a user