- From: Matt Ray <
>
- To: "
" <
>
- Subject: [chef] RE: Passing responses back to Chef?
- Date: Tue, 6 Aug 2013 19:00:20 +0000
- Accept-language: en-US
This is where you'd want to use mixlib-shellout in your recipes. It captures
all the stdout and stderr on a command, you can then process it in Ruby. Take
a look at this example.
https://github.com/opscode-cookbooks/pxe_dust/blob/master/recipes/bootstrap_template.rb#L33
https://github.com/opscode/mixlib-shellout
Thanks,
Matt Ray
Cloud Integrations Product Lead :: Opscode
512.731.2218 ::
mattray :: GitHub :: IRC :: Twitter
________________________________________
From: Brad Knowles
<
>
Sent: Tuesday, August 06, 2013 1:16 PM
To:
Cc: Brad Knowles
Subject: [chef] Passing responses back to Chef?
Folks,
Okay, so I have to be missing something really basic and easy, only I can't
figure out what it is. I was hoping someone here might be able to clue me in.
We're using a modified version of the mysql cookbook, and trying to detect
which version of the MySQL Engine that the user wants to install, and turn
that into a full version string that could be passed to the package manager
via the package resource.
I know how to access the desired engine version (major.minor.patch), and I
figured out a way to determine what the full version string is of the package
that might match -- e.g., "5.1.70" might translate to
"5.1.70-0ubuntu0.10.04.1".
What I can't figure out is how to pass that full version string information
back to Chef. Setting a shell environment variable doesn't help, because the
environment of the parent process isn't affected by the child process(es), as
explained at <
http://docs.opscode.com/essentials_environment_variables.html>:
From a shell, the source command can be used to reload a given
initialization file; however, since child processes do not affect
their parent’s environment, using a script or execute resource to
run source from inside a recipe will have no effect on the
environment for the chef-client
It also doesn't help to put that information into a file that could be
"sourced" from Chef, because you'd have to go through a bash resource as a
child process, as explained at
<
http://docs.opscode.com/resource_execute.html>, because this would get done
as a child process:
Instead, use the script resource or one of the script-based resources
(bash, csh, perl, python, or ruby). For example:
bash "foo" do
code "source /tmp/foo.sh"
end
So, how else do you get a child process to pass information back to Chef in a
useful manner?
--
Brad Knowles
<
>
LinkedIn Profile: <
http://tinyurl.com/y8kpxu>
Archive powered by MHonArc 2.6.16.