title: Install Bundler gem using Ansible
body: <p>I am trying to install Bundler on my VPS using Ansible.</p>
  
  <p>I already have rbenv set up and the global ruby is 2.1.0.</p>
  
  <p>If I SSH as root into the server and run <code>gem install bundler</code>, it installs perfectly.</p>
  
  <p>I have tried the following three ways of using Ansible to install the Bundler gem and all three produce no errors, but when I SSH in and run <code>gem list</code>, Bundler is nowhere to be seen.</p>
  
  <p>Attempt 1:</p>
  
  <pre><code>---
  - name: Install Bundler
    shell: gem install bundler
  </code></pre>
  
  <p>Attempt 2:</p>
  
  <pre><code>---
  - name: Install Bundler
    shell: gem install bundler
  </code></pre>
  
  <p>Attempt 3:</p>
  
  <pre><code>---
  - name: Install Bundler
    gem: name=bundler
         state=latest
  </code></pre>
  
  <p>I have also tried the last attempt with <code>user_install=yes</code> and also with <code>user_install=no</code> and neither make any difference.</p>
  
  <p>Any ideas how I can get it to install Bundler correctly via Ansible?</p>
  
  <p>I've been working on this for a little while now and I have 1 ruby version installed: 2.1.0 and ahve found that the shims directory for rbenv does not contain a shim for <code>bundle</code>.</p>
  
  <p>Should a shim for <code>bundle</code> be in there? I'm just getting confused as to why capistrano cannot find the <code>bundle</code> command as it's listed when I run <code>sudo gem list</code> but NOT when I run <code>gem list</code>?</p>
  
  <pre><code>root@weepingangel:/usr/local/rbenv/shims# echo $PATH
  /usr/local/rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
  root@weepingangel:/usr/local/rbenv/shims# gem environment
  RubyGems Environment:
    - RUBYGEMS VERSION: 2.2.0
    - RUBY VERSION: 2.1.0 (2013-12-25 patchlevel 0) [x86_64-linux]
    - INSTALLATION DIRECTORY: /usr/local/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0
    - RUBY EXECUTABLE: /usr/local/rbenv/versions/2.1.0/bin/ruby
    - EXECUTABLE DIRECTORY: /usr/local/rbenv/versions/2.1.0/bin
    - SPEC CACHE DIRECTORY: /root/.gem/specs
    - RUBYGEMS PLATFORMS:
      - ruby
      - x86_64-linux
    - GEM PATHS:
       - /usr/local/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0
       - /root/.gem/ruby/2.1.0
    - GEM CONFIGURATION:
       - :update_sources =&gt; true
       - :verbose =&gt; true
       - :backtrace =&gt; false
       - :bulk_threshold =&gt; 1000
       - :sources =&gt; ["http://gems.rubyforge.org", "http://gems.github.com"]
       - "gem" =&gt; "--no-ri --no-rdoc"
    - REMOTE SOURCES:
       - http://gems.rubyforge.org
       - http://gems.github.com
    - SHELL PATH:
       - /usr/local/rbenv/versions/2.1.0/bin
       - /usr/local/rbenv/libexec
       - /usr/local/rbenv/shims
       - /usr/local/sbin
       - /usr/local/bin
       - /usr/sbin
       - /usr/bin
       - /sbin
       - /bin
       - /usr/games
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>So, I think the two main problems I have:</p>
  
  <ol>
  <li><p>Why is bundler only visible when I run <code>sudo gem list</code>?</p></li>
  <li><p>My deploy is saying:</p>
  
  <pre><code>INFO [18d5838c] Running /usr/bin/env bundle install --binstubs  
  /var/rails_apps/neiltonge/shared/bin --path  
  /var/rails_apps/neiltonge/shared/bundle --without development test
  --deployment --quiet on 188.226.159.96 DEBUG [18d5838c] Command: cd /var/rails_apps/neiltonge/releases/20140301205432 &amp;&amp; ( PATH=$PATH
  /usr/bin/env bundle install --binstubs
  /var/rails_apps/neiltonge/shared/bin --path
  /var/rails_apps/neiltonge/shared/bundle --without development test
  --deployment --quiet ) DEBUG [18d5838c]     /usr/bin/env: bundle: No such file or directory
  </code></pre>
  
  <p>and this is my <code>$PATH</code>:</p>
  
  <pre><code>/usr/local/rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
  </code></pre></li>
  </ol>
  
  <p>Why can't bundle be located?</p>