Skip to content

Instantly share code, notes, and snippets.

@h0tw1r3
Created August 29, 2022 16:40
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 h0tw1r3/53762932b31dd9cd2a3cf186ffd41fab to your computer and use it in GitHub Desktop.
Save h0tw1r3/53762932b31dd9cd2a3cf186ffd41fab to your computer and use it in GitHub Desktop.
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