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

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.

主站蜘蛛池模板: 文成县| 五寨县| 武强县| 五寨县| 蓬安县| 安仁县| 尤溪县| 固镇县| 古交市| 汨罗市| 额济纳旗| 屏边| 确山县| 鲜城| 德兴市| 榆中县| 若羌县| 井陉县| 临颍县| 咸宁市| 蓝田县| 乌拉特后旗| 舟曲县| 通榆县| 阿拉善左旗| 桦川县| 勃利县| 鸡西市| 尼勒克县| 陕西省| 桐柏县| 阿合奇县| 门源| 东港市| 元氏县| 江华| 鄯善县| 西安市| 荥阳市| 瑞金市| 桃园市|