Error handling in Ansible provisioning files can be a complex. I built these provisioning files on the backs of giants (see the references for this tutorial). I added more error handling as I found problems.
Note
At this time, not all error cases are handled in the Ansible files, nor are all error paths tested.
What follows are simplified flowcharts describing the error handling for both RVM and Ruby installations.
RVM Installation
RVM Error Cases Diagram
The RVM Yaml Snippet
Not all error paths shown in the diagram above are covered in the rvm Ansible file located in
...vmfiles/vmrails/ansible/roles/ror/tasks/rvm.yml
Here’s a snippet from the file:
# NOTE: this doesn't check if the installer is now present after the install;
# it's assumed
- name: Install rvm
shell: >
{{ rvm1_temp_download_path }}/rvm-installer.sh {{ rvm1_rvm_version }}
--path {{ rvm1_install_path }} {{ rvm1_install_flags }}
when:
not rvm_binary_preinstalled.stat.exists
# Check again for the rvm binary to ensure the above installation worked
# but fail if it doesn't exist
- name: Detect rvm binary again
stat:
path: '{{ rvm1_rvm }}'
register: rvm_binary
- name: Write out message if no rvm binary at this point
fail:
msg: "Whoops! rvm binary not found after attempted installation"
when: not rvm_binary.stat.exists
Ruby Installation
Ruby Error Cases Diagram
Ruby Yaml Snippet
Not all error paths shown in the diagram below are covered in the rubies file located in
...vmfiles/vmrails/ansible/roles/ror/tasks/rubies.yml
Here’s a snippet from the file:
#===========================================
# Install ruby versions specified
# this task serves to populate the register variable
- name: Detect if rubies are installed
command: '{{ rvm1_rvm }} {{ item }} do true'
with_items: '{{ rvm1_rubies }}'
changed_when: False
failed_when: False
when: rvm1_rubies | bool
register: detect_rubies_result
# check for error by the return code from the rvm install command
- name: Install rubies
command: '{{ rvm1_rvm }} install {{ item.item }} {{ rvm1_ruby_install_flags }}'
with_items: '{{ detect_rubies_result.results }}'
register: install_rubies_result
failed_when: ( install_rubies_result.rc != 0 )
- name: Are all requested rubies installed successfully?
shell: >
{{ rvm1_rvm }} list strings | grep {{ item }}
with_items: '{{ rvm1_rubies }}'
register: ruby_ver_requested_and_installed
failed_when: item not in ruby_ver_requested_and_installed.stdout