- From: Norbert Hartl <
>
- To:
- Subject: [chef] Re: Re: What can be used in not_if / how to build something that can be used?
- Date: Wed, 21 Sep 2011 15:59:23 +0200
Am 21.09.2011 um 14:27 schrieb Bryan McLellan:
>
On Wed, Sep 21, 2011 at 8:11 AM, Norbert Hartl
>
<
>
>
wrote:
>
> Now I try to integrate the stuff a little bit more and make it more
>
> reliable. One of the things I do is to check condition that decide if a
>
> action needs to take place or not. In the tutorials/examples this almost
>
> all the time done using something like "unless File.exists....". I need to
>
> do something similar but for another running component. The task is to
>
> load some code into server. In order not to load the code every single
>
> provisioning time I like to check if it has been loaded already. I know
>
> how to do it with execute/script/bash... but then I have to write the
>
> specific action it has to do (that follows the condition) within the
>
> action. But I need the capabiltiy of checking things in the server quite
>
> often. So I'm looking for slightly more generic way of achieving it.
>
> I don't know if it is possible to create a definition function, an action
>
> or anything that returns a value and therefor can be used in not_if,
>
> only_if, etc. I had the impression LWRP could help but know I don't know
>
> how. My last ressort seems to be writing a library that I include in a
>
> recipe. But I wanted to ask if there is a better possibility to achieve
>
> the same.
>
>
only_if and not_if either run a ruby block, or execute a command,
>
depending on if their argument is a block or a string. Since you know
>
how to perform your test in bash, you could put that in a string:
>
>
# store our shell command in a string
>
test_conditional = "test 1 -lt 5"
>
>
# echo run only if our previously set shell command exits with 0
>
execute "test" do
>
command "echo run"
>
only_if test_conditional
>
end
thank you guys!
Didn't know about a string being evaluated as command. The command I need to
evaluate is about 10 to 20 lines. I've built a library the contructs the
proper strings and that I use. So I do basically
...
script "install seaside" do
interpreter "bash"
...
not_if GemStone.isDefinedClass("stone-default", "WASession")
end
To me it looks as nice as it has to be. Great stuff! And I like that
libraries are visible everywhere.
Norbert
Archive powered by MHonArc 2.6.16.