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

I have a role I’m testing that will install Redmine (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