Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Produce manifest code for testing Puppet with a catalog of 'n' classes with 'm' resources each.
#!/usr/bin/env perl
# Produce test code for 'n' classes with 'm' resources each for site.pp
#
# Usage: ./samplePPgen CLASSCOUNT RESOURCECOUNT NODENAME
# e.g., ./samplePPgen 1 1000 foo # 1 class with 1000 resources on node foo
# e.g., ./samplePPgen 1000 2 # 1000 classes with 2 resources each on default
#
# If parameters are omitted, the default output is 10 classes with 10
# file resources each, on the default node (meaning all nodes if you
# drop the generated code straight into
# /etc/puppet/puppetlabs/manifests/site.pp on your master).
use strict;
if ($ARGV[0] =~ /help/) {
print "parameters (all optional): CLASSCOUNT RESOURCECOUNT NODENAME\n";
exit (0);
}
my $classes = $ARGV[0] || 10;
my $resources = $ARGV[1] || 10;
my $nodename = $ARGV[2] ? ("'" . $ARGV[2] . "'") : "default";
my $classprefix = 'c_';
foreach my $i (1..$classes) {
$i = sprintf("%04d", $i);
print "class $classprefix$i {\n";
foreach my $j (1..$resources) {
$j = sprintf("%04d", $j);
print <<"HERE";
file { '/etc/crtestdir/c${i}r${resources}_file${j}_of_${resources}':
ensure => present,
mode => '0666',
content => 'CONTENT c${i}r${j}\\n',
}
HERE
}
print "}\n"; # matches "class"
}
print "\nnode $nodename {\n";
foreach my $i (1..$classes) {
$i = sprintf("%04d", $i);
print " include $classprefix$i\n";
}
print "}\n"; # matches "node"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.