Trigger an ohai update within a recipe?


#1

I’m running into a problem with a recipe. This seems like a common case so I’m hoping there’s a simple solution.

I have a recipe that configures a daemon (maradns fwiw) which drops root privileges to a uid/gid configured in the daemon’s config file which is generated by a template. The recipe first runs the User resource to create the user if necessary.

So the problem is, in the template I refer to node[:etc][:passwd][:maradns][:uid] and node[:etc][:group][:maradns][:gid] but at that point ohai hasn’t picked up those values and cached them so the template generation fails. On a subsequent run, the template is generated successfully.

So is there some way for me to trigger an update of ohai within the recipe? If not, I’ll file a bug for a feature request as, again, this seems like a relatively common case.


#2

Well here’s one way I found, though I’m hoping there’s something cleaner than this out there:

ruby_block “reload_ohai” do
block do
ohai = Ohai::System.new
ohai.all_plugins
node.automatic_attrs = ohai.data
node.save
end
end

I tried having this executed by a notify but it doesnt work, I think because notify appears to be non-blocking and ohai takes a few seconds to collect the data. By the time that happens, the template resource has already been called. Kindof sucks because it means this ohai reload will take place every time the script is run, not just when the user is created on the first run.


From: “Leinartas, Michael” MICHAEL.LEINARTAS@orbitz.com
Reply-To: "chef@lists.opscode.com" chef@lists.opscode.com
Date: Sat, 24 Jul 2010 20:34:26 -0500
To: "chef@lists.opscode.com" chef@lists.opscode.com
Subject: [chef] Trigger an ohai update within a recipe?

I’m running into a problem with a recipe. This seems like a common case so I’m hoping there’s a simple solution.

I have a recipe that configures a daemon (maradns fwiw) which drops root privileges to a uid/gid configured in the daemon’s config file which is generated by a template. The recipe first runs the User resource to create the user if necessary.

So the problem is, in the template I refer to node[:etc][:passwd][:maradns][:uid] and node[:etc][:group][:maradns][:gid] but at that point ohai hasn’t picked up those values and cached them so the template generation fails. On a subsequent run, the template is generated successfully.

So is there some way for me to trigger an update of ohai within the recipe? If not, I’ll file a bug for a feature request as, again, this seems like a relatively common case.


#3

Going off the top of my head, so dbl check the docs, but try:

setting ‘action :nothing’ on the ruby block

then ‘notifies :action, resources(:ruby_block => ‘reload_ohai’), :immediate’ in the resource you want to trigger the block

On Jul 24, 2010, at 11:38 PM, Leinartas, Michael wrote:

Well here’s one way I found, though I’m hoping there’s something cleaner than this out there:

ruby_block “reload_ohai” do
block do
ohai = Ohai::System.new
ohai.all_plugins
node.automatic_attrs = ohai.data
node.save
end
end

I tried having this executed by a notify but it doesnt work, I think because notify appears to be non-blocking and ohai takes a few seconds to collect the data. By the time that happens, the template resource has already been called. Kindof sucks because it means this ohai reload will take place every time the script is run, not just when the user is created on the first run.

From: “Leinartas, Michael” MICHAEL.LEINARTAS@orbitz.com
Reply-To: "chef@lists.opscode.com" chef@lists.opscode.com
Date: Sat, 24 Jul 2010 20:34:26 -0500
To: "chef@lists.opscode.com" chef@lists.opscode.com
Subject: [chef] Trigger an ohai update within a recipe?

I’m running into a problem with a recipe. This seems like a common case so I’m hoping there’s a simple solution.

I have a recipe that configures a daemon (maradns fwiw) which drops root privileges to a uid/gid configured in the daemon’s config file which is generated by a template. The recipe first runs the User resource to create the user if necessary.

So the problem is, in the template I refer to node[:etc][:passwd][:maradns][:uid] and node[:etc][:group][:maradns][:gid] but at that point ohai hasn’t picked up those values and cached them so the template generation fails. On a subsequent run, the template is generated successfully.

So is there some way for me to trigger an update of ohai within the recipe? If not, I’ll file a bug for a feature request as, again, this seems like a relatively common case.


#4

Yep - it is blocking, it is just two-phase (compile and execute.)

Adam

On Mon, Jul 26, 2010 at 12:02 PM, Alex Soto apsoto@gmail.com wrote:

Going off the top of my head, so dbl check the docs, but try:
setting ‘action :nothing’ on the ruby block
then ‘notifies :action, resources(:ruby_block => ‘reload_ohai’),
:immediate’ in the resource you want to trigger the block

On Jul 24, 2010, at 11:38 PM, Leinartas, Michael wrote:

Well here’s one way I found, though I’m hoping there’s something cleaner
than this out there:

ruby_block “reload_ohai” do
block do
ohai = Ohai::System.new
ohai.all_plugins
node.automatic_attrs = ohai.data
node.save
end
end

I tried having this executed by a notify but it doesnt work, I think because
notify appears to be non-blocking and ohai takes a few seconds to collect
the data. By the time that happens, the template resource has already been
called. Kindof sucks because it means this ohai reload will take place
every time the script is run, not just when the user is created on the first
run.


From: “Leinartas, Michael” MICHAEL.LEINARTAS@orbitz.com
Reply-To: "chef@lists.opscode.com" chef@lists.opscode.com
Date: Sat, 24 Jul 2010 20:34:26 -0500
To: "chef@lists.opscode.com" chef@lists.opscode.com
Subject: [chef] Trigger an ohai update within a recipe?

I’m running into a problem with a recipe. This seems like a common case so
I’m hoping there’s a simple solution.

I have a recipe that configures a daemon (maradns fwiw) which drops root
privileges to a uid/gid configured in the daemon’s config file which is
generated by a template. The recipe first runs the User resource to create
the user if necessary.

So the problem is, in the template I refer to
node[:etc][:passwd][:maradns][:uid] and node[:etc][:group][:maradns][:gid]
but at that point ohai hasn’t picked up those values and cached them so the
template generation fails. On a subsequent run, the template is generated
successfully.

So is there some way for me to trigger an update of ohai within the recipe?
If not, I’ll file a bug for a feature request as, again, this seems like a
relatively common case.


Opscode, Inc.
Adam Jacob, CTO
T: (206) 508-7449 E: adam@opscode.com