官术网_书友最值得收藏!

Chapter 4. Modularizing Manifests with Classes and Defined Types

At this point, you have already performed some production-grade tasks with Puppet. You learned how to write standalone manifests and then invoke puppet apply to put them to use. While setting up your first Puppet master and agent, you created a simple example for a node manifest on the master. In a node '<hostname>' block, you created the equivalent of a manifest file. This way, the Puppet master used just this manifest for the specified agent node.

While this is all useful, and of essential importance, it will obviously not suffice for daily business. By working with node blocks that contain sets of resources, you will end up performing lots of copy and paste operations for similar nodes, and the whole construct will become unwieldy very quickly.

This is an unnatural approach to developing Puppet manifests. Despite the great differences to many other languages that you might be familiar with, the Puppet DSL is a programming language. Building manifests merely from node blocks and resources would be like writing C with no functions except main, or Ruby without any classes of your own.

The manifests that you can write with the means that are already at your disposal are not flat—you learned about common control structures such as if and case. Your manifests can use these to adapt to various circumstances on the agent, by querying the values of Facter facts and branching in accordance with the results.

However, these constructs should be complemented by the language tools to create reusable units of manifest code, similar to functions or methods in procedural languages. This chapter introduces these concepts through the following topics:

  • Introducing classes and defined types
  • Structured design patterns
  • Including classes from defined types
  • Nesting definitions in classes
  • Establishing relationships among containers
  • Making classes more flexible through parameters
主站蜘蛛池模板: 海安县| 洪湖市| 平果县| 抚州市| 都江堰市| 银川市| 米脂县| 浪卡子县| 陇西县| 潢川县| 舟山市| 太谷县| 弥渡县| 红安县| 东辽县| 台东县| 北碚区| 沁阳市| 永吉县| 株洲县| 霍山县| 渭南市| 宁武县| 怀集县| 彭泽县| 文山县| 二连浩特市| 阿合奇县| 凤阳县| 芜湖县| 阳春市| 富民县| 巩留县| 鄂托克前旗| 邵阳县| 马山县| 眉山市| 白银市| 新疆| 长葛市| 临朐县|