2

I recently decided to switch my Ansible deployment to install Ruby via rbenv rather than from apt-get via ruby1.9.1. Now I'm getting an error when trying to install the gem via Ansible.

TASK: [nginx | s3cp gem] ****************************************************** 
failed: [staging.myapp.com] => {"cmd": ["/usr/local/bin", "query", "-n", "^s3cp$"], "failed": true, "item": "", "rc": 13}
msg: [Errno 13] Permission denied

FATAL: all hosts have already failed -- aborting

Ansible playbook entry for this command:

- name: s3cp gem
  gem: name=s3cp state=present executable=/usr/local/bin

I have sudo set to "yes" in a higher-level call to this playbook part. So I am not sure why it's tripping up. I also am able to login with the same user used for Ansible and navigate to that directory and also install this gem.

It was working fine when I was using apt-get to install ruby1.9.1. Any ideas?

This is deployed to an Ubuntu 13.04 server, by the way.

MORE INFORMATION:

Apparently it's not just tripping up on s3cp. I skipped that one and went on to another command to install bundler. This command also would not work (failed in the same way). I am wondering if there's a default ruby that's conflicting with the rbenv ruby (though, which ruby when ssh'ed in is yielding the expected rbenv directory).

MORE-MORE INFO:

I tried to install ruby via rvm instead. I had the same error. :(

Mxx
  • 8,979
  • 4
  • 27
  • 37
Neal
  • 4,468
  • 36
  • 33

2 Answers2

1

What happens when you run ansible with -vvvv? It should provide full verbose output of the tasks, hopefully including any errors that it encounters. With a bit of luck it will show you what the problem is.

Another thing to check is what user you're running the tasks as. How do you have the following parameters set at the top of your play (or do you not specify any of these)?

- hosts: myhosts
  user: someuser
  sudo: True
  sudo_user: another_user
Bruce P
  • 19,995
  • 8
  • 63
  • 73
1

As far as I know, the gem ansible module is not rbenv-aware. This means that when you call the gem module, it will try to install a gem system wide. This, of course, will fail if you're not acting as root on your node.

To install a gem with rbenv, you must use rbenv's gem shim. The only way to do this is to be able to trigger rbenv init by sending the command thru bash :

- name: Install Bundler
  command: bash -lc "gem install bundler"

This has been already adressed here : Install Bundler gem using Ansible

Community
  • 1
  • 1
leucos
  • 17,661
  • 1
  • 44
  • 34