Skip to content

Commit a4c1ee7

Browse files
committed
Use tp::fail instaead of deprecation to avoid fails on puppet8. Update docs and ancillary defines
1 parent c19540f commit a4c1ee7

File tree

18 files changed

+165
-126
lines changed

18 files changed

+165
-126
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ Here follows an example of tp resources used inside a custom profile where the c
155155

156156
# Configuration of sshd_config server configuration file (main config file)
157157
tp::conf { 'openssh':
158-
template => $server_template,
159-
options_hash => $options,
158+
template => $server_template,
159+
my_options => $options,
160160
}
161161

162162
# Configuration of ssh_config client configuration file
163163
tp::conf { 'openssh::ssh_config':
164-
template => $client_template,
165-
options_hash => $options,
164+
template => $client_template,
165+
my_options => $options,
166166
}
167167
}
168168

@@ -191,11 +191,11 @@ Install an application with default settings (package installed, service started
191191

192192
tp::install { 'redis': }
193193

194-
Configure the application main configuration file a custom erb template which uses data from a custom $options_hash:
194+
Configure the application main configuration file a custom erb template which uses data from a custom $my_options:
195195

196196
tp::conf { 'rsyslog':
197-
template => 'site/rsyslog/rsyslog.conf.erb',
198-
options_hash => lookup('rsyslog::options_hash'),
197+
template => 'site/rsyslog/rsyslog.conf.erb',
198+
my_options => lookup('rsyslog::my_options'),
199199
}
200200

201201
Populate any custom directory from a Git repository (it requires Puppet Labs' vcsrepo module):
@@ -225,7 +225,7 @@ Other parameters are available to manage integrations:
225225
- **puppi_enable** Default: false. Installs [Puppi](https://github.com/example42/puppi) and enables puppi integration.
226226
- **test_enable** Default: false. If to enable automatic testing of the managed application.
227227
- **test_template** Default: undef. If provided, the provided erb template is used to test the application (instead of default tests).
228-
- **options_hash** Default: {}. An optional hash where to set variable to use in test_template.
228+
- **my_options** Default: {}. An optional hash where to set variable to use in test_template.
229229

230230
Some specific params are to handle repos:
231231

@@ -239,7 +239,7 @@ These parameters allow to skip management of packages or services:
239239

240240
Some parameters allow to configure tp::conf and tp::dir resources directly from tp::install (inheriting the same settings and options):
241241

242-
- **conf_hash**. Default: { }. A hash of tp::conf resources to create. These resources will refer to the same application specified in the tp::install $title and inherits the settings ensure, settings_hash, options_hash and data_module
242+
- **conf_hash**. Default: { }. A hash of tp::conf resources to create. These resources will refer to the same application specified in the tp::install $title and inherits the settings ensure, settings_hash, my_options and data_module
243243
- **dir_hash**. Default: { }. A hash of tp::dir resources to create, as for the conf one.
244244

245245
Parameters are also available to customise the tiny data settings which affect package and service names, repos settings, file paths and so on. The params are common to all the tp defines, check [Updating tiny data and using alternative data sources](#Updating-tiny-data-and-using-alternative-data-sources) section for details.
@@ -253,7 +253,7 @@ An example with a custom test for the rabbitmq service:
253253
cli_enable => true,
254254
test_enable => true,
255255
test_template => 'profile/rabbitmb/tp_test.erb',
256-
options_hash => { 'server' => "rabbitmq.${::domain}" }
256+
my_options => { 'server' => "rabbitmq.${::domain}" }
257257
}
258258

259259
It's possible to specify the version of the package to install (the provided version must be available in the configured repos):
@@ -294,16 +294,16 @@ It's possible to manage files with different methods, for example directly provi
294294
or providing a custom template with custom options:
295295

296296
tp::conf { 'openssh::ssh_config':
297-
template => 'profile/openssh/ssh_config.erb',
298-
options_hash => {
297+
template => 'profile/openssh/ssh_config.erb',
298+
my_options => {
299299
UsePAM => 'yes',
300300
X11Forwarding => 'no',
301301
}
302302
}
303303

304304
Via the template parameter with can both specify files .erb suffix (used as `content => template($template)`) or with .epp suffix (used as `content => epp($template)`). If not .erb or .epp suffix is present in the template value, then it's treates as and erb (`content => template($template)`).
305305

306-
In the profile/templates/openssh/ssh_config.erb template you will have the contents you want and use the above options with something like (note you can use both the @options and the @options_hash variable):
306+
In the profile/templates/openssh/ssh_config.erb template you will have the contents you want and use the above options with something like (note you can use both the @options and the @my_options variable):
307307

308308
[...]
309309
UsePAM <%= @options['UsePAM'] %>
@@ -323,10 +323,10 @@ also it's possible to provide the source to use, instead of managing it with the
323323
'puppet:///modules/site/redis/redis.conf' ] ,
324324
}
325325

326-
For applications for which it exists the setting 'config_file_format' you can just pass the hash of options_hash of settings to configure and tp::conf creates a valid configuration file for the application:
326+
For applications for which it exists the setting 'config_file_format' you can just pass the hash of my_options of settings to configure and tp::conf creates a valid configuration file for the application:
327327

328328
tp::conf { 'filebeat':
329-
options_hash => {
329+
my_options => {
330330
filebeat.modules => ['module: system']
331331
syslog => {
332332
enabled => true,
@@ -339,7 +339,7 @@ This example makes much more sense if based on Hiera data (see [Configuring tp r
339339

340340
tp::conf_hash:
341341
filebeat:
342-
options_hash:
342+
my_options:
343343
filebeat.modules:
344344
- module: system
345345
syslog:
@@ -530,15 +530,15 @@ Or you can use a specific `tp::test` define:
530530

531531
tp::test { 'rabbitmq':
532532
template => 'profile/rabbimq/tptest.erb',
533-
options_hash => {
533+
my_options => {
534534
port => '11111',
535535
host => 'localhost',
536536
},
537537
}
538538

539-
All the keys set via the $options_hash parameter can be used in the erb template with sopmething like:
539+
All the keys set via the $my_options parameter can be used in the erb template with sopmething like:
540540

541-
port_to_check=<%= @options_hash['port'] >
541+
port_to_check=<%= @my_options['port'] >
542542

543543
The `tp::test` define has the following parameters to manage the content of the test script (placed under `/etc/tp/test/$title`):
544544

data/common.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ tp::check_package_command: 'puppet resource package'
99
tp::check_repo_path: 'echo "Check repo not supported on this OS"'
1010
tp::check_repo_path_post: ''
1111
tp::info_package_command': 'puppet resource package'
12-
tp::options_hash: {}
1312
tp::install_hash: {}
1413
tp::install_hash_merge_behaviour: 'first'
1514
tp::install_defaults: {}

docs/conf.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ Given the above example, we can edit the referenced file with:
1111
[root@centos7-p4 ~]# mkdir -p /vagrant/modules_local/site/templates/nginx
1212
[root@centos7-p4 ~]# vi /vagrant/modules_local/site/templates/nginx/nginx.conf.erb
1313

14-
You can pass an hash of custom key/values using the ```options_hash``` parameter:
14+
You can pass an hash of custom key/values using the ```my_options``` parameter:
1515

1616
$nginx_options = {
1717
'worker_processes' => '12',
1818
'worker_connections' => '512',
1919
}
2020
tp::conf { 'nginx':
21-
template => 'site/nginx/nginx.conf.erb',
22-
options_hash => $nginx_options,
21+
template => 'site/nginx/nginx.conf.erb',
22+
my_options => $nginx_options,
2323
}
2424

2525
An then, in your ```$modulepath/site/templates/ningx/nginx.conf.erb``` have something like:
@@ -35,7 +35,7 @@ An then, in your ```$modulepath/site/templates/ningx/nginx.conf.erb``` have some
3535
multi_accept on;
3636
}
3737

38-
Some explanations are needed here. Your ```options_hash``` parameter is accessed, in the erb file, via the ```@options``` variable (You can use also ```@options_hash```) because in ```tp::conf``` we plan to merge the values from @options_hash to a set of default options (compliant with the underlying OS).
38+
Some explanations are needed here. Your ```my_options``` parameter is accessed, in the erb file, via the ```@options``` variable (You can use also ```@my_options```) because in ```tp::conf``` we plan to merge the values from @my_options to a set of default options (compliant with the underlying OS).
3939
You have at disposal also the ```@settings``` hash which contains OS specific data for the managed application. To have an idea of what kind of data we provide for each supported application check in [```data/nginx/default.yaml```](https://github.com/example42/puppet-tp/blob/master/data/nginx/default.yaml).
4040

4141
There are many options in ```tp::conf``` that let you manage every aspect of your configurations, for example we can manage its permissions, how to populate its content (with static source, epp or erb templates, plain content...), if to trigger a service restart when the files changes (by default the relevant service, if present, is restarted) and so on.

docs/hiera.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ On hiera yaml files then you can have somethig as follows (not actually recommen
3232
template: "site/apache/mime.types.erb"
3333
mysql:
3434
template: "site/mysql/my.cnf.erb"
35-
options_hash:
36-
35+
my_options:
36+
'innodb_buffer_pool_size': 512M
37+
'innodb_log_file_size': 128M
38+
'innodb_flush_log_at_trx_commit': 2
3739

3840
tp::dir_hash:
3941
apache::certs:

manifests/conf.pp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
# app that can be used in the provided erb or epp templates respectively as
182182
# @options_hash['key'] or $options_hash['key'],
183183
#
184-
# @param settings_hash An hash that can override the application settings tp
184+
# @param my_settings An hash that can override the application settings tp
185185
# returns, according to the underlying Operating System and the default
186186
# behaviour.
187187
#
@@ -256,10 +256,10 @@
256256
) {
257257
# Deprecations
258258
if $settings_hash != {} {
259-
deprecation('settings_hash', 'Replace with my_settings')
259+
tp::fail($on_missing_data, "Module ${caller_module_name} needs updates: Parameter settings_hash in tp::conf is deprecated, replace it with my_settings")
260260
}
261261
if $options_hash != {} {
262-
deprecation('options_hash', 'Replace with my_options')
262+
tp::fail($on_missing_data, "Module ${caller_module_name} needs updates: Parameter options_hash in tp::conf is deprecated, replace it with my_options")
263263
}
264264

265265
if $use_v4 {

manifests/debug.pp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
Variant[Undef,String] $epp = undef,
1313
Variant[Undef,String] $content = undef,
1414

15+
Hash $my_options = {},
1516
Hash $options_hash = {},
17+
18+
Hash $my_settings = {},
1619
Hash $settings_hash = {},
1720

1821
String[1] $data_module = 'tinydata',
@@ -24,9 +27,17 @@
2427
Boolean $cli_enable = pick($tp::cli_enable, true),
2528

2629
) {
30+
# Deprecations
31+
if $settings_hash != {} {
32+
tp::fail('notify', "Module ${caller_module_name} needs updates: Parameter settings_hash in tp::debug is deprecated, replace it with my_settings")
33+
}
34+
if $options_hash != {} {
35+
tp::fail('notify', "Module ${caller_module_name} needs updates: Parameter options_hash in tp::debug is deprecated, replace it with my_options")
36+
}
37+
2738
# Settings evaluation
2839
$tp_settings=tp_lookup($title,'settings',$data_module,'deep_merge')
29-
$settings = $tp_settings + $settings_hash
40+
$settings = deep_merge($tp_settings,$settings_hash,$my_settings)
3041

3142
include tp
3243

@@ -35,7 +46,7 @@
3546
debug_command => $debug_command,
3647
}
3748

38-
$options = merge($options_defaults, $options_hash)
49+
$options = deep_merge($options_defaults, $options_hash $my_options)
3950

4051
$array_package_name=any2array($settings['package_name'])
4152
$array_service_name=any2array($settings['service_name'])

manifests/dir.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
) {
176176
# Deprecations
177177
if $settings_hash != {} {
178-
deprecation('settings_hash', 'Replace with my_settings')
178+
tp::fail($on_missing_data, "Module ${caller_module_name} needs updates: Parameter settings_hash in tp::dir is deprecated, replace it with my_settings")
179179
}
180180

181181
if $use_v4 {
@@ -344,7 +344,7 @@
344344
$title_path = undef
345345
}
346346

347-
$settings = $tp_settings + $settings_hash
347+
$settings = deep_merge($tp_settings,$settings_hash,$my_settings)
348348
$prefix = $scope ? {
349349
'global' => '',
350350
'user' => 'user_',

manifests/info.pp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
Variant[Undef,String] $epp = undef,
1313
Variant[Undef,String] $content = undef,
1414

15+
Hash $my_options = {},
1516
Hash $options_hash = {},
17+
18+
Hash $my_settings = {}
1619
Hash $settings_hash = {},
1720

1821
String[1] $data_module = 'tinydata',
@@ -24,9 +27,17 @@
2427
Boolean $cli_enable = pick($tp::cli_enable, true),
2528

2629
) {
30+
# Deprecations
31+
if $settings_hash != {} {
32+
tp::fail('notify', 'Parameter settings_hash in tp::info is deprecated, replace it with my_settings')
33+
}
34+
if $options_hash != {} {
35+
tp::fail('notify', 'Parameter options_hash in tp::info is deprecated, replace it with my_options')
36+
}
37+
2738
# Settings evaluation
2839
$tp_settings=tp_lookup($title,'settings',$data_module,'deep_merge')
29-
$settings = $tp_settings + $settings_hash
40+
$settings = deep_merge($tp_settings,$settings_hash,$my_settings)
3041

3142
include tp
3243

@@ -35,7 +46,7 @@
3546
info_command => $info_command,
3647
}
3748

38-
$options = merge($options_defaults, $options_hash)
49+
$options = deep_merge($options_defaults, $options_hash, $my_options)
3950

4051
$array_package_name=any2array($settings['package_name'])
4152
$array_service_name=any2array($settings['service_name'])

manifests/init.pp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,25 @@
105105
}
106106

107107
if $conf_hash != {} {
108-
deprecation('conf_hash', 'Replace with confs')
108+
tp::fail('notify', 'Parameter conf_hash in class tp is deprecated, replace it with confs')
109109
}
110110
if $dir_hash != {} {
111-
deprecation('dir_hash', 'Replace with dirs')
111+
tp::fail('notify', 'Parameter dir_hash in class tp is deprecated, replace it with dirs')
112112
}
113113
if $install_hash != {} {
114-
deprecation('install_hash', 'Replace with installs')
114+
tp::fail('notify', 'Parameter install_hash in class tp is deprecated, replace it with installs')
115115
}
116116
if $concat_hash != {} {
117-
deprecation('concat_hash', 'No more supported')
117+
tp::fail('notify', 'Parameter concat_hash in class tp is no more supported')
118118
}
119119
if $stdmod_hash != {} {
120-
deprecation('stdmod__hash', 'No more supported')
120+
tp::fail('notify', 'Parameter stdmod_hash in class tp is no more supported')
121121
}
122122
if $puppi_hash != {} {
123-
deprecation('puppi_hash', 'No more supported')
123+
tp::fail('notify', 'Parameter puppi_hash in class tp is no more supported')
124124
}
125125
if $repo_hash != {} {
126-
deprecation('repo_hash', 'Replace with repos')
127-
}
128-
if $options_hash != {} {
129-
deprecation('options_hash', 'Replace with options')
126+
tp::fail('notify', 'Parameter repo_hash in class tp is no more supported')
130127
}
131128

132129
if 'identity' in $facts {

0 commit comments

Comments
 (0)