Hi all,
I’m new to Ansible and am working on my first project with it. I have a question about the best way to do something.
My playbook is installing Ruby through rbenv (a tool that controls the environment to permit easy switching between different Ruby builds, much like rvm). This is working great except for one thing. After a new Rubygem is installed, rbenv needs to “rehash” - regenerate the executable shims that it uses to control the environment. Within my playbook, I need to rehash several times. For example, I install the passenger gem, then must rehash before I use the passenger command-line tool.
It seems like ‘rbenv rehash’ has a lot in common with handlers. I’d like to declare the play once and refer to it by name when it needs to be executed. Ideally, I’d like to attach it to certain tasks which trigger a rehash (usually, gem installs) on change. However, I need it to run right away, not at the end of the playbook, and I need it to run multiple times within a playbook. So handlers don’t quite work for me. Is there a similar way to get the behavior I’m looking for? I’m thinking of a “run-immediately handler” type of thing.
Or, it’s possible that I’m taking a wrong approach entirely. Maybe I should somehow plug rbenv into the standard Ansible gem
module, so that the rehash happens automatically without explicit instructions from my playbook. I have no idea if or how this would be possible.
Any advice appreciated.
Ian