Hi,
this is my first post and I’m learning chef at the moment. I’m using veewee, vagrant and chef to bootstrap an appliance for me. The basic machine is bootstrapped and running. Nice tool you did
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.
I hope I could explain my problem in a proper way. I’m not used to chef terminology, yet. Sorry for that.
thanks in advance,
Norbert
not_if / only_if are based on exit code of check line.
You can have a simple script that will check if code should be uploaded
or not, and the script should return ether 0 / 1
For example, using execute resource:
execute "code_upload" do
command "my_code_upload_script" # this is the script that will upload
code
action :run
not_if "my_code_exists_check_script" # this is the script that will
check if code is already uploaded or not
end
Another good way may be to move everything to ruby, and use more ruby in
your recipes
On 9/21/11 3:11 PM, Norbert Hartl wrote:
Hi,
this is my first post and I'm learning chef at the moment. I'm using veewee, vagrant and chef to bootstrap an appliance for me. The basic machine is bootstrapped and running. Nice tool you did
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.
I hope I could explain my problem in a proper way. I'm not used to chef terminology, yet. Sorry for that.
thanks in advance,
Norbert
--
Vladimir Girnet
Infrastructure Engineer
Tacit Knowledge
On Wed, Sep 21, 2011 at 8:11 AM, Norbert Hartl norbert@hartl.name 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
Am 21.09.2011 um 14:27 schrieb Bryan McLellan:
On Wed, Sep 21, 2011 at 8:11 AM, Norbert Hartl norbert@hartl.name 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