[chef] Re: testing for mounted fs, and trying shell_out

Chronological Thread 
  • From: AJ Christensen < >
  • To:
  • Subject: [chef] Re: testing for mounted fs, and trying shell_out
  • Date: Wed, 26 Sep 2012 09:10:35 +1200

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"

The Higgs Boson logging messages always crack me up. 



On Sep 26, 2012 8:18 AM, < "> > wrote:

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']
    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.")
    Chef::Log.fatal("HIGGS-BOSON: /ebs is not mounted.")

[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:in `resource_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:in `method_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:in `instance_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:in `load_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

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]"


Archive powered by MHonArc 2.6.16.