geerlingguy/ansible-role-ruby

Gems are not installing with user permissions

SturmB opened this issue · 2 comments

I'm still pretty new to Ruby and Ansible, but I think I've got a halfway-decent grasp of the basics.

That said, I don't know what to do to get gems like colorls and lolcat to work. I've installed them using this role:

# vars.yml
ruby_install_gems:
  - colorls
  - lolcat
ruby_install_gems_user: "sturm"

However, when I SSH into the machine where this role was run, I cannot run colorls I cannot even run any gem installation:

 sturm@ansible-test  ~  colorls

 sturm@ansible-test  ~  gem which colorls
/home/sturm/.gem/ruby/2.5.0/gems/colorls-1.4.1/lib/colorls.rb

 sturm@ansible-test  ~  gem install colorls
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /var/lib/gems/2.5.0 directory.

 sturm@ansible-test  ~ 

This is on a DigitalOcean freshly-created Ubuntu 18.04 droplet. It was even created with Ansible. If it helps, here's the playbook containing tasks for after the provisioning of the droplet:

---
# digitalocean.yml
- hosts: do
  remote_user: root
  gather_facts: false

  vars_files:
    - vars.yml

  pre_tasks:
    - name: Wait for port 22 to become available
      local_action: "wait_for port=22 host={{ inventory_hostname }}"
    
    - name: Gathering Facts
      setup:

  tasks:
    - name: Ensure user is created
      include_role:
        name: weareinteractive.users

    - name: Ensure git is installed
      import_role:
        name: geerlingguy.git

    - name: Ensure zsh and all plugins are installed
      include_role:
        name: viasite-ansible.zsh

    - name: Ensure Ruby and gems are installed
      include_role:
        name: geerlingguy.ruby

- hosts: do
  remote_user: "{{ users[0].username }}"
  gather_facts: false

  vars_files:
    - vars.yml

  tasks:
    - name: Ensure SSH key pair is created
      openssh_keypair:
        path: ~/.ssh/id_github
        state: present
        type: "ed25519"
        comment: "test@digitalocean"
      register: keys

    - name: Ensure SSH key is on GitHub
      github_key:
        name: "test@digitalocean"
        token: "{{ github_access_token }}"
        state: present
        pubkey: "{{ keys.public_key }}"

Please let me know if you need any more information.

stale commented

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale commented

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.