Change facts back to variables

This commit is contained in:
Nick Janetakis
2014-07-02 08:39:27 -04:00
parent 7555d13122
commit 1947717539
7 changed files with 27 additions and 44 deletions

View File

@@ -51,38 +51,34 @@ rvm1_rvm_stable_version_number: 'https://raw.githubusercontent.com/wayneeseguin/
rvm1_rvm_force_upgrade_installer: false rvm1_rvm_force_upgrade_installer: false
``` ```
## Facts ## Exposed variables
You will likely want to use various ruby related commands in other roles. This role exposes a number of popular paths and variables as persisted facts. You will likely want to use various ruby related commands in other roles. This role exposes a number of popular paths and variables that you can use.
Since the values are saved to `/etc/ansible/facts.d/rvm1.fact` you do not need to run this role every time you invoke your play book to have access to the facts. They will be persisted between play book runs. - `rvm1_default_ruby_version`
- `default_ruby_version`
- The default ruby version that is selected - The default ruby version that is selected
- `rvm` - `rvm1_rvm`
- The path to the rvm binary - The path to the rvm binary
- `default_wrappers`: - `rvm1_default_wrappers`:
- The path containing all of the wrapped ruby related binaries - The path containing all of the wrapped ruby related binaries
- `ruby` - `rvm1_ruby`
- The path to the ruby binary - The path to the ruby binary
- `gem` - `rvm1_gem`
- The path to the gem binary - The path to the gem binary
- `bundle` - `rvm1_bundle`
- The path to the bundle binary - The path to the bundle binary
- `rake` - `rvm1_rake`
- The path to the rake binary with bundle exec already applied - The path to the rake binary with bundle exec already applied
### Example ### Example
You can access them in any play or role by prepending `ansible_local` to the value. 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 `{{ ansible_local.rvm1.rake }} db:migrate`.
## Upgrading and removing old versions of ruby ## Upgrading and removing old versions of ruby

View File

@@ -1,6 +0,0 @@
---
- name: ensure /etc/ansible/facts.d is created
file: path='/etc/ansible/facts.d' state='directory'
- name: ensure facts are persisted in /etc/ansible/facts.d/rvm1.fact
template: src='etc/ansible/facts.d/rvm1.fact.j2' dest='/etc/ansible/facts.d/rvm1.fact'

View File

@@ -1,4 +1,3 @@
--- ---
- include: 'facts.yml'
- include: 'rvm.yml' - include: 'rvm.yml'
- include: 'rubies.yml' - include: 'rubies.yml'

View File

@@ -1,6 +1,6 @@
--- ---
- name: detect if rubies are installed - name: detect if rubies are installed
command: '{{ ansible_local.rvm1.rvm }} {{ item }} do true' command: '{{ rvm1 }} {{ item }} do true'
changed_when: false changed_when: false
failed_when: false failed_when: false
register: detect_rubies register: detect_rubies
@@ -8,30 +8,30 @@
when: rvm1_rubies when: rvm1_rubies
- name: ensure rubies are installed - name: ensure rubies are installed
command: '{{ ansible_local.rvm1.rvm }} install {{ item.item }}' command: '{{ rvm1 }} install {{ item.item }}'
when: rvm1_rubies and item.rc != 0 when: rvm1_rubies and item.rc != 0
with_items: detect_rubies.results with_items: detect_rubies.results
- name: detect default ruby version - name: detect default ruby version
command: '{{ ansible_local.rvm1.rvm }} alias list default' command: '{{ rvm1 }} alias list default'
changed_when: false changed_when: false
register: detect_default_ruby_version register: detect_default_ruby_version
- name: ensure default ruby is selected - name: ensure default ruby is selected
command: '{{ ansible_local.rvm1.rvm }} alias create default {{ ansible_local.rvm1.default_ruby_version }}' command: '{{ rvm1 }} alias create default {{ rvm1_default_ruby_version }}'
when: detect_default_ruby_version.stdout == '' or ansible_local.rvm1.default_ruby_version not in detect_default_ruby_version.stdout when: detect_default_ruby_version.stdout == '' or rvm1_default_ruby_version not in detect_default_ruby_version.stdout
- 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 - name: detect if ruby version can be deleted
command: '{{ ansible_local.rvm1.rvm }} {{ rvm1_delete_ruby }} do true' command: '{{ rvm1 }} {{ rvm1_delete_ruby }} do true'
changed_when: false changed_when: false
failed_when: false failed_when: false
register: detect_delete_ruby register: detect_delete_ruby
when: rvm1_delete_ruby when: rvm1_delete_ruby
- name: ensure ruby version is deleted - name: ensure ruby version is deleted
command: '{{ ansible_local.rvm1.rvm }} remove {{ rvm1_delete_ruby }}' command: '{{ rvm1 }} remove {{ rvm1_delete_ruby }}'
changed_when: false changed_when: false
when: rvm1_delete_ruby and detect_delete_ruby.rc == 0 when: rvm1_delete_ruby and detect_delete_ruby.rc == 0

View File

@@ -1,6 +1,6 @@
--- ---
- name: detect rvm binary - name: detect rvm binary
stat: path='{{ ansible_local.rvm1.rvm }}' stat: path='{{ rvm1 }}'
register: rvm_binary register: rvm_binary
- name: detect rvm installer - name: detect rvm installer
@@ -8,7 +8,7 @@
register: rvm_installer register: rvm_installer
- name: detect current rvm version - name: detect current rvm version
command: '{{ ansible_local.rvm1.rvm }} version' command: '{{ rvm1 }} version'
changed_when: false changed_when: false
register: rvm_current_version register: rvm_current_version
when: rvm_binary.stat.exists when: rvm_binary.stat.exists
@@ -39,9 +39,9 @@
when: not rvm_binary.stat.exists when: not rvm_binary.stat.exists
- name: ensure rvm is upgraded - name: ensure rvm is upgraded
shell: '{{ ansible_local.rvm1.rvm }} get stable && {{ ansible_local.rvm1.rvm }} reload' shell: '{{ rvm1 }} get stable && {{ rvm1 }} reload'
when: rvm_binary.stat.exists and rvm_stable_version_number.content | default(rvm1_rvm_stable_version_number) | replace('\n', '') > rvm_current_version.stdout.split()[1] when: rvm_binary.stat.exists and rvm_stable_version_number.content | default(rvm1_rvm_stable_version_number) | replace('\n', '') > rvm_current_version.stdout.split()[1]
- name: ensure rvm installs ruby dependencies - name: ensure rvm installs ruby dependencies
command: '{{ ansible_local.rvm1.rvm }} autolibs 3' command: '{{ rvm1 }} autolibs 3'
when: not rvm_binary.stat.exists when: not rvm_binary.stat.exists

View File

@@ -13,7 +13,4 @@
rvm1_install_path: '/home/travis/.rvm' rvm1_install_path: '/home/travis/.rvm'
roles: roles:
- ansible-ruby - ansible-ruby
post_tasks:
- debug: var=ansible_local.rvm1

View File

@@ -1,11 +1,8 @@
--- ---
rvm1_default_ruby_version: '{{ rvm1_rubies | last if rvm1_rubies and rvm1_rubies is iterable else "" }}'
rvm1_rvm: '{{ rvm1_install_path }}/bin/rvm'
rvm1_default_wrappers: '{{ rvm1_install_path }}/wrappers/default' rvm1_default_wrappers: '{{ rvm1_install_path }}/wrappers/default'
rvm1_ruby: '{{ rvm1_default_wrappers }}/ruby'
rvm1_gem: '{{ rvm1_default_wrappers }}/gem'
rvm1_bundle: '{{ rvm1_default_wrappers }}/bundle' rvm1_bundle: '{{ rvm1_default_wrappers }}/bundle'
rvm1_facts: | rvm1_rake: '{{ rvm1_bundle }} exec {{ rvm1_default_wrappers }}/rake'
default_ruby_version='{{ rvm1_rubies | last if rvm1_rubies and rvm1_rubies is iterable else "" }}'
rvm='{{ rvm1_install_path }}/bin/rvm'
default_wrappers= '{{ rvm1_default_wrappers }}'
ruby='{{ rvm1_default_wrappers }}/ruby'
gem='{{ rvm1_default_wrappers }}/gem'
bundle='{{ rvm1_bundle }}'
rake='{{ rvm1_bundle }} exec {{ rvm1_default_wrappers }}/rake'