Add the ability to delete a ruby version

This commit is contained in:
Nick Janetakis
2014-07-01 15:21:34 -04:00
parent 043b7976b3
commit 6144181edf
3 changed files with 41 additions and 1 deletions

View File

@@ -25,6 +25,10 @@ rvm1_group: 'rvm'
rvm1_rubies: rvm1_rubies:
- 'ruby-2.1.2' - 'ruby-2.1.2'
# Which version of ruby do you want to delete?
# Example: `rvm1_delete_ruby: ruby-2.1.0`
rvm1_delete_ruby: ''
# Where should the rvm-installer and other temp files be downloaded to? # Where should the rvm-installer and other temp files be downloaded to?
rvm1_temp_download_path: '/usr/local/src' rvm1_temp_download_path: '/usr/local/src'
@@ -76,6 +80,28 @@ You will likely want to use various ruby related commands in other roles. This r
If you wanted to run a database migration in rails you would use `{{ rvm1_rake }} db:migrate`. If you wanted to run a database migration in rails you would use `{{ rvm1_rake }} db:migrate`.
## Upgrading and removing old versions of ruby
A common work flow for upgrading your ruby version would be:
1. Install the new version
2. Run your application role so that bundle install re-installs your gems
3. Delete the previous version of ruby
You can delete a version of ruby with this role in 1 of 2 ways:
### Edit your inventory directly
You could overwrite `rvm1_delete_ruby: 'ruby-2.1.0'` and then run your play book. This would work but then you would have to go back and edit your inventory to make it an empty string afterwards.
The delete task is idempotent but it still requires you to make 2 edits.
#### Leverage ansible's `--extra-vars`
Just add `--extra-vars 'rvm1_delete_ruby=ruby-2.1.0'` to the end of your play book command and that version will be removed without having to manually edit your inventory.
Not having to edit anything sure sounds better to me.
## Example playbook ## Example playbook
For the sake of this example let's assume you have a group called **app** and you have a typical `site.yml` file. For the sake of this example let's assume you have a group called **app** and you have a typical `site.yml` file.

View File

@@ -5,6 +5,8 @@ rvm1_group: 'rvm'
rvm1_rubies: rvm1_rubies:
- 'ruby-2.1.2' - 'ruby-2.1.2'
rvm1_delete_ruby:
rvm1_temp_download_path: '/usr/local/src' rvm1_temp_download_path: '/usr/local/src'
rvm1_install_path: '/usr/local/rvm' rvm1_install_path: '/usr/local/rvm'

View File

@@ -23,3 +23,15 @@
- name: ensure rvm install path is writable by the set owner:group - name: ensure rvm install path is writable by the set owner:group
file: path='{{ rvm1_install_path }}' state=directory recurse=yes owner='{{ rvm1_user }}' group='{{ rvm1_group }}' file: path='{{ rvm1_install_path }}' state=directory recurse=yes owner='{{ rvm1_user }}' group='{{ rvm1_group }}'
- name: detect if ruby version can be deleted
command: '{{ rvm1 }} {{ rvm1_delete_ruby }} do true'
changed_when: false
failed_when: false
register: detect_delete_ruby
when: rvm1_delete_ruby
- name: ensure ruby version is deleted
command: '{{ rvm1 }} remove {{ rvm1_delete_ruby }}'
changed_when: false
when: rvm1_delete_ruby and detect_delete_ruby.rc == 0