Skip to content

Instantly share code, notes, and snippets.

@apchamberlain
Last active September 9, 2015 14:19
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 apchamberlain/9121140 to your computer and use it in GitHub Desktop.
Save apchamberlain/9121140 to your computer and use it in GitHub Desktop.
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