Hi,
The attached script is made for those who have one node per file and want
to catch if something have been made global by being outside on the node
block.
Example:
node xxx { ... }
package{...}
if ... { ... }
which should have been
node xxx { ...
package{...}
if ... { ... }
}
Adjust the path in brackets.sh to your needs and in puppet.conf add
prerun_command = /path/to/brackets.sh
The script is READ ONLY, and doesn't change any of your files.
Please test it on your node pp files, and report any bugs =)
Hugs,
Sandra
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/puppet-users/-/iQZoA0somJ0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
#!/usr/bin/perl
use strict;
#use warnings;
#use Data::Dumper;
my $b;
my $ok;
my $node;
open (FILE, '<', "$ARGV[0]") || die "Unable to open $ARGV[0]\n";
while (defined (my $line = <FILE>)) {
next if ($line =~ /^#/); # allow comments before the node block
if ($line =~ /^node/) {
$node = 1;
}
unless ($node) {
print "ERROR: $ARGV[0] is not a valid node file. No node block found.\n";
exit 1;
}
# remove everything between " " and ' '
# these can contain # which would ruin the comment removal
$line =~ s/"[^"]*[^"]*"//g;
$line =~ s/'[^']*[^']*'//g;
my @chars = split(//, $line);
while ($line =~ /(.)/g) { # . is never a newline here
if ($1 eq "#") {last;} # found a comment. skip rest of the line
elsif ($1 eq "{") {$b .= "{"}
elsif ($1 eq "}") {$b .= "}"}
}
# a node file must end with a } and optional spaces and newlines afterwards
if ($line =~ /}\s*$/) {
$ok = 1;
} else {
undef $ok unless ($line =~ /^\s*$/);
}
}
close FILE;
# remove first { and last } which in a valid case should belong to "node xxx {}"
$b = substr($b,1);
$b = substr($b,0,length($b)-1);
while (length($b) > 2 || $b eq "{}") {
$b = join "", (split (/{}/, $b));
}
if ($b eq "" && $ok) {
exit 0;
} elsif ($b eq "" && !$ok) {
print "ERROR: $ARGV[0] have atleast one line after the node {} block.\n";
exit 1;
} else {
print "ERROR: $ARGV[0] have a {} block after the node {} block. Not allowed.\n";
exit 1;
}
#!/bin/bash
for f in /etc/puppet/nodes/*.pp; do
/etc/puppet/nodes/brackets.pl $f
done