Skip to content

Instantly share code, notes, and snippets.

@btm
Created April 8, 2009 22:45
Show Gist options
  • Save btm/92102 to your computer and use it in GitHub Desktop.
Save btm/92102 to your computer and use it in GitHub Desktop.
#
# Author:: Bryan McLellan <btm@loftninjas.org>
# Cookbook Name:: search
# Recipe:: default
#
# Copyright 2009, Bryan McLellan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
hosts = search(:node, "*").map { |host| {
"hostname" => host["hostname"],
"fqdn" => host["fqdn"],
"domain" => host["domain"],
"ipaddress" => host["ipaddress"],
"lsb" => {
"id" => host["lsb"]["id"],
"description" => host["lsb"]["description"],
}
}
}
template "/tmp/foo" do
source "foo.erb"
mode 0644
owner "root"
group "root"
variables :hosts => hosts
end
# Chef test
<% @hosts.each do |host| -%>
<%= host["hostname"] %>
<%= host["ipaddress"] %>
<%= host["lsb"]["id"] %>
<% end -%>
[Wed, 08 Apr 2009 15:45:28 -0700] INFO: Starting Chef Run
/srv/chef/cache/cookbooks/search/recipes/default.rb:27:in `from_file': undefined method `[]' for nil:NilClass (NoMethodError)
from /srv/chef/cache/cookbooks/search/recipes/default.rb:21:in `map'
from /srv/chef/cache/cookbooks/search/recipes/default.rb:21:in `from_file'
from /var/lib/gems/1.8/gems/chef-0.5.7/lib/chef/cookbook.rb:139:in `load_recipe'
from /var/lib/gems/1.8/gems/chef-0.5.7/lib/chef/compile.rb:109:in `load_recipes'
from /var/lib/gems/1.8/gems/chef-0.5.7/lib/chef/compile.rb:101:in `each'
from /var/lib/gems/1.8/gems/chef-0.5.7/lib/chef/compile.rb:101:in `load_recipes'
from /var/lib/gems/1.8/gems/chef-0.5.7/lib/chef/client.rb:339:in `converge'
from /var/lib/gems/1.8/gems/chef-0.5.7/lib/chef/client.rb:76:in `run'
from /var/lib/gems/1.8/gems/chef-0.5.7/bin/chef-client:113
from /var/lib/gems/1.8/gems/chef-0.5.7/bin/chef-client:107:in `loop'
from /var/lib/gems/1.8/gems/chef-0.5.7/bin/chef-client:107
from /var/lib/gems/1.8/bin/chef-client:19:in `load'
from /var/lib/gems/1.8/bin/chef-client:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment