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

Including classes from defined types

The example_app_config type that was defined in the previous example is supposed to serve a very specific purpose. Therefore, it assumes that the base directory, /etc/example_app, and its subdirectories were managed independently, outside the defined type. This was a sound design, but many defined types are meant to be used from lots of independent classes or other defined types. Such defines need to be self-contained.

In our example, the defined type needs to make sure that the following resources are part of the manifest:

file { [ '/etc/example_app', '/etc/example_app/config.d.enabled' ]:
  ensure => 'directory',
} 

Just putting this declaration into the body of the define will lead to duplicate resource errors. Each instance of example_app_config will try to declare the directories by itself. However, we already discussed a pattern to avoid just that issue—we called it the component class.

To make sure that any instance of the example_app_config type is self-contained and works on its own, wrap the preceding declaration in a class (for example, class example_app_config_directories) and make sure to include this class right in the body of the define:

define example_app_config(Array $regions = []) {
  include example_app_config_directories
...
}

Tip

You can refer to the examples that come with your copy of this book for the definition of the class.

主站蜘蛛池模板: 凤山市| 大兴区| 莲花县| 克什克腾旗| 资兴市| 长丰县| 电白县| 仁化县| 金平| 肥西县| 宜都市| 武安市| 东源县| 民勤县| 海林市| 梁河县| 麟游县| 巴林右旗| 耿马| 红桥区| 田阳县| 高阳县| 呼和浩特市| 祥云县| 沾益县| 天柱县| 朝阳市| 苍山县| 平远县| 巴马| 东方市| 铁岭市| 衡水市| 长宁区| 镇宁| 府谷县| 玉树县| 包头市| 台中县| 辽阳市| 武义县|