I had the same problem when trying to install ruby-2.2.3 using rbenv using Ansible 2.1 on the firewall.
rbenv was installed on a user on ubuntu called rails , which does not have sudo privileges, but when ansible connects to my ubuntu box, it loses env. $ PATH defined in /home/rails/.bashrc, by default was only ansible_env.PATH
Assuming you installed rbenv, follow these steps:
git clone git://github.com/sstephenson/rbenv.git .rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc source ~/.bashrc
in order to get the path to work, I needed to install it manually, so for this specific task I did:
- name: install rubies become_user: rails environment: PATH: "{{ ansible_env.PATH }}:/home/rails/.rbenv/shims:/home/rails/.rbenv/bin " shell: '{{ rbenv_shell }} -lc "rbenv install {{ item[0] }}"' with_together - "{{ rubies }}" - "{{ ruby_installed.results }}" ...
This will add the path to your rbenv command to search for ansible_env.PATH and make it work as expected.
source share