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
Convert an Array of Integers into an Array of Strings in Ruby
Ruby: How to Make Irb Print Structure for Arrays and Hashes
How to Make a Ruby String Safe for a Filesystem
How to List All Objects Created from a Class in Ruby
What Would a Default Getter and Setter Look Like in Rails
How to Format a Number 1000 as "1 000"
How to Set the Actionmailer Default_Url_Options's :Host Dynamically to the Request's Hostname
Rbenv Irb History Is Not Saving
Undefined Instance Method "Respond_To" in Rails 5 API Controller
Modify Ruby Hash in Place( Rails Strong Params)
Uninitialized Constant Rake::Dsl in Ruby Gem