Puppet codes - array and looping
It does bothering me at first when I start to code in puppet. Where is my array definition and how am I going to loop. Here is the caveat right after searching for help in the puppet user group.
This is the example.
I have declared some variables at /etc/puppet/manifests/site.pp
$all_nodes = ["node1.hiu.com", "node2.hiu.com", "node3.hiu.com", "node4.hiu.com"]
Here is the code for the looping
define install_package_zookeeper {
if $fqdn == "$name" {
package { mapr-zookeeper:
ensure => present,
}
}
}
class mapr::install_zookeeper {
install_package_zookeeper { $all_nodes:;}
}
Basiscally, here is the explanation, the define function can take the argument of array and traverse the array items as a single instance. e.g.
install_package_zookeeper { ["node1.hiu.com", "node2.hiu.com", "node3.hiu.com"] }
as like this
install_package_zookeeper {
"node1.hiu.com":
.
.
"node2.hiu.com":
.
.
"node3.hiu.com":
}
So, taking the puppet default behaviour of grant is actually mean to do a looping for an array. lol
No comments:
Post a Comment