Skip to content

Instantly share code, notes, and snippets.

@kwilczynski
Created April 20, 2011 14:56
Show Gist options
  • Save kwilczynski/931552 to your computer and use it in GitHub Desktop.
Save kwilczynski/931552 to your computer and use it in GitHub Desktop.
Puppet and The Magic of Define
# The following monstrosity ...
class test { }
define test::a($array) {
test::iterator { $name:
array => $array
}
}
define test::iterator($array) {
$i = inline_template('<%= array.collect { |i| "#{name}_#{i}" }.join("|") %>')
$j = split($i, "\\|")
notice $j
test::action { $j: }
}
define test::action {
notice $name
}
$a = [ 'a', 'b', 'c' ]
test::a {
"foo":
array => $a;
"bar":
array => $a;
}
# Will produce the following ...
kwilczynski@dev04:~/Development/Sandbox$ puppet test.pp
notice: Scope(Test::Iterator[foo]): foo_a foo_b foo_c
notice: Scope(Test::Iterator[bar]): bar_a bar_b bar_c
notice: Scope(Test::Action[foo_a]): foo_a
notice: Scope(Test::Action[foo_b]): foo_b
notice: Scope(Test::Action[foo_c]): foo_c
notice: Scope(Test::Action[bar_a]): bar_a
notice: Scope(Test::Action[bar_b]): bar_b
notice: Scope(Test::Action[bar_c]): bar_c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment