# Running Ruby 2.6 from /etc/profile.d via Ansible Playbook in RHEL 7

**URL:** <https://forum.ansible.com/t/running-ruby-2-6-from-etc-profile-d-via-ansible-playbook-in-rhel-7/33092>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [June 4, 2020, 2:20pm UTC](https://forum.ansible.com/t/running-ruby-2-6-from-etc-profile-d-via-ansible-playbook-in-rhel-7/33092 "2020-06-04T14:20:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [June 4, 2020, 2:20pm UTC](https://forum.ansible.com/t/running-ruby-2-6-from-etc-profile-d-via-ansible-playbook-in-rhel-7/33092/1 "2020-06-04T14:20:47Z")

</div>

I have a role I’m testing that will install Redmine ([www.redmine.org](http://www.redmine.org)) on to a RHEL 7.8 machine. Redmine requires Ruby \>= 2.3. So I’m installing Ruby 2.6.2 via the rhel-server-rhscl-7-rpms repository. If I log into the machine manually and check the Ruby version, its 2.6.2. However, when I connect via my Ansible playbook, Ruby is the default 2.0, so I can’t get any of the Ruby Gems to install since the version is too old.

Here’s the relevant plays/errors:  
The /etc/profile.d/enableruby26.sh, as installed by another role i wrote that installs Ruby 2.6.2 and uploads this script to /etc/profile.d:

#!/bin/bash  
source scl\_source enable rh-ruby26

Play:

- name: Make sure to run the newer Ruby if necessary  
shell: source /etc/profile.d/enableruby26.sh  
when: ansible\_os\_family == ‘RedHat’ and ansible\_distribution\_major\_version == ‘7’

Errors:

TASK [redmine : Verify Ruby version] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [role-test]

TASK [redmine : Print Ruby version] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [role-test] =\> {  
“msg”: “ruby 2.0.0p648 (2015-12-16) [x86\_64-linux]”  
}

TASK [redmine : Obtain gem path] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [role-test]

TASK [redmine : Print gem path] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [role-test] =\> {  
“msg”: “/bin/gem”  
}

TASK [redmine : Install latest Bundler gem (RHEL 7)] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [role-test]: FAILED! =\> {“changed”: false, “cmd”: “/opt/rh/rh-ruby26/root/usr/bin/gem query --remote -n ‘^bundler$’”, “msg”: “/opt/rh/rh-ruby26/root/usr/bin/ruby: error while loading shared libraries: libruby.so.2.6: cannot open shared object file: No such file or directory”, “rc”: 127, “stderr”: “/opt/rh/rh-ruby26/root/usr/bin/ruby: error while loading shared libraries: libruby.so.2.6: cannot open shared object file: No such file or directory\n”, “stderr\_lines”: [“/opt/rh/rh-ruby26/root/usr/bin/ruby: error while loading shared libraries: libruby.so.2.6: cannot open shared object file: No such file or directory”], “stdout”: “”, “stdout\_lines”: }

So, how do I get the /etc/profile.d/enableruby26.sh to run and have its variables available within my Ansible playbook?

Thanks,  
Harry
