geerlingguy/ansible-role-ruby

Ruby installed gems non-root user?

anton-kasperovich opened this issue · 5 comments

I used Vagrant and Ansible as provision. There is options to install gems or give access for non-root users?

I set:

ruby_install_gems: ['compass:0.12.6', 'sass:3.4.9']

All works fine, but gems installed in /root/.gem/ruby/2.1.0/bin and vagrant user doesn't has access for binary files like compass.

Solution for me, instead of using ruby_install_gems i wrote task:

  - name: Install Ruby gems
    sudo: no
    gem: name={{ item.name }} version={{ item.version }} state=present
    with_items: ruby_gems

Something I addressed in my own role a while back.

I find sudo being a great thing for node, ruby and python.
At the same time nothing works with sudo as root - so I changed it to become: yes and become_user:"{{ansible_ssh_user}}".

Works like a treat now :) - all the vm's I have my customized playbook running (via DrupalVM) are able to access any and all ruby modules required at any given time. The only issue this does introduce (which I have no care for) is that the applicable commands can't be used with sudo access from the user root.

- name: "Gems | Ensure installed and updated"
  become: yes
  become_user: "{{ ansible_ssh_user }}"
  gem: name={{ item.name }} executable={{ gem_location }} state=latest user_install=no
  with_items: "{{ ruby_gems }}"

I noticed this also.

Hopefully this works now... if some people could test it and make sure it's working for various use cases, that'd be great :)

Looks good to me, I'll test it later :)
edit: All good! :)