I developed an Ansible role that installs chruby and another one that installs ruby using ruby-install.
I would like to use chruby in my Ansible playbooks, but the chruby
command is not available to the command
and shell
modules, even if chruby works fine if I login via SSH with the same user I am running the playbook with.
This is what I tried:
Ensuring that chruby is available to all users by deploying the following script to /etc/profile.d/chruby.sh
, as suggested in chruby's README:
if [ -n "$BASH_VERSION" ] || [ -n "$ZSH_VERSION" ]; then
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
fi
Running a task with the command
or shell
modules (using /bin/bash
as executable) to manually run source /usr/local/share/chruby/chruby.sh
and source /usr/local/share/chruby/auto.sh
before executing a command
task for chruby
In both cases I got the following error: chruby: command not found
.
How can I run chruby within an Ansible play?
You can write simple bash/etc script or you can source those files:
shell: bash -c "source /usr/local/share/chruby/chruby.sh; source /usr/local/share/chruby/auto.sh;chruby ..."