问题
Here is example how apply cookbook to node with Chef. But nothing told about multiple nodes. For example I have a akka application, which is passed akka.cluster.seed-nodes
parameters. So the algorithm should be:
- Define array "IP" with ip addresses like [192.168.1.1], [192.168.1.2], [192.168.1.3]
- Define empty array "bootsrapped" with bootsrapped ip addresses
- starting iteration over "IP"
- invoke
knife bootstrap
with current ip and "pass"-Dakka.cluster.seed-nodes
with "bootsrapped" values - store boostrapped ip in second array
- go to 3
So the goal is to write a script that can be applied to several nodes from sever. How do so with chef?
回答1:
You wouldn't do this on the server side. In fact, the server doesn't even apply a recipe to a single node. If you want multiple chef nodes with the same recipes run on them, you would simply create multiple chef nodes and give them all the same run_list. You could package those recipes into a role, but that doesn't change the need to define each one individually.
If you wanted to scrip this, you would do so on the workstation (the node you run knife from). You could either have a small script that iterates over an array of IPs and bootstraps each one, or you could use a tool like Vagrant to define a whole cluster of nodes in a single DSL file.
来源:https://stackoverflow.com/questions/27353595/how-apply-chef-cookbook-recipes-to-multiple-nodes