Skip to content

Commit

Permalink
rvm: Refactor away from nested vars, make defaults for system & user …
Browse files Browse the repository at this point in the history
…install automatic (since Ansible does not support specific key/value overrides/Mashing like Chef, entire nested hash must be re-defined)
  • Loading branch information
trinitronx committed Aug 28, 2015
1 parent 4995de4 commit 02a6870
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 34 deletions.
12 changes: 4 additions & 8 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ rvm:
url: https://get.rvm.io
temp_installer_path: /tmp/rvm-installer.sh

system_install: true
root: /usr/local/rvm
init_script: /etc/profile.d/rvm.sh

auto_update_rvm: true

default_ruby_version: ruby-2.2.2

# the packages which need for download rvm
required_packages:
- curl
- gnupg2

rvm_install_type: system
rvm_auto_update_rvm: true
rvm_default_ruby_version: ruby-2.2.2
8 changes: 4 additions & 4 deletions tasks/install_ruby.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
- name: installing Ruby as root
command: "{{rvm.root}}/bin/rvm install {{rvm.default_ruby_version}}"
command: "{{rvm_root}}/bin/rvm install {{rvm_default_ruby_version}}"
sudo: true
when: rvm.system_install
when: "'{{ rvm_install_type }}' == 'system'"

- name: installing Ruby as user
command: "{{rvm.root}}/bin/rvm install {{rvm.default_ruby_version}}"
command: "{{rvm_root}}/bin/rvm install {{rvm_default_ruby_version}}"
sudo: false
when: not rvm.system_install
when: "'{{ rvm_install_type }}' == 'user'"

- include: ./select_ruby.yml
16 changes: 8 additions & 8 deletions tasks/install_rvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
mode: 0755

- name: installing RVM as root
command: "{{rvm.temp_installer_path}} --path {{rvm.root}} stable"
command: "{{rvm.temp_installer_path}} --path {{rvm_root}} stable"
sudo: true
when: rvm.system_install
when: "'{{ rvm_install_type }}' == 'system'"

- name: installing RVM as user
command: "{{rvm.temp_installer_path}} --path {{rvm.root}} stable"
command: "{{rvm.temp_installer_path}} --path {{rvm_root}} stable"
sudo: false
when: not rvm.system_install
when: "'{{ rvm_install_type }}' == 'user'"

- name: removing RVM installer
file:
path: "{{rvm.temp_installer_path}}"
state: absent

- name: setting RVM autolibs on as root
command: "{{rvm.root}}/bin/rvm autolibs 3"
command: "{{rvm_root}}/bin/rvm autolibs 3"
sudo: true
when: rvm.system_install
when: "'{{ rvm_install_type }}' == 'system'"

- name: setting RVM autolibs on as user
command: "{{rvm.root}}/bin/rvm autolibs 3"
command: "{{rvm_root}}/bin/rvm autolibs 3"
sudo: false
when: not rvm.system_install
when: "'{{ rvm_install_type }}' == 'user'"
7 changes: 5 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
---
- name: include install type vars
include_vars: "{{ rvm_install_type }}.yml"

- include: ./install_packages.yml

- name: checking that RVM is installed
stat:
path: "{{rvm.init_script}}"
path: "{{rvm_init_script}}"
ignore_errors: True
register: rvm_install_result

- include: ./install_rvm.yml
when: rvm_install_result.stat.exists != true

- include: ./update_rvm.yml
when: rvm.auto_update_rvm and rvm_install_result.stat.exists == true
when: rvm_auto_update_rvm and rvm_install_result.stat.exists == true

- include: ./select_ruby.yml

Expand Down
8 changes: 4 additions & 4 deletions tasks/receive_key.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
sudo: true
register: mpapis_gpg_key_exists
ignore_errors: true
when: rvm.system_install
when: "'{{ rvm_install_type }}' == 'system'"

- name: receiving key as root
shell: "curl -sSL https://rvm.io/mpapis.asc | gpg --import -"
sudo: true
when: mpapis_gpg_key_exists is defined and mpapis_gpg_key_exists.rc is defined and mpapis_gpg_key_exists.rc != 0 and rvm.system_install
when: mpapis_gpg_key_exists is defined and mpapis_gpg_key_exists.rc is defined and mpapis_gpg_key_exists.rc != 0 and '{{ rvm_install_type }}' == 'system'

- name: Check for mpapis gpg key as user
shell: gpg --list-keys mpapis
sudo: false
register: mpapis_gpg_key_exists
ignore_errors: true
when: not rvm.system_install
when: "'{{ rvm_install_type }}' == 'user'"

- name: receiving key as user
shell: "curl -sSL https://rvm.io/mpapis.asc | gpg --import -"
sudo: false
when: mpapis_gpg_key_exists is defined and mpapis_gpg_key_exists.rc is defined and mpapis_gpg_key_exists.rc != 0 and not rvm.system_install
when: mpapis_gpg_key_exists is defined and mpapis_gpg_key_exists.rc is defined and mpapis_gpg_key_exists.rc != 0 and '{{ rvm_install_type }}' == 'user'
8 changes: 4 additions & 4 deletions tasks/select_ruby.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
- name: setting default Ruby version as root
shell: "source {{rvm.init_script}} && rvm use {{rvm.default_ruby_version}} --default executable=/bin/bash"
shell: "source {{rvm_init_script}} && rvm use {{rvm_default_ruby_version}} --default executable=/bin/bash"
sudo: true
register: rvm_select_ruby_version_root
ignore_errors: True
changed_when: False
when: rvm.system_install
when: "'{{ rvm_install_type }}' == 'system'"

- name: setting default Ruby version as user
shell: "source {{rvm.init_script}} && rvm use {{rvm.default_ruby_version}} --default executable=/bin/bash"
shell: "source {{rvm_init_script}} && rvm use {{rvm_default_ruby_version}} --default executable=/bin/bash"
sudo: false
register: rvm_select_ruby_version_user
ignore_errors: True
changed_when: False
when: not rvm.system_install
when: "'{{ rvm_install_type }}' == 'user'"
8 changes: 4 additions & 4 deletions tasks/update_rvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
- include: ./receive_key.yml

- name: updating RVM as root
shell: "source {{rvm.init_script}} && rvm get stable executable=/bin/bash"
shell: "source {{rvm_init_script}} && rvm get stable executable=/bin/bash"
sudo: true
when: rvm.system_install
when: "'{{ rvm_install_type }}' == 'system'"

- name: updating RVM as user
shell: "source {{rvm.init_script}} && rvm get stable executable=/bin/bash"
shell: "source {{rvm_init_script}} && rvm get stable executable=/bin/bash"
sudo: false
when: not rvm.system_install
when: "'{{ rvm_install_type }}' == 'user'"
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
3 changes: 3 additions & 0 deletions vars/system.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
rvm_root: /usr/local/rvm
rvm_init_script: /etc/profile.d/rvm.sh
3 changes: 3 additions & 0 deletions vars/user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
rvm_root: "~/.rvm"
rvm_init_script: "~/.rvm/scripts/rvm"

0 comments on commit 02a6870

Please sign in to comment.