From 02a6870f20fddeb890925d250e1912914eb3da6f Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Thu, 27 Aug 2015 13:24:55 -0600 Subject: [PATCH] rvm: Refactor away from nested vars, make defaults for system & user install automatic (since Ansible does not support specific key/value overrides/Mashing like Chef, entire nested hash must be re-defined) --- defaults/main.yml | 12 ++++-------- tasks/install_ruby.yml | 8 ++++---- tasks/install_rvm.yml | 16 ++++++++-------- tasks/main.yml | 7 +++++-- tasks/receive_key.yml | 8 ++++---- tasks/select_ruby.yml | 8 ++++---- tasks/update_rvm.yml | 8 ++++---- vars/main.yml | 1 + vars/system.yml | 3 +++ vars/user.yml | 3 +++ 10 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 vars/main.yml create mode 100644 vars/system.yml create mode 100644 vars/user.yml diff --git a/defaults/main.yml b/defaults/main.yml index 0745368..f4926f3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 diff --git a/tasks/install_ruby.yml b/tasks/install_ruby.yml index f048bd8..c3dc7da 100644 --- a/tasks/install_ruby.yml +++ b/tasks/install_ruby.yml @@ -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 diff --git a/tasks/install_rvm.yml b/tasks/install_rvm.yml index 6a5892c..2acee83 100644 --- a/tasks/install_rvm.yml +++ b/tasks/install_rvm.yml @@ -12,14 +12,14 @@ 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: @@ -27,11 +27,11 @@ 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 \ No newline at end of file + when: "'{{ rvm_install_type }}' == 'user'" \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 1ef0a7e..09b706e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,9 +1,12 @@ --- +- 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 @@ -11,7 +14,7 @@ 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 diff --git a/tasks/receive_key.yml b/tasks/receive_key.yml index baffad9..71d59e4 100644 --- a/tasks/receive_key.yml +++ b/tasks/receive_key.yml @@ -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' diff --git a/tasks/select_ruby.yml b/tasks/select_ruby.yml index 99400d7..19f5a8e 100644 --- a/tasks/select_ruby.yml +++ b/tasks/select_ruby.yml @@ -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 \ No newline at end of file + when: "'{{ rvm_install_type }}' == 'user'" \ No newline at end of file diff --git a/tasks/update_rvm.yml b/tasks/update_rvm.yml index 4d44aa6..109898b 100644 --- a/tasks/update_rvm.yml +++ b/tasks/update_rvm.yml @@ -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 \ No newline at end of file + when: "'{{ rvm_install_type }}' == 'user'" \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1 @@ +--- diff --git a/vars/system.yml b/vars/system.yml new file mode 100644 index 0000000..7be53da --- /dev/null +++ b/vars/system.yml @@ -0,0 +1,3 @@ +--- +rvm_root: /usr/local/rvm +rvm_init_script: /etc/profile.d/rvm.sh diff --git a/vars/user.yml b/vars/user.yml new file mode 100644 index 0000000..6681c71 --- /dev/null +++ b/vars/user.yml @@ -0,0 +1,3 @@ +--- +rvm_root: "~/.rvm" +rvm_init_script: "~/.rvm/scripts/rvm"