Skip to content

Commit

Permalink
use local rvm
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermeindl committed Jan 17, 2024
1 parent 5b21e12 commit 3b2de63
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 19 deletions.
3 changes: 0 additions & 3 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
---
roles:
- name: rvm/ruby
src: https://github.com/rvm/rvm1-ansible
version: v2.2.0
- name: geerlingguy.composer
src: https://github.com/geerlingguy/ansible-role-composer
version: master
4 changes: 2 additions & 2 deletions roles/gitlab/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ gitlab_with_zsh: true
gitlab_omniauth_enabled: false
gitlab_omniauth_providers: []

gitlab_repository_version: '16-7-stable'
gitlab_repository_version: '16-8-stable'
gitlab_ce_version: '{{ gitlab_repository_version }}'
gitlab_ee_version: '{{ gitlab_repository_version }}-ee'
gitlab_path: "{{ gitlab_home }}/gitlab"
Expand Down Expand Up @@ -77,7 +77,7 @@ gitlab_rvm_ruby_path: '{{ gitlab_home }}/.rvm/wrappers/default'
# This Version is fixed in .ruby_version
# gitaly ruby should be rerun (on version change, manually is required - see gitlab_gitaly.yml)
# ruby 3.2 or newer uses openssl 3, which comes with ubuntu 22.04
gitlab_ruby_version: 3.1.4
gitlab_ruby_version: 3.2.2

gitlab_mail_room_enabled: true

Expand Down
3 changes: 1 addition & 2 deletions roles/gitlab/tasks/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@

- name: Install ruby with rvm version {{ gitlab_ruby_version }}
ansible.builtin.include_role:
name: rvm.ruby
name: alphanodes.setup.rvm
vars:
rvm1_rubies: ['ruby-{{ gitlab_ruby_version }}']
rvm1_user: '{{ gitlab_user }}'
rvm1_bundler_install: false
ansible_become: true

- name: Install bundler for RVM
Expand Down
9 changes: 0 additions & 9 deletions roles/gitlab/tasks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,6 @@
- Restart gitlab
- Restart gitlab.slice

- name: Remove initializers_rack_attack
when: not gitlab_initializers_rack_attack
ansible.builtin.file:
path: '{{ gitlab_path }}/config/initializers/rack_attack.rb'
state: absent
notify:
- Restart gitlab
- Restart gitlab.slice

- name: Install GitLab systemd service files
ansible.builtin.template:
src: 'etc/systemd/system/{{ item }}.j2'
Expand Down
4 changes: 1 addition & 3 deletions roles/redmine/tasks/account_instance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,12 @@
- name: RVM setup - {{ redmine_user }}
ansible.builtin.include_role:
name: rvm.ruby
name: alphanodes.setup.rvm
allow_duplicates: true
vars:
rvm1_rubies: '{{ instance.rvm_rubies | default(rvm_rubies) }}'
rvm1_user: '{{ instance_name }}'
rvm1_bundler_install: false
rvm1_install_path: '{{ redmine_home }}/.rvm'
rvm1_install_flags: '{{ rvm_install_flags }}'
# see https://github.com/ansible/ansible/issues/29159#issuecomment-380862971
ansible_become: true
tags:
Expand Down
22 changes: 22 additions & 0 deletions roles/rvm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Ansible Role: rvm

An Ansible Role that installs [rvm](https://rsync.samba.org/) and manage ruby version on Debian and Ubuntu servers.

## Role Variables

Available variables can be found in [defaults/main.yml](defaults/main.yml)

## Example Playbook

```yaml
- hosts: all

vars:
rvm1_rubies: ['ruby-2.2.5','ruby-2.3.1'],
rvm1_install_flags: '--auto-dotfiles', # Remove --user-install from defaults
rvm1_install_path: /usr/local/rvm, # Set to system location
rvm1_user: root

roles:
- alphanodes.setup.rvm
```
64 changes: 64 additions & 0 deletions roles/rvm/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---

# Install 1 or more versions of ruby
# The last ruby listed will be set as the default ruby
rvm1_rubies:
- 'ruby-3.2.2'

# Install bundler
rvm1_bundler_install: false

# Delete a specific version of ruby (ie. ruby-2.1.0)
rvm1_delete_ruby:

# Install path for rvm (defaults to user based install)
rvm1_install_path: '~/.rvm'

# Add or remove any install flags
# NOTE: If you are doing a ROOT BASED INSTALL then
# make sure you REMOVE the --user-install flag below
rvm1_install_flags: '--user-install'

# Add additional ruby install flags
rvm1_ruby_install_flags:

# Set the owner for the rvm directory
rvm1_user: 'ubuntu'

# URL for the latest installer script
rvm1_rvm_latest_installer: 'https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer'

# rvm version to use
rvm1_rvm_version: 'stable'

# Check and update rvm, disabling this will force rvm to never update
rvm1_rvm_check_for_updates: True

# GPG key verification, use an empty string if you want to skip this
# Note: Unless you know what you're doing, just keep it as is
# Identity proof: https://keybase.io/mpapis
# PGP message: https://rvm.io/mpapis.asc
# rvm1_gpg_keys: '409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB'
rvm1_gpg_keys: ''

# The GPG key server
rvm1_gpg_key_server: 'hkp://keys.openpgp.org'

# The GPG alternative key servers
rvm1_gpg_key_servers:
- '{{ rvm1_gpg_key_server }}'
- hkp://pgp.mit.edu
- hkp://keyserver.pgp.com
- hkp://keyserver.ubuntu.com

# autolib mode, see https://rvm.io/rvm/autolibs
rvm1_autolib_mode: 2

# Name of UID 0 user
root_user: 'root'

# Name of GID 0 group -- BSD systems typically use wheel instead of root
root_group: '{{ root_user }}'

# Symlink binaries to system path
rvm1_symlink: true
19 changes: 19 additions & 0 deletions roles/rvm/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
galaxy_info:
description: RVM role to install and manage your ruby versions
author: alexandermeindl
company: AlphaNodes GmbH
license: Apache License 2.0
min_ansible_version: '2.14'

platforms:
- name: Ubuntu
versions:
- focal
- jammy
- name: Debian
versions:
- bullseye
- bookworm

dependencies: []
11 changes: 11 additions & 0 deletions roles/rvm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

- name: Install RVM
ansible.builtin.import_tasks: 'rvm.yml'
become: true
become_user: '{{ rvm1_user }}'

- name: Install Ruby and Gems
ansible.builtin.import_tasks: 'rubies.yml'
become: true
become_user: '{{ rvm1_user }}'
69 changes: 69 additions & 0 deletions roles/rvm/tasks/rubies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---

- name: Detect rubies
ansible.builtin.command: '{{ rvm1_rvm }} list strings'
register: rvm_list_strings
changed_when: False

Check warning on line 6 in roles/rvm/tasks/rubies.yml

View workflow job for this annotation

GitHub Actions / build

6:17 [truthy] truthy value should be one of [false, true]

- name: Install rubies
ansible.builtin.command: '{{ rvm1_rvm }} install {{ item }} {{ rvm1_ruby_install_flags }}'
loop: '{{ rvm1_rubies | difference(rvm_list_strings.stdout_lines) }}'

- name: Detect default ruby version
ansible.builtin.command: '{{ rvm1_rvm }} alias list default'
changed_when: False

Check warning on line 14 in roles/rvm/tasks/rubies.yml

View workflow job for this annotation

GitHub Actions / build

14:17 [truthy] truthy value should be one of [false, true]
register: detect_default_ruby_version

- name: Select default ruby
ansible.builtin.command: '{{ rvm1_rvm }} alias create default {{ rvm1_default_ruby_version }}'
when: detect_default_ruby_version.stdout|default() | length == 0 or
rvm1_default_ruby_version not in detect_default_ruby_version.stdout

- name: Detect installed ruby patch number
ansible.builtin.shell: >
set -o pipefail &&
{{ rvm1_rvm }} list strings |
grep {{ item }} |
tail -n 1
with_items: '{{ rvm1_rubies }}'
changed_when: False

Check warning on line 29 in roles/rvm/tasks/rubies.yml

View workflow job for this annotation

GitHub Actions / build

29:17 [truthy] truthy value should be one of [false, true]
register: ruby_patch
check_mode: no # Run in normal mode when in --check mode (http://docs.ansible.com/ansible/playbooks_checkmode.html)

Check warning on line 31 in roles/rvm/tasks/rubies.yml

View workflow job for this annotation

GitHub Actions / build

31:15 [truthy] truthy value should be one of [false, true]

Check warning on line 31 in roles/rvm/tasks/rubies.yml

View workflow job for this annotation

GitHub Actions / build

31:18 [comments] too few spaces before comment

- name: Install bundler if not installed
ansible.builtin.shell: >
set -o pipefail &&
ls {{ rvm1_install_path }}/wrappers/{{ item.stdout }} |
if ! grep "^bundler " ; then {{ rvm1_install_path }}/wrappers/{{ item.stdout }}/gem install bundler ; fi
args:
creates: '{{ rvm1_install_path }}/wrappers/{{ item.stdout }}/bundler'
with_items: '{{ ruby_patch.results }}'
when: rvm1_bundler_install
register: bundler_install
changed_when: '"Successfully installed bundler" in bundler_install.stdout'

- name: Symlink ruby related binaries on the system path
ansible.builtin.file:
state: 'link'
src: '{{ rvm1_install_path }}/wrappers/default/{{ item }}'
dest: '{{ rvm1_symlink_to }}/{{ item }}'
owner: '{{ root_user }}'
group: '{{ root_group }}'
when: not '--user-install' in rvm1_install_flags and rvm1_symlink
with_items: '{{ rvm1_symlink_binaries }}'

- name: Symlink bundler binaries on the system path
ansible.builtin.file:
state: 'link'
src: '{{ rvm1_install_path }}/wrappers/default/{{ item }}'
dest: '{{ rvm1_symlink_to }}/{{ item }}'
owner: '{{ root_user }}'
group: '{{ root_group }}'
when: not '--user-install' in rvm1_install_flags and rvm1_bundler_install and rvm1_symlink
with_items: '{{ rvm1_symlink_bundler_binaries }}'

- name: Delete ruby if relevant
ansible.builtin.command: '{{ rvm1_rvm }} remove {{ rvm1_delete_ruby }}'
register: rvm_delete_command
changed_when: "'#removing' in rvm_delete_command.stdout"
when: rvm1_delete_ruby is defined and rvm1_delete_ruby
63 changes: 63 additions & 0 deletions roles/rvm/tasks/rvm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---

- name: Detect rvm binary
ansible.builtin.stat:
path: '{{ rvm1_rvm }}'
register: rvm_binary

- name: Detect rvm installer
ansible.builtin.stat:
path: '{{ rvm1_temp_download_path }}/rvm-installer.sh'
register: rvm_installer

- name: Detect current rvm version
ansible.builtin.command: '{{ rvm1_rvm }} version'
changed_when: False

Check warning on line 15 in roles/rvm/tasks/rvm.yml

View workflow job for this annotation

GitHub Actions / build

15:17 [truthy] truthy value should be one of [false, true]
register: rvm_current_version
when: rvm_binary.stat.exists

- name: Install rvm installer
ansible.builtin.get_url:
url: '{{ rvm1_rvm_latest_installer }}'
dest: '{{ rvm1_temp_download_path }}/rvm-installer.sh'
mode: 0755
when: not rvm_installer.stat.exists

- name: Import GPG keys from keyservers
ansible.builtin.command: 'gpg --batch --keyserver {{ item }} --recv-keys {{ rvm1_gpg_keys }}'
changed_when: False

Check warning on line 28 in roles/rvm/tasks/rvm.yml

View workflow job for this annotation

GitHub Actions / build

28:17 [truthy] truthy value should be one of [false, true]
check_mode: False

Check warning on line 29 in roles/rvm/tasks/rvm.yml

View workflow job for this annotation

GitHub Actions / build

29:15 [truthy] truthy value should be one of [false, true]
with_items: '{{ rvm1_gpg_key_servers }}'
register: gpg_import
when: not ansible_check_mode and rvm1_gpg_keys | length and (gpg_import is not defined or gpg_import.rc != 0)
ignore_errors: True

Check warning on line 33 in roles/rvm/tasks/rvm.yml

View workflow job for this annotation

GitHub Actions / build

33:18 [truthy] truthy value should be one of [false, true]

- name: Was GPG import from keyservers succesfull?
ansible.builtin.set_fact:
gpg_imported_from: '{{ item.item }}'
when: "'rc' in item and item.rc == 0"
with_items: "{{ gpg_import.results }}"

- name: Import GPG keys from rvm.io, if keyservers failed
ansible.builtin.shell: >
set -o pipefail &&
curl -sSL https://rvm.io/{{ item }} | gpg --batch --import -
with_items:
- mpapis.asc
- pkuczynski.asc
when: not ansible_check_mode and rvm1_gpg_keys | length and gpg_imported_from is not defined

- name: Install rvm
ansible.builtin.shell: >
/usr/bin/env bash {{ rvm1_temp_download_path }}/rvm-installer.sh {{ rvm1_rvm_version }}
--path {{ rvm1_install_path }} {{ rvm1_install_flags }}
when: not rvm_binary.stat.exists

- name: Update rvm
ansible.builtin.shell: '{{ rvm1_rvm }} get {{ rvm1_rvm_version }} && {{ rvm1_rvm }} reload'
changed_when: False

Check warning on line 58 in roles/rvm/tasks/rvm.yml

View workflow job for this annotation

GitHub Actions / build

58:17 [truthy] truthy value should be one of [false, true]
when: rvm_binary.stat.exists and rvm1_rvm_check_for_updates

- name: Configure rvm
ansible.builtin.command: '{{ rvm1_rvm }} autolibs {{ rvm1_autolib_mode }}'
when: not rvm_binary.stat.exists
23 changes: 23 additions & 0 deletions roles/rvm/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

rvm1_temp_download_path: '/tmp'

rvm1_default_ruby_version: '{{ rvm1_rubies | last if rvm1_rubies and rvm1_rubies is iterable else rvm1_rubies }}'

rvm1_rvm: '{{ rvm1_install_path }}/bin/rvm'

rvm1_symlink_binaries:
- 'erb'
- 'executable-hooks-uninstaller'
- 'gem'
- 'irb'
- 'rake'
- 'rdoc'
- 'ri'
- 'ruby'

rvm1_symlink_bundler_binaries:
- 'bundle'
- 'bundler'

rvm1_symlink_to: '/usr/local/bin'

0 comments on commit 3b2de63

Please sign in to comment.