Run arbitrary ruby code in a chef cookbook -
i have simple chef cookbook , sets motd on centos machine. takes content of /tmp/mymotd.txt , turns motd.
i have simple ruby script (a full-fledged ruby script) reads text web-server , puts in /tmp/mymotd.txt.
my questions are:
- how run ruby script within cookbook?
- how pass parameters script (e.g. address of web-server)
thanks lot beforehand.
ad 1.
you can use libraries
directory in scripts place there ruby script , declare in module. example:
# includes module module_name # here code using script # example function def example_function (text) # code end end
you can use
include module_name
in recipe import functions , use like
example_function(something)
what's - can use there chef functions , resources.
important info: remember chef has 2 compilation phases. first of ruby code, second of chef resources. means, have remember priority of code. won't write here more info it, since haven't asked this, if want, can find here.
ad 2.
you can in several ways, seems me, best option use environments
. can find more info in here. basically, can set environment script before run - way can define variables use later.
hope helps.
Comments
Post a Comment