Skip to content

Instantly share code, notes, and snippets.

@schisamo
Forked from rcreasey/gamespy.ohai.erb
Created June 29, 2011 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schisamo/1055220 to your computer and use it in GitHub Desktop.
Save schisamo/1055220 to your computer and use it in GitHub Desktop.
You could put the ohai plugin file in /cookbooks/ohai/files/default/plugins and the ohai cookbook will distribute it for you.
provides "gamespy"
require_plugin "kernel"
require_plugin "network"
def get_ip_address(name, eth)
network[:interfaces][eth][:addresses].each do |key, info|
gamespy[name] = key if info['family'] == 'inet'
end
end
def has_dsr_interfaces?
return network[:interfaces].has_key?('eth0') &&
network[:interfaces].has_key?('eth1') &&
network[:interfaces].has_key?('lo:0')
end
def looks_like_matchmaking?
has_dsr_interfaces?
end
if looks_like_matchmaking?
gamespy Mash.new
get_ip_address(:private_ipv4, :eth0)
get_ip_address(:public_ipv4, :eth1)
get_ip_address(:loopback, "lo:0".to_sym)
end
# this code is not needed if use the ohai cookbook to distribute plugin
# force template creation and ohai reload in compile phase so
# the attribute data returned by the plugin data is available for
# recipes during execute phase
template "#{node[:ohai][:plugin_path]}/gamespy.rb" do
source "gamespy.ohai.erb"
owner "root"
group "root"
mode 0755
action :nothing
end.run_action(:create)
ohai 'gamespy' do
action :nothing
end.run_action(:reload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment