- DevOps:Puppet,Docker,and Kubernetes
- Thomas Uphill John Arundel Neependra Khare Hideto Saito Hui Chuan Chloe Lee Ke Jou Carol Hsu
- 226字
- 2021-07-09 18:32:53
Using arrays of resources
Anything that you can do to a resource, you can do to an array of resources. Use this idea to refactor your manifests to make them shorter and clearer.
How to do it…
Here are the steps to refactor using arrays of resources:
- Identify a class in your manifest where you have several instances of the same kind of resource, for example, packages:
package { 'sudo' : ensure => installed } package { 'unzip' : ensure => installed } package { 'locate' : ensure => installed } package { 'lsof' : ensure => installed } package { 'cron' : ensure => installed } package { 'rubygems' : ensure => installed }
- Group them together and replace them with a single package resource using an array:
package { [ 'cron', 'locate', 'lsof', 'rubygems', 'sudo', 'unzip' ]: ensure => installed, }
How it works…
Most of Puppet's resource types can accept an array instead of a single name, and will create one instance for each of the elements in the array. All the parameters you provide for the resource (for example, ensure => installed
) will be assigned to each of the new resource instances. This shorthand will only work when all the resources have the same attributes.
See also
- The Iterating over multiple items recipe in Chapter 1, Puppet Language and Style
推薦閱讀
- Word 2003、Excel 2003、PowerPoint 2003上機指導與練習
- 輕松學C語言
- 大數據項目管理:從規劃到實現
- 計算機圖形學
- 輕松學PHP
- 錯覺:AI 如何通過數據挖掘誤導我們
- R Machine Learning By Example
- Mastering Salesforce CRM Administration
- Blender Compositing and Post Processing
- 塊數據5.0:數據社會學的理論與方法
- 中文版AutoCAD 2013高手速成
- ZigBee無線通信技術應用開發
- 機器學習案例分析(基于Python語言)
- 樂高創意機器人教程(中級 上冊 10~16歲) (青少年iCAN+創新創意實踐指導叢書)
- Advanced Deep Learning with Keras