Loading rvm in remote server before a playbook starts

Hello! Does anyone know how to load rvm in a playbook so that it’s available in {{ ansible_env.PATH }} ?

  • name: Deploy my app
    environment:
    PATH: "{{ ansible_env.PATH }}

This does not include /home/ubuntu/.rvm/gems/ruby-2.2.2/wrappers

- name: Deploy my app
environment:
   PATH: "{{ ansible_env.PATH }}

This is basically a noop, you are assigning the PATH ansible normally
gets to the PATH, also environment is not a task, it is a play/task
directive.

Hey Brian. Thanks for the response. Yeah I definitely agree this is a noop. My question is how do I make is so that it loads RVM and ansible_env.PATH will include paths such as /home/ubuntu/.rvm/gems/ruby-2.2.2/wrappers. For example, immediately when I SSH into my EC2 instance it automatically loads RVM. I’d like to do the same with ansible when I ssh.

Hi,

the problem with this is, that you are loading your .rvm environment probably
from some kind of .profile or the login shell you are using.

When Ansible does its login into the destination server it is running in an
empty environment like a cron job.

You have to wrap your script in a wrapper script, that would enable your rvm
environment inside your task. Maybe you should reconsider using a ruby version
from rvm for system tasks, you may be trying to perform.

Greetings,
/mf

I see thanks Marcus. I’ll go ahead keep fiddling with this and see what I come up with.