Skip to content

Instantly share code, notes, and snippets.

@drewda
Created November 6, 2013 19:57
Show Gist options
  • Save drewda/7343078 to your computer and use it in GitHub Desktop.
Save drewda/7343078 to your computer and use it in GitHub Desktop.
Installing ruby/rbenv with Ansible
# from http://mmoya.org/blog/2013/02/22/installing-rubyrbenv-with-ansible/
# based on https://gist.github.com/v1nc3ntlaw/1441139#file-rbenv-install-system-wide-sh
---
- hosts: all
vars:
- rbenv_root: /usr/local/rbenv
- ruby_version: 1.9.3-p385
tasks:
- name: rbenv | install build depends
apt: pkg=$item state=latest install_recommends=no
with_items:
- build-essential
- git
- libcurl4-openssl-dev
- libmysqlclient-dev
- libreadline5-dev
- libssl-dev
- libxml2-dev
- libxslt1-dev
- zlib1g-dev
- name: rbenv | update rbenv repo
git: repo=git://github.com/sstephenson/rbenv.git dest=$rbenv_root version=v0.4.0
- name: rbenv | add rbenv to path
file: path=/usr/local/bin/rbenv src=${rbenv_root}/bin/rbenv state=link
- name: rbenv | add rbenv initialization to profile
template: src=templates/rbenv.sh.j2 dest=/etc/profile.d/rbenv.sh owner=root group=root mode=0755
- name: rbenv | check ruby-build installed
command: test -x /usr/local/bin/ruby-build
register: rbuild_present
ignore_errors: yes
- name: rbenv | create temporary directory
command: mktemp -d
register: tempdir
when_failed: $rbuild_present
- name: rbenv | clone ruby-build repo
git: repo=git://github.com/sstephenson/ruby-build.git dest=${tempdir.stdout}/ruby-build
when_failed: $rbuild_present
- name: rbenv | install ruby-build
command: ./install.sh chdir=${tempdir.stdout}/ruby-build
when_failed: $rbuild_present
- name: rbenv | remove temporary directory
file: path=${tempdir.stdout} state=absent
when_failed: $rbuild_present
- name: rbenv | check ruby $ruby_version installed
shell: RBENV_ROOT=${rbenv_root} rbenv versions | grep $ruby_version
register: ruby_installed
ignore_errors: yes
- name: rbenv | install ruby $ruby_version
shell: RBENV_ROOT=${rbenv_root} rbenv install $ruby_version
when_failed: $ruby_installed
- name: rbenv | set global ruby $ruby_version
shell: RBENV_ROOT=${rbenv_root} rbenv global $ruby_version
when_failed: $ruby_installed
- name: rbenv | rehash
shell: RBENV_ROOT=${rbenv_root} rbenv rehash
when_failed: $ruby_installed
- name: rbenv | set gemrc
copy: src=files/gemrc dest=/root/.gemrc owner=root group=root mode=0644
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment