You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use VoxPupuli's puppet-chrony as the reference module
bgtm and the style guide used puppetlabs-ntp as their running "real-world
best practices" example. ntp is a puppetlabs module, and its
parameter-defaults approach (every default in common.yaml, none inline)
contradicts the guidance these same docs give. VoxPupuli's puppet-chrony
is a community-maintained module with the identical
init.pp/install/config/service + contain structure that keeps static
defaults inline and overrides only OS-specific values in per-OS Hiera
data.
- bgtm.md: convert the full walkthrough (intro, main class signature,
install/config/service classes, the naming example, and the
containment block) to chrony, with every snippet based on real module
source. The main class signature now shows inline defaults, the naming
example uses chrony::service's service_manage toggle to illustrate the
thing_manage convention, and a note explains the assert_private() calls
that mark the subordinate classes private.
- style_guide.markdown: convert the ntp references where ntp stood in as
the reference module (the comment example, the validation-example
link, and the parameter-documentation example). The "Bad"
parameter-ordering example is left as ntp so chrony is not cast as the
bad example.
Closes#395
Signed-off-by: Michael Harp <mike@mikeharp.com>
Copy file name to clipboardExpand all lines: docs/_openvox_8x/bgtm.md
+67-80Lines changed: 67 additions & 80 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ This section covers:
42
42
*[How best to order your classes (rather than resources)](#ordering).
43
43
*[How to leverage and utilize dependencies](#dependencies).
44
44
45
-
To demonstrate a real-world best practices standard module, we will walk through the structure of the [puppetlabs-ntp](https://forge.puppet.com/puppetlabs/ntp) module.
45
+
To demonstrate a real-world best practices standard module, we will walk through the structure of VoxPupuli's [puppet-chrony](https://github.com/voxpupuli/puppet-chrony) module.
46
46
47
47
### Class design
48
48
@@ -59,81 +59,68 @@ In terms of class structure we recommend the following (more detail below):
59
59
The main class of any module must share the name of the module and be located in the `init.pp` file. The name and location of the main module class is extremely important, as it guides the [autoloader](./lang_namespaces.html#autoloader-behavior) behavior.
60
60
The main class of a module is its interface point and ought to be the only parameterized class if possible. Limiting the parameterized classes to just the main class allows you to control usage of the entire module with the inclusion of a single class. This class should provide sensible defaults so that a user can get going with `include module`.
61
61
62
-
For instance, the main `ntp` class in the `ntp` module looks like this:
62
+
For instance, the main `chrony` class in the `chrony` module looks like this:
Note that each static default is declared inline, right on the parameter, so the value is visible in the class signature and in generated reference documentation.
80
+
81
81
#### `module::install`
82
82
83
83
The install class must be located in the `install.pp` file. It should contain all of the resources related to getting the software that the module manages onto the node.
84
84
85
-
The install class must be named `module::install`, as in the `ntp` module:
85
+
The install class must be named `module::install`, as in the `chrony` module:
86
86
87
87
```puppet
88
-
class ntp::install {
89
-
90
-
if $ntp::package_manage {
91
-
package { $ntp::package_name:
92
-
ensure => $ntp::package_ensure,
93
-
}
94
-
88
+
class chrony::install {
89
+
assert_private()
90
+
91
+
package { 'chrony':
92
+
ensure => $chrony::package_ensure,
93
+
name => $chrony::package_name,
94
+
source => $chrony::package_source,
95
+
provider => $chrony::package_provider,
95
96
}
96
-
97
97
}
98
98
```
99
99
100
+
The `install`, `config`, and `service` classes are private: they are declared only by the main `chrony` class, never directly by users. Each one calls `assert_private()`, which fails compilation with a clear message if the class is declared from outside its own module. See [public and private classes](./style_guide.html#public-and-private) for more on this distinction.
101
+
100
102
#### `module::config`
101
103
102
104
The resources related to configuring the installed software should be placed in a config class. The config class must be named `module::config` and must be located in the `config.pp` file.
103
105
104
-
For example, see the `module::config` class in the `ntp` module:
106
+
For example, see the `module::config` class in the `chrony` module:
105
107
106
108
```puppet
107
-
class ntp::config {
108
-
109
-
#The servers-netconfig file overrides NTP config on SLES 12, interfering with our configuration.
110
-
if $facts['operatingsystem'] == 'SLES' and $facts['operatingsystemmajrelease'] == '12' {
@@ -145,23 +132,22 @@ The remaining service resources, and anything else related to the running state
145
132
For example:
146
133
147
134
```puppet
148
-
class ntp::service {
135
+
class chrony::service {
136
+
assert_private()
149
137
150
-
if ! ($ntp::service_ensure in [ 'running', 'stopped' ]) {
151
-
fail('service_ensure parameter must be running or stopped')
138
+
if $chrony::service_manage {
139
+
service { $chrony::service_name:
140
+
ensure => $chrony::service_ensure,
141
+
enable => $chrony::service_enable,
142
+
}
152
143
}
153
144
154
-
if $ntp::service_manage == true {
155
-
service { 'ntp':
156
-
ensure => $ntp::service_ensure,
157
-
enable => $ntp::service_enable,
158
-
name => $ntp::service_name,
159
-
provider => $ntp::service_provider,
160
-
hasstatus => true,
161
-
hasrestart => true,
145
+
if $chrony::wait_manage {
146
+
service { $chrony::wait_name:
147
+
ensure => $chrony::wait_ensure,
148
+
enable => $chrony::wait_enable,
162
149
}
163
150
}
164
-
165
151
}
166
152
```
167
153
@@ -177,22 +163,22 @@ Naming consistency is imperative for community comprehension and assists in trou
177
163
178
164
Best practices recommend the pattern of `thing_property` for naming parameters.
179
165
180
-
For example, in the `ntp` module
166
+
For example, in the `chrony` module the service resource uses `service_name`, `service_ensure`, and `service_enable`:
181
167
182
168
```puppet
183
-
class ntp::install {
169
+
class chrony::service {
184
170
185
-
if $ntp::package_manage {
186
-
package { $ntp::package_name:
187
-
ensure => $ntp::package_ensure,
171
+
if $chrony::service_manage {
172
+
service { $chrony::service_name:
173
+
ensure => $chrony::service_ensure,
174
+
enable => $chrony::service_enable,
188
175
}
189
-
190
176
}
191
177
192
178
}
193
179
```
194
180
195
-
If you have a parameter that toggles an entire function on and off, the naming convention can be amended to `thing_manage`. This applies, in particular, to Boolean toggles, such as when the module manages the installation altogether. The `thing_manage` convention allows you to wrap all of the resources in an `if $package_manage {}` test, as shown in the `ntp` example above.
181
+
If you have a parameter that toggles an entire function on and off, the naming convention can be amended to `thing_manage`. This applies, in particular, to Boolean toggles, such as when the module manages the service altogether. The `thing_manage` convention allows you to wrap all of the resources in an `if $service_manage {}` test, as shown in the `chrony` example above.
196
182
197
183
Consistent naming across modules helps with the readability and usability of your code.
198
184
@@ -228,15 +214,16 @@ To allow other modules to form ordering relationships with your module, ensure t
228
214
229
215
Classes do not _automatically_ contain the classes they declare. This is because classes can be declared in several places via `include` and similar functions. To contain classes, use [the `contain` function](./function.html#contain). For more information and context about containment, see [the containment docs](./lang_containment.html).
230
216
231
-
For example, the `ntp` module uses containment in the main `ntp` class:
217
+
For example, the `chrony` module uses containment in the main `chrony` class:
Copy file name to clipboardExpand all lines: docs/_openvox_8x/style_guide.markdown
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,15 +191,15 @@ Do not use `/* */` comments in Puppet code.
191
191
**Good:**
192
192
193
193
```puppet
194
-
# Configures NTP
195
-
file { '/etc/ntp.conf': ... }
194
+
# Configures chrony
195
+
file { '/etc/chrony.conf': ... }
196
196
```
197
197
198
198
**Bad:**
199
199
200
200
```puppet
201
-
/* Creates file /etc/ntp.conf */
202
-
file { '/etc/ntp.conf': ... }
201
+
/* Creates file /etc/chrony.conf */
202
+
file { '/etc/chrony.conf': ... }
203
203
```
204
204
205
205
#### Documentation comments
@@ -712,7 +712,7 @@ Documentation [comments](#documentation-comments) for OpenVox Strings should be
712
712
1. Following lines, if applicable: Define parameters. Parameters should be [typed](./lang_data_type.html).
713
713
1. Next lines: Includes and validation come after parameters are defined. Includes may come before or after validation, but should be grouped separately, with all includes and requires in one group and all validations in another.
714
714
* Validations should validate any parameters and fail catalog compilation if any
715
-
parameters are invalid. See [ntp](https://github.com/puppetlabs/puppetlabs-ntp/blob/master/manifests/init.pp#L212:L274) for an example.
715
+
parameters are invalid. See [chrony](https://github.com/voxpupuli/puppet-chrony/blob/master/manifests/init.pp#L371-L373) for an example.
716
716
1. Next lines, if applicable: Should declare local variables and perform variable munging.
717
717
1. Next lines: Should declare resource defaults.
718
718
1. Next lines: Should override resources if necessary.
@@ -1262,20 +1262,20 @@ For example:
1262
1262
```puppet
1263
1263
# @param config_epp Specifies a file to act as a EPP template for the config file.
1264
1264
# Valid options: a path (absolute, or relative to the module path). Example value:
1265
-
# 'ntp/ntp.conf.epp'. A validation error is thrown if you supply both this param **and**
1265
+
# 'chrony/chrony.conf.epp'. A validation error is thrown if you supply both this param **and**
1266
1266
# the `config_template` param.
1267
1267
```
1268
1268
1269
1269
If you use Strings to document your module, include information about Strings in the Reference section of your README so that your users will know how to generate the documentation. See [OpenVox Strings](https://github.com/OpenVoxProject/openvox-strings) documentation for details on usage, installation, and correctly writing documentation comments.
1270
1270
1271
-
If you do not include Strings code comments, you should include a Reference section in your README with a complete list of all classes, types, providers, defined types, and parameters that the user can configure. Include a brief description, the valid options, and the default values (if any). For example, this is a parameter for the `ntp` module's `ntp` class:
1271
+
If you do not include Strings code comments, you should include a Reference section in your README with a complete list of all classes, types, providers, defined types, and parameters that the user can configure. Include a brief description, the valid options, and the default values (if any). For example, this is a parameter for the `chrony` module's `chrony` class:
1272
1272
1273
1273
```markdown
1274
1274
#### `package_ensure`
1275
1275
1276
1276
Data type: String.
1277
1277
1278
-
Whether to install the NTP package, and what version to install. Values: 'present', 'latest', or a specific version number.
1278
+
Whether to install the chrony package, and what version to install. Values: 'present', 'latest', or a specific version number.
0 commit comments