Created
December 9, 2010 21:56
-
-
Save jordansissel/735396 to your computer and use it in GitHub Desktop.
Exported resource query/collection in ruby puppet dsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FACTER_fqdn=host1 puppet --certname host1 --node_name fqdn --storeconfigs --dblocation /tmp/puppet.sqlite -e '@@nagios_hostgroup { "mygroup": notes => "Hello"; }' | |
FACTER_fqdn=host2 puppet --certname host2 --node_name fqdn --storeconfigs --dblocation /tmp/puppet.sqlite -e '@@nagios_hostgroup { "mygroup": notes => "Hello"; }' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define a class that provides a bunch of Nagios_hostgroup resources. | |
# These resources are defined by already-exported Nagios_hostgroups. | |
# This will also go through and prune out duplicate exports. | |
require "puppet/rails/resource" | |
hostclass :happy do | |
found = Set.new | |
Puppet::Rails::Resource.find_all_by_restype("Nagios_hostgroup").each do |resource| | |
# Skip duplicate resource titles | |
key = [resource.restype, resource.title] | |
next if found.include?(key) | |
found << key | |
# Build a hash of parameters for this resource | |
params = {} | |
resource.param_values.each do |pv| | |
name = pv.param_name.name | |
params[name] = pv.value | |
end | |
# Override the target file for this example | |
params[:target] = "/tmp/example_nagios_config" | |
# Now create the resource. | |
nagios_hostgroup resource.title, params | |
end | |
end | |
node :default do | |
include "happy" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% puppet apply --verbose --storeconfig --dblocation /tmp/puppet.sqlite testpuppet.rb | |
info: Connecting to sqlite3 database: /tmp/puppet.sqlite | |
info: Caching catalog for snack.home | |
info: Applying configuration version '1291931649' | |
notice: /Stage[main]/Happy/Nagios_hostgroup[mygroup]/ensure: created |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
snack(~) % cat /tmp/example_nagios_config | |
# HEADER: This file was autogenerated at Thu Dec 09 13:54:10 -0800 2010 | |
# HEADER: by puppet. While it can still be managed manually, it | |
# HEADER: is definitely not recommended. | |
define hostgroup { | |
notes Hello | |
hostgroup_name mygroup | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this:
# Build a hash of parameters for this resource
params = Hash[ resource.param_values.map{ |pv| [ pv.param_name.name, pv.value ] } ]