Skip to content

Instantly share code, notes, and snippets.

@h0tw1r3
Created August 29, 2022 16:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Puppet 99 Bottles of Beer on the Wall
$bottles = Integer[0,99].map |$bottle| { abs($bottle - 99) }
$report = {
bottles => '%s bottle%s of beer on the wall, %s bottle%s of beer.',
left => '%s bottle%s of beer on the wall.',
take => 'Take one down and pass it around',
buy => 'Go to the store and buy some more',
}
$bottles.map |$bottles_on_wall| {
$bottles_left = $bottles_on_wall ? {
0 => 99,
1 => 'no more',
default => ($bottles_on_wall - 1),
}
$action = $bottles_on_wall ? {
0 => 'buy',
default => 'take',
}
$bottles_as_word = ($bottles_on_wall == 0) ? {
true => 'no more',
false => $bottles_on_wall,
}
notice(
sprintf($report['bottles'],
capitalize($bottles_as_word),
($bottles_on_wall != 1) ? { true => 's', false => '' },
$bottles_as_word,
($bottles_on_wall != 1) ? { true => 's', false => '' },
)
)
notice(
sprintf("${report[$action]}, ${report['left']}",
$bottles_left,
($bottles_left != 1) ? { true => 's', false => '' },
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment