From 1947717539836f358b45cc0e41a1abca960f45dd Mon Sep 17 00:00:00 2001 From: Nick Janetakis Date: Wed, 2 Jul 2014 08:39:27 -0400 Subject: [PATCH] Change facts back to variables --- README.md | 24 ++++++++++-------------- tasks/facts.yml | 6 ------ tasks/main.yml | 1 - tasks/rubies.yml | 14 +++++++------- tasks/rvm.yml | 8 ++++---- tests/test.yml | 5 +---- vars/main.yml | 13 +++++-------- 7 files changed, 27 insertions(+), 44 deletions(-) delete mode 100644 tasks/facts.yml diff --git a/README.md b/README.md index 16a11b7..4d0068d 100644 --- a/README.md +++ b/README.md @@ -51,38 +51,34 @@ rvm1_rvm_stable_version_number: 'https://raw.githubusercontent.com/wayneeseguin/ 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. - -- `default_ruby_version` +- `rvm1_default_ruby_version` - The default ruby version that is selected -- `rvm` +- `rvm1_rvm` - The path to the rvm binary -- `default_wrappers`: +- `rvm1_default_wrappers`: - The path containing all of the wrapped ruby related binaries -- `ruby` +- `rvm1_ruby` - The path to the ruby binary -- `gem` +- `rvm1_gem` - The path to the gem binary -- `bundle` +- `rvm1_bundle` - The path to the bundle binary -- `rake` +- `rvm1_rake` - The path to the rake binary with bundle exec already applied ### 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 `{{ ansible_local.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 diff --git a/tasks/facts.yml b/tasks/facts.yml deleted file mode 100644 index 240a0b9..0000000 --- a/tasks/facts.yml +++ /dev/null @@ -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' \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index d03f7d3..3e8fd04 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,3 @@ --- -- include: 'facts.yml' - include: 'rvm.yml' - include: 'rubies.yml' \ No newline at end of file diff --git a/tasks/rubies.yml b/tasks/rubies.yml index e8e6700..5e49d46 100644 --- a/tasks/rubies.yml +++ b/tasks/rubies.yml @@ -1,6 +1,6 @@ --- - name: detect if rubies are installed - command: '{{ ansible_local.rvm1.rvm }} {{ item }} do true' + command: '{{ rvm1 }} {{ item }} do true' changed_when: false failed_when: false register: detect_rubies @@ -8,30 +8,30 @@ when: rvm1_rubies - 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 with_items: detect_rubies.results - name: detect default ruby version - command: '{{ ansible_local.rvm1.rvm }} alias list default' + command: '{{ rvm1 }} alias list default' changed_when: false register: detect_default_ruby_version - name: ensure default ruby is selected - command: '{{ ansible_local.rvm1.rvm }} alias create default {{ ansible_local.rvm1.default_ruby_version }}' - when: detect_default_ruby_version.stdout == '' or ansible_local.rvm1.default_ruby_version not in detect_default_ruby_version.stdout + command: '{{ rvm1 }} 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: 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 }}' - 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 failed_when: false register: detect_delete_ruby when: rvm1_delete_ruby - name: ensure ruby version is deleted - command: '{{ ansible_local.rvm1.rvm }} remove {{ rvm1_delete_ruby }}' + command: '{{ rvm1 }} remove {{ rvm1_delete_ruby }}' changed_when: false when: rvm1_delete_ruby and detect_delete_ruby.rc == 0 \ No newline at end of file diff --git a/tasks/rvm.yml b/tasks/rvm.yml index 1dd8847..c9d4aa0 100644 --- a/tasks/rvm.yml +++ b/tasks/rvm.yml @@ -1,6 +1,6 @@ --- - name: detect rvm binary - stat: path='{{ ansible_local.rvm1.rvm }}' + stat: path='{{ rvm1 }}' register: rvm_binary - name: detect rvm installer @@ -8,7 +8,7 @@ register: rvm_installer - name: detect current rvm version - command: '{{ ansible_local.rvm1.rvm }} version' + command: '{{ rvm1 }} version' changed_when: false register: rvm_current_version when: rvm_binary.stat.exists @@ -39,9 +39,9 @@ when: not rvm_binary.stat.exists - 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] - name: ensure rvm installs ruby dependencies - command: '{{ ansible_local.rvm1.rvm }} autolibs 3' + command: '{{ rvm1 }} autolibs 3' when: not rvm_binary.stat.exists \ No newline at end of file diff --git a/tests/test.yml b/tests/test.yml index 24d0b2f..d159f5f 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -13,7 +13,4 @@ rvm1_install_path: '/home/travis/.rvm' roles: - - ansible-ruby - - post_tasks: - - debug: var=ansible_local.rvm1 \ No newline at end of file + - ansible-ruby \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml index 1b60d91..74b134f 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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_ruby: '{{ rvm1_default_wrappers }}/ruby' +rvm1_gem: '{{ rvm1_default_wrappers }}/gem' rvm1_bundle: '{{ rvm1_default_wrappers }}/bundle' -rvm1_facts: | - 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' \ No newline at end of file +rvm1_rake: '{{ rvm1_bundle }} exec {{ rvm1_default_wrappers }}/rake' \ No newline at end of file