Rbenv in a playbook / executing a handler immediately

443 views
Skip to first unread message

Ian Young

unread,
Aug 28, 2013, 5:04:25 PM8/28/13
to ansible...@googlegroups.com
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

James Cammarata

unread,
Aug 28, 2013, 5:08:31 PM8/28/13
to ansible...@googlegroups.com
Yes, you can add 'meta: flush_handlers' as a task and it will run any handlers that have been notified up to that point. This is documented in the playbook section if you want to read up on it more:



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--

James Cammarata <jcamm...@ansibleworks.com>
Sr. Software Engineer, AnsibleWorks, Inc.
http://www.ansibleworks.com/
Reply all
Reply to author
Forward
0 new messages