Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor, deprecation fixes and tasks flow improved #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
Ansible RVM role
================

This Ansible role installs RVM as root and the required ruby version.
If user isn't root (executing without sudo) then RVM will be installed to the user home directory,
but you need to change paths to it own RVM through variables `rvm_root` and `rvm_init_script`.
This Ansible role installs RVM and the required ruby version.
Installation is possible for system or for single user (without root privileges)

Requirements
------------
Expand All @@ -27,7 +26,14 @@ Role Variables

The last two variables are set according to whether a `system`-wide install (Multi-User install), or a Single-User install has been chosen with `rvm_install_type`.

The playbook runs with root permissions by default if the `ansible_ssh_user` that is running your playbook has `sudo` privileges, and `rvm_install_type` is set to `system`.
The palybook should runs on user with sufficient permissions:
- to install dependencies via `apt` or `yum` if you do not have installed `curl` and `gnupg2` pakages
- to install dependencies via `apt` or `yum` if you set `rvm_autolibs` to `3` or `4` (default `3`)
- to install in system path for example in `system` mode (`rvm_install_type` variable)

If you want to install on unprivileged user you should have system dependencies installed and set:
- `rvm_install_type` to `user`
- `rvm_autolibs` prefably to `2`

When the playbook is run with `rvm_install_type = user`, the playbook will install RVM to the home directory of the `ansible_ssh_user`.
The defaults for the last two variables are then:
Expand Down
2 changes: 0 additions & 2 deletions tasks/install_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
name: "{{ item }}"
state: present
with_items: "{{ rvm_required_packages }}"
sudo: true
when: ansible_os_family == "RedHat"

- name: ensure necessary apt packages are installed
apt:
name: "{{ item }}"
state: present
with_items: "{{ rvm_required_packages }}"
sudo: true
when: ansible_os_family == "Debian"
11 changes: 2 additions & 9 deletions tasks/install_ruby.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
---
- name: installing Ruby as root
- name: Install Ruby
command: "{{rvm_root}}/bin/rvm install {{rvm_default_ruby_version}}"
sudo: true
when: "'{{ rvm_install_type }}' == 'system'"

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

- include: ./select_ruby.yml
- include_tasks: ./select_ruby.yml
25 changes: 6 additions & 19 deletions tasks/install_rvm.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
---
- include: ./receive_key.yml
- include_tasks: ./receive_key.yml

- name: downloading RVM installer
- name: Download RVM installer
get_url:
url: "{{rvm_url}}"
dest: "{{rvm_temp_installer_path}}"

- name: set executable RVM installer
- name: Set RVM installer to be executable
file:
path: "{{rvm_temp_installer_path}}"
mode: 0755

- name: installing RVM as root
- name: Install RVM
command: "{{rvm_temp_installer_path}} --path {{rvm_root}} stable"
sudo: true
when: "'{{ rvm_install_type }}' == 'system'"

- name: installing RVM as user
command: "{{rvm_temp_installer_path}} --path {{rvm_root}} stable"
sudo: false

- name: removing RVM installer
- name: Remove RVM installer
file:
path: "{{rvm_temp_installer_path}}"
state: absent

- name: setting RVM autolibs option as root
command: "{{rvm_root}}/bin/rvm autolibs {{rvm_autolibs}}"
sudo: true
when: "'{{ rvm_install_type }}' == 'system'"

- name: setting RVM autolibs option as user
- name: Set RVM autolibs option
command: "{{rvm_root}}/bin/rvm autolibs {{rvm_autolibs}}"
sudo: false
when: "'{{ rvm_install_type }}' == 'user'"
16 changes: 8 additions & 8 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
---
- name: include install type vars
- name: Include install type vars
include_vars: "{{ rvm_install_type }}.yml"

- include: ./install_packages.yml
- include_tasks: ./install_packages.yml

- name: checking that RVM is installed
- name: Check if RVM installed
stat:
path: "{{rvm_init_script}}"
ignore_errors: True
failed_when: False
register: rvm_install_result

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

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

- include: ./select_ruby.yml
- include_tasks: ./select_ruby.yml

- include: ./install_ruby.yml
when: rvm_select_ruby_version_user|failed or rvm_select_ruby_version_root|failed
- include_tasks: ./install_ruby.yml
when: rvm_select_ruby_version is defined and rvm_select_ruby_version.rc != 0
26 changes: 8 additions & 18 deletions tasks/receive_key.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
---
- name: Check for mpapis gpg key as root
- name: Check for mpapis gpg key
shell: gpg --list-keys mpapis
sudo: true
register: mpapis_gpg_key_exists
ignore_errors: true
when: "'{{ rvm_install_type }}' == 'system'"
ignore_errors: True
changed_when: False
failed_when: False

- 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_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: "'{{ rvm_install_type }}' == 'user'"

- name: receiving key as user
- name: Install GPG key
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 '{{ rvm_install_type }}' == 'user'
args:
warn: False
when: mpapis_gpg_key_exists is defined and mpapis_gpg_key_exists.rc is defined and mpapis_gpg_key_exists.rc != 0
14 changes: 2 additions & 12 deletions tasks/select_ruby.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
---
- name: setting default Ruby version as root
- name: Check if desired Ruby installed and default
shell: "source {{rvm_init_script}} && rvm use {{rvm_default_ruby_version}} --default executable=/bin/bash"
sudo: true
register: rvm_select_ruby_version_root
register: rvm_select_ruby_version
ignore_errors: True
failed_when: False
changed_when: False
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"
sudo: false
register: rvm_select_ruby_version_user
ignore_errors: True
changed_when: False
when: "'{{ rvm_install_type }}' == 'user'"
12 changes: 3 additions & 9 deletions tasks/update_rvm.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
---
- include: ./receive_key.yml
- include_tasks: ./receive_key.yml

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

- name: updating RVM as user
shell: "source {{rvm_init_script}} && rvm get stable executable=/bin/bash"
sudo: false
when: "'{{ rvm_install_type }}' == 'user'"