Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Forked from btm/default.rb
Created April 9, 2009 04:59
Show Gist options
  • Save jtimberman/92249 to your computer and use it in GitHub Desktop.
Save jtimberman/92249 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 -%>
$ cat /tmp/foo
# Chef test
ubuntu804vm
10.13.37.116
Ubuntu
ubuntu2vm
10.13.37.117
Ubuntu
centos1vm
10.13.37.120
ops1vm
10.13.37.111
Ubuntu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment