hello. i’d like to test that a dir path is separately mounted filesystem.
and if it is, place a config file there via a template. what are the best
ways to do that?
just today i tried to poke at using shell_out, drawing from examples from
other cookbooks. but i’m failing at that. i’m also new to wielding
begin/rescue. my intention is for the chef-client run to fail if if the
mount point isn’t mounted.
is shell_out a decent way to test the mount? any advice?
my recipe snippet and error:
require 'chef/mixin/shell_out’
require 'chef/mixin/language’
include Chef::Mixin::ShellOut
if node[‘ec2’]
begin
ebs_mounted = true if shell_out(“grep /ebs /proc/mounts 2>&1 | grep -q md[1-9]”)
Chef::Log.info(“HIGGS-BOSON: /ebs is mounted.”)
rescue
Chef::Log.fatal(“HIGGS-BOSON: /ebs is not mounted.”)
raise
end
end
[Tue, 25 Sep 2012 19:36:08 +0000] DEBUG: Re-raising exception: NameError - Cannot find a resource for include on centos version 5.8
/opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/resource_platform_map.rb:129:in get' /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/resource.rb:667:inresource_for_platform’
/opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/resource.rb:684:in resource_for_node' /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/mixin/recipe_definition_dsl_core.rb:58:inmethod_missing’
/var/cache/chef/cookbooks/cupcake-percona/recipes/percona-setup.rb:14:in from_file' /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/mixin/from_file.rb:30:ininstance_eval’
/opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/mixin/from_file.rb:30:in from_file' /opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/cookbook_version.rb:578:inload_recipe’
i can place the config file under the right circumstances using only_if within
a template resource block. this does the right thing, but it is silent about
it. i’d prefer it fail, or notify me. i guess i could set up a chef_handler for
the notification, but i’d like to hear thoughts on my attempt with shellout and
begin/rescue.
template “#{node[‘thing’][‘conf_dir’]}/config.conf” do
source "config.conf.erb"
owner "root"
mode "0644"
only_if "grep /ebs /proc/mounts 2>&1 | grep -q md[1-9]"
end
hello. i'd like to test that a dir path is separately mounted filesystem.
and if it is, place a config file there via a template. what are the best
ways to do that?
just today i tried to poke at using shell_out, drawing from examples from
other cookbooks. but i'm failing at that. i'm also new to wielding
begin/rescue. my intention is for the chef-client run to fail if if the
mount point isn't mounted.
is shell_out a decent way to test the mount? any advice?
my recipe snippet and error:
require 'chef/mixin/shell_out'
require 'chef/mixin/language'
include Chef::Mixin::ShellOut
if node['ec2']
begin
ebs_mounted = true if shell_out("grep /ebs /proc/mounts 2>&1 | grep -q
md[1-9]")
Chef::Log.info("HIGGS-BOSON: /ebs is mounted.")
rescue
Chef::Log.fatal("HIGGS-BOSON: /ebs is not mounted.")
raise
end
end
[Tue, 25 Sep 2012 19:36:08 +0000] DEBUG: Re-raising exception: NameError -
Cannot find a resource for include on centos version 5.8
/opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/resource_platform_map.rb:129:in
`get'
i can place the config file under the right circumstances using only_if
within
a template resource block. this does the right thing, but it is silent
about
it. i'd prefer it fail, or notify me. i guess i could set up a
chef_handler for
the notification, but i'd like to hear thoughts on my attempt with
shellout and
begin/rescue.
template "#{node['thing']['conf_dir']}/config.conf" do
source "config.conf.erb"
owner "root"
mode "0644"
only_if "grep /ebs /proc/mounts 2>&1 | grep -q md[1-9]"
end
You can't mix a module into the chef recipe DSL, the way it is evaluating
is trying to find a Chef resource for 'include' statement.
Try to require then Chef::Mixin:: ShellOut.shell_out "foo"
cool... so my approach to the task using shell_out and begin/rescue is
sane, if not good? i'll try to get back to this soon to get it to work.
yay context-switching.
The Higgs Boson logging messages always crack me up.
:> .. yeah, it gives me something easy to grep for.
hello. i'd like to test that a dir path is separately mounted filesystem.
and if it is, place a config file there via a template. what are the best
ways to do that?
just today i tried to poke at using shell_out, drawing from examples from
other cookbooks. but i'm failing at that. i'm also new to wielding
begin/rescue. my intention is for the chef-client run to fail if if the
mount point isn't mounted.
is shell_out a decent way to test the mount? any advice?
my recipe snippet and error:
require 'chef/mixin/shell_out'
require 'chef/mixin/language'
include Chef::Mixin::ShellOut
if node['ec2']
begin
ebs_mounted = true if shell_out("grep /ebs /proc/mounts 2>&1 | grep -q
md[1-9]")
Chef::Log.info("HIGGS-BOSON: /ebs is mounted.")
rescue
Chef::Log.fatal("HIGGS-BOSON: /ebs is not mounted.")
raise
end
end
[Tue, 25 Sep 2012 19:36:08 +0000] DEBUG: Re-raising exception: NameError -
Cannot find a resource for include on centos version 5.8
/opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/resource_platform_map.rb:129:in
`get'
i can place the config file under the right circumstances using only_if
within
a template resource block. this does the right thing, but it is silent
about
it. i'd prefer it fail, or notify me. i guess i could set up a
chef_handler for
the notification, but i'd like to hear thoughts on my attempt with
shellout and
begin/rescue.
template "#{node['thing']['conf_dir']}/config.conf" do
source "config.conf.erb"
owner "root"
mode "0644"
only_if "grep /ebs /proc/mounts 2>&1 | grep -q md[1-9]"
end
cool... so my approach to the task using shell_out and begin/rescue is
sane, if not good?
Seems like you're expecting shell_out to raise an exception if the
grep command doesn't find the mount. That's not how shell_out works,
so your rescue block will never run.
Instead you should be checking #exitstatus:
if node['ec2']
ebs_mounted = shell_out("grep /ebs /proc/mounts 2>&1 | grep -q
md[1-9]").exitstatus.zero?
end
cool... so my approach to the task using shell_out and begin/rescue is
sane, if not good?
Seems like you're expecting shell_out to raise an exception if the
grep command doesn't find the mount. That's not how shell_out works,
so your rescue block will never run.
Instead you should be checking #exitstatus:
if node['ec2']
ebs_mounted = shell_out("grep /ebs /proc/mounts 2>&1 | grep -q
md[1-9]").exitstatus.zero?
end
cool... so my approach to the task using shell_out and begin/rescue is
sane, if not good?
Seems like you're expecting shell_out to raise an exception if the
grep command doesn't find the mount. That's not how shell_out works,
so your rescue block will never run.
Instead you should be checking #exitstatus:
if node['ec2']
ebs_mounted = shell_out("grep /ebs /proc/mounts 2>&1 | grep -q
md[1-9]").exitstatus.zero?
end
Why not just open /proc/mounts and read it?
Shelling out of ruby code to run a grep pipe seems overly complicated
and fragile.
On Tue, Sep 25, 2012 at 3:18 PM, Booker Bense bbense@gmail.com wrote:
Why not just open /proc/mounts and read it?
Shelling out of ruby code to run a grep pipe seems overly complicated
and fragile.
if node['ecs']
mnt = Array.new
File.open '/proc/mounts' do |io|
mnt = io.grep(//ebs.*md[1-9]/ )
end
if ( mnt.empty?)
# Fail
else
# Create awesome
end
end
If you can write your shell_out in a few lines of Ruby, it is almost
always faster, simpler and more robust. It is very easy to generate a
false positive error return from a shell command. Because what you're
actually testing is the execution of the shell, not the actual result.
"The Ruby Way" is an excellent source of recipes for doing basic shell stuff.
You can't mix a module into the chef recipe DSL, the way it is evaluating
is trying to find a Chef resource for 'include' statement.
Try to require then Chef::Mixin:: ShellOut.shell_out "foo"
hi. i probably won't use shell_out for my task of detecting a mounted fs, but
i'd still like to be able to wield shell_out in case i want it in the future.
and i'm still failing:
hello. i'd like to test that a dir path is separately mounted filesystem.
and if it is, place a config file there via a template. what are the best
ways to do that?
just today i tried to poke at using shell_out, drawing from examples from
other cookbooks. but i'm failing at that. i'm also new to wielding
begin/rescue. my intention is for the chef-client run to fail if if the
mount point isn't mounted.
is shell_out a decent way to test the mount? any advice?
my recipe snippet and error:
require 'chef/mixin/shell_out'
require 'chef/mixin/language'
include Chef::Mixin::ShellOut
if node['ec2']
begin
ebs_mounted = true if shell_out("grep /ebs /proc/mounts 2>&1 | grep -q
md[1-9]")
Chef::Log.info("HIGGS-BOSON: /ebs is mounted.")
rescue
Chef::Log.fatal("HIGGS-BOSON: /ebs is not mounted.")
raise
end
end
[Tue, 25 Sep 2012 19:36:08 +0000] DEBUG: Re-raising exception: NameError -
Cannot find a resource for include on centos version 5.8
/opt/opscode/embedded/lib/ruby/gems/1.9.1/gems/chef-0.10.10/lib/chef/resource_platform_map.rb:129:in
`get'
i can place the config file under the right circumstances using only_if
within
a template resource block. this does the right thing, but it is silent
about
it. i'd prefer it fail, or notify me. i guess i could set up a
chef_handler for
the notification, but i'd like to hear thoughts on my attempt with
shellout and
begin/rescue.
template "#{node['thing']['conf_dir']}/config.conf" do
source "config.conf.erb"
owner "root"
mode "0644"
only_if "grep /ebs /proc/mounts 2>&1 | grep -q md[1-9]"
end
You can't mix a module into the chef recipe DSL, the way it is evaluating
is trying to find a Chef resource for 'include' statement.
Try to require then Chef::Mixin:: ShellOut.shell_out "foo"
hi. i probably won't use shell_out for my task of detecting a mounted fs,
but
i'd still like to be able to wield shell_out in case i want it in the
future.
and i'm still failing:
hello. i'd like to test that a dir path is separately mounted
filesystem.
and if it is, place a config file there via a template. what are the
best
ways to do that?
just today i tried to poke at using shell_out, drawing from examples
from
other cookbooks. but i'm failing at that. i'm also new to wielding
begin/rescue. my intention is for the chef-client run to fail if if the
mount point isn't mounted.
is shell_out a decent way to test the mount? any advice?
my recipe snippet and error:
require 'chef/mixin/shell_out'
require 'chef/mixin/language'
include Chef::Mixin::ShellOut
if node['ec2']
begin
ebs_mounted = true if shell_out("grep /ebs /proc/mounts 2>&1 |
grep -q
md[1-9]")
Chef::Log.info("HIGGS-BOSON: /ebs is mounted.")
rescue
Chef::Log.fatal("HIGGS-BOSON: /ebs is not mounted.")
raise
end
end
[Tue, 25 Sep 2012 19:36:08 +0000] DEBUG: Re-raising exception:
NameError -
Cannot find a resource for include on centos version 5.8
i can place the config file under the right circumstances using only_if
within
a template resource block. this does the right thing, but it is silent
about
it. i'd prefer it fail, or notify me. i guess i could set up a
chef_handler for
the notification, but i'd like to hear thoughts on my attempt with
shellout and
begin/rescue.
template "#{node['thing']['conf_dir']}/config.conf" do
source "config.conf.erb"
owner "root"
mode "0644"
only_if "grep /ebs /proc/mounts 2>&1 | grep -q md[1-9]"
end