Created
April 20, 2011 14:56
-
-
Save kwilczynski/931552 to your computer and use it in GitHub Desktop.
Puppet and The Magic of Define
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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