templates/ansible/roles/ruby/tasks/rvm.yml
---
- name: Detect rvm binary
stat: path='{{ rvm1_rvm }}'
register: rvm_binary
- name: Detect rvm installer
stat: path='{{ rvm1_temp_download_path }}/rvm-installer.sh'
register: rvm_installer
- name: Detect current rvm version
command: '{{ rvm1_rvm}} version'
changed_when: False
register: rvm_current_version
when: rvm_binary.stat.exists
- name: Install rvm installer
get_url:
url: '{{ rvm1_rvm_latest_installer }}'
dest: '{{ rvm1_temp_download_path }}/rvm-installer.sh'
when: not rvm_installer.stat.exists
- name: Configure rvm installer
file:
path: '{{ rvm1_temp_download_path }}/rvm-installer.sh'
mode: 0755
when: not rvm_binary.stat.exists
- name: Import GPG keys
command: 'gpg --keyserver {{ rvm1_gpg_key_server }} --recv-keys {{ rvm1_gpg_keys }}'
changed_when: False
when: rvm1_gpg_keys != ''
sudo_user: '{{ rvm1_user }}'
- name: Install rvm
command: >
{{ rvm1_temp_download_path }}/rvm-installer.sh {{ rvm1_rvm_version }}
--path {{ rvm1_install_path }} {{ rvm1_install_flags }}
when: not rvm_binary.stat.exists
sudo_user: '{{ rvm1_user }}'
- name: Update rvm
shell: '{{ rvm1_rvm }} get {{ rvm1_rvm_version }} && {{ rvm1_rvm }} reload'
changed_when: False
when: rvm_binary.stat.exists and rvm1_rvm_check_for_updates
sudo_user: '{{ rvm1_user }}'
- name: Configure rvm
command: '{{ rvm1_rvm }} autolibs 3'
when: not rvm_binary.stat.exists
sudo_user: '{{ rvm1_user }}'
- name: Detect if rubies are installed
command: '{{ rvm1_rvm }} {{ item }} do true'
changed_when: False
failed_when: False
register: detect_rubies
with_items: rvm1_rubies
- name: Install rubies
command: '{{ rvm1_rvm }} install {{ item.item }} --binary'
when: item.rc != 0
with_items: detect_rubies.results
sudo_user: '{{ rvm1_user }}'
register: install_rubies
ignore_errors: yes
# Try to install non-binary version if previous command failed
# https://github.com/andreychernih/railsbox/issues/13
- name: Install rubies (non-binary)
command: '{{ rvm1_rvm }} install {{ item.item }}'
when: item.rc != 0 and install_rubies.results[0].rc != 0
with_items: detect_rubies.results
sudo_user: '{{ rvm1_user }}'
- name: Detect default ruby version
command: '{{ rvm1_rvm }} alias list default'
changed_when: False
register: detect_default_ruby_version
- name: Select default ruby
command: '{{ rvm1_rvm }} alias create default {{ rvm1_default_ruby_version }}'
when: detect_default_ruby_version.stdout == '' or
rvm1_default_ruby_version not in detect_default_ruby_version.stdout
- name: Symlink ruby related binaries on the system path
file:
state: 'link'
src: '{{ rvm1_install_path }}/wrappers/default/{{ item }}'
dest: '{{ rvm1_symlink_to }}/{{ item }}'
owner: 'root'
group: 'root'
force: yes
when: not '--user-install' in rvm1_install_flags
with_items: rvm1_symlink_binaries
- name: Create rvm.sh
template: src=rvm.sh.j2 dest={{ profile_d_path }}/rvm.sh owner={{ user_name }} group={{ group_name }}