Install Bundler Gem Using Ansible

Install Bundler gem using Ansible

The problem is that, when running gem install bundler via ansible, you're not initializing rbenv properly, since rbenv init is run in .bashrc or .bash_profile. So the gem command used is the system one, not the one installed as a rbenv shim. So whenever you install a gem, it is installed system-wide, not in your rbenv environment.

To have rbenv initialized properly, you must execute bash itself and explicitely state that it's a login shell, so it reads it's initialization files :

ansible your_host -m command -a 'bash -lc "gem install bundler"' -u your_rbenv_user 

Leave the -u your_rbenv_user part if you really want to do this as root.

If the above command works, you can easily turn it into a playbook action :

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

It's cumbersome, but it's the only way I found so far.

how to install gems for rbenv, using Ansible

Well, you can always use the bundle from the shims directory

command: ${HOME}/.rbenv/shims/bundle install --deployment

bundle install hang while installing private gem via ansible playbook

As per @Ankit_Kukarni comment, I tried adding github.com to known_hosts file and finally it worked.

Adding following piece of code to the playbook

  - name: ensure github.com is a known host
sudo: yes
lineinfile:
dest: /home/ubuntu/.ssh/known_hosts
create: yes
state: present
line: "{{ lookup('pipe', 'ssh-keyscan -t rsa github.com') }}"
regexp: "^github\\.com"

A detail explanation can be found here



Related Topics



Leave a reply



Submit