---
- name: packages
  apt:
    pkg: "{{ item }}"
    update_cache: yes
    state: present
    cache_valid_time: 86400
  with_flattened:
  - rvm_packages
  - rvm_custom_packages

- include: gpg_keys.yml
  when: rvm_gpg_keys != ''

- name: Install RVM
  shell: >
    curl -L https://get.rvm.io
    | bash -s stable --autolibs=disable --auto-dotfiles
  args:
    creates: ~/.rvm
  sudo: yes
  sudo_user: "{{ rvm_user }}"

- name: ruby versions
  shell: >
    ~/.rvm/bin/rvm install
    {{ '--default' if item == rvm_default else '' }}
    {{ item }}
  args:
    creates: "~/.rvm/rubies/ruby-{{ item }}"
  sudo: yes
  sudo_user: "{{ rvm_user }}"
  with_flattened:
  - rvm_rubies
  - "{{ rvm_default }}"

- name: facts
  set_fact:
    RUBY_PREFIX: '~/.rvm/bin/rvm default do '
    RUBY_BIN: '/home/{{ rvm_user }}/.rvm/gems/ruby-{{ rvm_default }}/wrappers/ruby'

- name: Install gems
  shell: >
    {{RUBY_PREFIX}} gem install {{item}}
  sudo: yes
  sudo_user: "{{ rvm_user }}"
  with_flattened:
  - rvm_install_gems
  register: ruby_rvm_bundler_result
  changed_when: >
    "Fetching" in ruby_rvm_bundler_result.stdout

---
- name: packages
  apt:
    pkg: "{{ item }}"
    update_cache: yes
    state: present
    cache_valid_time: 86400
  with_flattened:
  - rvm_packages
  - rvm_custom_packages

- include: gpg_keys.yml
  when: rvm_gpg_keys != ''

- name: Install RVM
  shell: >
    curl -L https://get.rvm.io
    | bash -s stable --autolibs=disable --auto-dotfiles
  args:
    creates: ~/.rvm
  sudo: yes
  sudo_user: "{{ rvm_user }}"

- name: ruby versions
  shell: >
    ~/.rvm/bin/rvm install
    {{ '--default' if item == rvm_default else '' }}
    {{ item }}
  args:
    creates: "~/.rvm/rubies/ruby-{{ item }}"
  sudo: yes
  sudo_user: "{{ rvm_user }}"
  with_flattened:
  - rvm_rubies
  - "{{ rvm_default }}"

- name: facts
  set_fact:
    RUBY_PREFIX: '~/.rvm/bin/rvm default do '
    RUBY_BIN: '/home/{{ rvm_user }}/.rvm/gems/ruby-{{ rvm_default }}/wrappers/ruby'

- name: install gems
  shell: >
    {{RUBY_PREFIX}} gem install {{item}}
  sudo: yes
  sudo_user: "{{ rvm_user }}"
  with_flattened:
  - rvm_install_gems

Revert "added 'changed_when' to indicate whether the gems had been installed or not"
Revert "added 'changed_when' to indicate whether the gems had been installed or not"

This reverts commit 529715bd34b29e3a78d817b95d08b61bfa063323.
