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 ... }
- 程序員數學:用Python學透線性代數和微積分
- 編寫整潔的Python代碼(第2版)
- Object-Oriented JavaScript(Second Edition)
- C語言程序設計立體化案例教程
- C語言程序設計教程
- Hands-On GUI Programming with C++ and Qt5
- Visual C++程序設計與項目實踐
- Java高并發編程詳解:深入理解并發核心庫
- Using Yocto Project with BeagleBone Black
- 編程的原則:改善代碼質量的101個方法
- 計算機應用基礎(Windows 7+Office 2010)
- 川哥教你Spring Boot 2實戰
- Apache Kafka 1.0 Cookbook
- Learning GraphQL and Relay
- TensorFlow.NET實戰