---

- name: Install imagemagick.
  become: Yes
  package:
    name: imagemagick
    state: present

- name: Install configured gems.
  gem: "name={{ item }} state=present"
  with_items:
    - wraith
  when: wraith_testing_framework.install | default(False)

- name: Get gems path.
  command: ruby -rubygems -e 'puts Gem.user_dir'
  become: No
  register: gems_path

# Add gems path to .bashrc for convenience when testing.
- name: Add gems path to .bashrc
  blockinfile:
    path: ~/.bashrc
    backup: True
    insertafter: EOF
    content: "export PATH={{ npm_config_prefix }}/bin:{{ gems_path.stdout }}/bin:$PATH"

- name: Add Wraith npm dependencies.
  npm:
    name: "{{ item.name | default(item) }}"
    version: "{{ item.version | default('latest') }}"
    global: Yes
    state: latest
  become: Yes
  environment:
    NPM_CONFIG_PREFIX: "{{ npm_config_prefix }}"
    NODE_PATH: "$NODE_PATH:{{ npm_config_prefix }}/lib/node_modules"
    NPM_CONFIG_UNSAFE_PERM: "{{ npm_config_unsafe_perm }}"
  with_items:
    - name: phantomjs
    - name: casperjs
  when: wraith_testing_framework.install | default(False)

---

- name: Install imagemagick.
  become: Yes
  package:
    name: imagemagick
    state: present

- name: Install configured gems.
  gem: "name={{ item }} state=present"
  with_items:
    - wraith
  when: wraith_testing_framework.install | default(False)

- name: Get gems path.
  command: ruby -rubygems -e 'puts Gem.user_dir'
  become: No
  register: gems_path
  when: gems_path is undefined

# Add gems path to .bashrc for convenience when testing.
- name: Add gems path to .bashrc
  blockinfile:
    path: ~/.bashrc
    backup: True
    insertafter: EOF
    content: "export PATH={{ npm_config_prefix }}/bin:{{ gems_path.stdout }}/bin:$PATH"

- name: Add Wraith npm dependencies.
  npm:
    name: "{{ item.name | default(item) }}"
    version: "{{ item.version | default('latest') }}"
    global: Yes
    state: latest
  become: Yes
  environment:
    NPM_CONFIG_PREFIX: "{{ npm_config_prefix }}"
    NODE_PATH: "$NODE_PATH:{{ npm_config_prefix }}/lib/node_modules"
    NPM_CONFIG_UNSAFE_PERM: "{{ npm_config_unsafe_perm }}"
  with_items:
    - name: phantomjs
    - name: casperjs
  when: wraith_testing_framework.install | default(False)

Add "when" to "Get gems path"
(wraith): Add "when" to "Get gems path"
