简体   繁体   中英

use lwrp with chef-solo

I'm using chef-solo with librarian-chef to manage my servers. Here's the structure I have locally:

Cheffile Cheffile.lock cookbooks data_bags Gemfile Gemfile.lock .git .gitignore nodes README.md roles tmp

Each node from the nodes/ dir has a role defined and I've added most of the generic attributes in the roles.

I've included the nrpe cookbook in one of the roles and it's working for the generic part:

```

"apache" => {

    "timeout" => 5,
    "keep_alive" => 'On',
    "max_keep_alive_requests" => 100,
    "keep_alive_timeout" => 5,

    "prefork" => {
        "start_servers" => 5,
        "min_spare_servers" => 5,
        "max_spare_servers" => 10,
        "max_clients" => 100,
        "max_requests_per_child" => 1000
    }
},
"nrpe" => {
    "server_port" => 5666,
    "connection_timeout" => 300,
    "dont_blame_nrpe" => 1,
    "command_timeout" => 60,
    "allowed_hosts" => ["10.1.1.10,10.11.1.11"],

 }

} override_attributes(attrs)

```

I'm now trying to use the LWRP provided by the cookbook to set up checks in the chef created nrpe.cfg

Any syntax I was able to think about doesn't seem to work though. The knife solo bootstrap nodename either exits with syntax errors or completes, but nothing is added on the node. Any insight on how to add this:

nagios_nrpecheck 'check_load' do command "#{node['nagios']['plugin_dir']}/check_load" warning_condition '6' critical_condition '10' action :add end

in the nrpe block from the role file above will be much appreciated.

Thanks!

You can't add an LWRP to a runlist in a role. You must wrap the LWRP declaration in a recipe and then add the recipe to the role's runlist or the nodes runlist.

my_wrapper_cookbook/recipes/nrpecheck.rb

nagios_nrpecheck 'check_load' do
  command "#{node['nagios']['plugin_dir']}/check_load"
  warning_condition '6'
  critical_condition '10'
  action :add
end

role

....
  run_list: {
    "recipe[my_wrapper_cookbook::nrpecheck]"
  }
....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM