Skip to content

Fix #116 #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 3.10.3
- Fix warnings

## 3.10.2

- Fixed options param in tp::conf where use_v4 is false
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ Here follows an example of tp resources used inside a custom profile where the c

# Configuration of sshd_config server configuration file (main config file)
tp::conf { 'openssh':
template => $server_template,
options_hash => $options,
template => $server_template,
my_options => $options,
}

# Configuration of ssh_config client configuration file
tp::conf { 'openssh::ssh_config':
template => $client_template,
options_hash => $options,
template => $client_template,
my_options => $options,
}
}

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

tp::install { 'redis': }

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

tp::conf { 'rsyslog':
template => 'site/rsyslog/rsyslog.conf.erb',
options_hash => lookup('rsyslog::options_hash'),
template => 'site/rsyslog/rsyslog.conf.erb',
my_options => lookup('rsyslog::my_options'),
}

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

Some specific params are to handle repos:

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

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

- **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
- **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
- **dir_hash**. Default: { }. A hash of tp::dir resources to create, as for the conf one.

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.
Expand All @@ -253,7 +253,7 @@ An example with a custom test for the rabbitmq service:
cli_enable => true,
test_enable => true,
test_template => 'profile/rabbitmb/tp_test.erb',
options_hash => { 'server' => "rabbitmq.${::domain}" }
my_options => { 'server' => "rabbitmq.${::domain}" }
}

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

tp::conf { 'openssh::ssh_config':
template => 'profile/openssh/ssh_config.erb',
options_hash => {
template => 'profile/openssh/ssh_config.erb',
my_options => {
UsePAM => 'yes',
X11Forwarding => 'no',
}
}

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)`).

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):
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):

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

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:
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:

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

tp::conf_hash:
filebeat:
options_hash:
my_options:
filebeat.modules:
- module: system
syslog:
Expand Down Expand Up @@ -530,15 +530,15 @@ Or you can use a specific `tp::test` define:

tp::test { 'rabbitmq':
template => 'profile/rabbimq/tptest.erb',
options_hash => {
my_options => {
port => '11111',
host => 'localhost',
},
}

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

port_to_check=<%= @options_hash['port'] >
port_to_check=<%= @my_options['port'] >

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

Expand Down
1 change: 0 additions & 1 deletion data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ tp::check_package_command: 'puppet resource package'
tp::check_repo_path: 'echo "Check repo not supported on this OS"'
tp::check_repo_path_post: ''
tp::info_package_command': 'puppet resource package'
tp::options_hash: {}
tp::install_hash: {}
tp::install_hash_merge_behaviour: 'first'
tp::install_defaults: {}
Expand Down
8 changes: 4 additions & 4 deletions docs/conf.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Given the above example, we can edit the referenced file with:
[root@centos7-p4 ~]# mkdir -p /vagrant/modules_local/site/templates/nginx
[root@centos7-p4 ~]# vi /vagrant/modules_local/site/templates/nginx/nginx.conf.erb

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

$nginx_options = {
'worker_processes' => '12',
'worker_connections' => '512',
}
tp::conf { 'nginx':
template => 'site/nginx/nginx.conf.erb',
options_hash => $nginx_options,
template => 'site/nginx/nginx.conf.erb',
my_options => $nginx_options,
}

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

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).
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).
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).

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.
Expand Down
6 changes: 4 additions & 2 deletions docs/hiera.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ On hiera yaml files then you can have somethig as follows (not actually recommen
template: "site/apache/mime.types.erb"
mysql:
template: "site/mysql/my.cnf.erb"
options_hash:

my_options:
'innodb_buffer_pool_size': 512M
'innodb_log_file_size': 128M
'innodb_flush_log_at_trx_commit': 2

tp::dir_hash:
apache::certs:
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/tp_lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Puppet::Parser::Functions
hiera_file_path = mp.path + '/data/' + app + '/hiera.yaml'

unless File.exist?(hiera_file_path)
function_warning(["No tinydata found for: #{app} in #{hiera_file_path}. Trying to install package #{app}"])
function_notice(["No tinydata found for: #{app} in #{hiera_file_path}. Trying to install package #{app}"])
default_fallback = true
hiera_file_path = mp.path + '/data/default/hiera.yaml'
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/tp_lookup4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Puppet::Parser::Functions
hiera_file_path = mp.path + '/data/' + app + '/hiera.yaml'

unless File.exist?(hiera_file_path)
function_warning(["No tinydata found for: #{app} in #{hiera_file_path}. Trying to install package #{app}"])
function_notice(["No tinydata found for: #{app} in #{hiera_file_path}. Trying to install package #{app}"])
default_fallback = true
hiera_file_path = mp.path + '/data/default/hiera.yaml'
end
Expand Down
8 changes: 4 additions & 4 deletions manifests/conf.pp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
# app that can be used in the provided erb or epp templates respectively as
# @options_hash['key'] or $options_hash['key'],
#
# @param settings_hash An hash that can override the application settings tp
# @param my_settings An hash that can override the application settings tp
# returns, according to the underlying Operating System and the default
# behaviour.
#
Expand Down Expand Up @@ -256,10 +256,10 @@
) {
# Deprecations
if $settings_hash != {} {
deprecation('settings_hash', 'Replace with my_settings')
tp::fail($on_missing_data, "Module ${caller_module_name} needs updates: Parameter settings_hash in tp::conf is deprecated, replace it with my_settings")
}
if $options_hash != {} {
deprecation('options_hash', 'Replace with my_options')
tp::fail($on_missing_data, "Module ${caller_module_name} needs updates: Parameter options_hash in tp::conf is deprecated, replace it with my_options")
}

if $use_v4 {
Expand Down Expand Up @@ -442,7 +442,7 @@
$upstream_repo = getparam(Tp::Install[$app],'upstream_repo')
}
$tp_settings = tp_lookup($app,'settings',$data_module,'merge')
$settings = $tp_settings + $settings_hash
$settings = deep_merge($tp_settings,$settings_hash,$my_settings)

$tp_options = tp_lookup($app,"options::${base_file}",$data_module,'merge')
$options = deep_merge($tp_options,$options_hash,$my_options,)
Expand Down
15 changes: 13 additions & 2 deletions manifests/debug.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
Variant[Undef,String] $epp = undef,
Variant[Undef,String] $content = undef,

Hash $my_options = {},
Hash $options_hash = {},

Hash $my_settings = {},
Hash $settings_hash = {},

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

) {
# Deprecations
if $settings_hash != {} {
tp::fail('notify', "Module ${caller_module_name} needs updates: Parameter settings_hash in tp::debug is deprecated, replace it with my_settings")
}
if $options_hash != {} {
tp::fail('notify', "Module ${caller_module_name} needs updates: Parameter options_hash in tp::debug is deprecated, replace it with my_options")
}

# Settings evaluation
$tp_settings=tp_lookup($title,'settings',$data_module,'deep_merge')
$settings = $tp_settings + $settings_hash
$settings = deep_merge($tp_settings,$settings_hash,$my_settings)

include tp

Expand All @@ -35,7 +46,7 @@
debug_command => $debug_command,
}

$options = merge($options_defaults, $options_hash)
$options = deep_merge($options_defaults, $options_hash, $my_options)

$array_package_name=any2array($settings['package_name'])
$array_service_name=any2array($settings['service_name'])
Expand Down
4 changes: 2 additions & 2 deletions manifests/dir.pp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
) {
# Deprecations
if $settings_hash != {} {
deprecation('settings_hash', 'Replace with my_settings')
tp::fail($on_missing_data, "Module ${caller_module_name} needs updates: Parameter settings_hash in tp::dir is deprecated, replace it with my_settings")
}

if $use_v4 {
Expand Down Expand Up @@ -344,7 +344,7 @@
$title_path = undef
}

$settings = $tp_settings + $settings_hash
$settings = deep_merge($tp_settings,$settings_hash,$my_settings)
$prefix = $scope ? {
'global' => '',
'user' => 'user_',
Expand Down
15 changes: 13 additions & 2 deletions manifests/info.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
Variant[Undef,String] $epp = undef,
Variant[Undef,String] $content = undef,

Hash $my_options = {},
Hash $options_hash = {},

Hash $my_settings = {},
Hash $settings_hash = {},

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

) {
# Deprecations
if $settings_hash != {} {
tp::fail('notify', 'Parameter settings_hash in tp::info is deprecated, replace it with my_settings')
}
if $options_hash != {} {
tp::fail('notify', 'Parameter options_hash in tp::info is deprecated, replace it with my_options')
}

# Settings evaluation
$tp_settings=tp_lookup($title,'settings',$data_module,'deep_merge')
$settings = $tp_settings + $settings_hash
$settings = deep_merge($tp_settings,$settings_hash,$my_settings)

include tp

Expand All @@ -35,7 +46,7 @@
info_command => $info_command,
}

$options = merge($options_defaults, $options_hash)
$options = deep_merge($options_defaults, $options_hash, $my_options)

$array_package_name=any2array($settings['package_name'])
$array_service_name=any2array($settings['service_name'])
Expand Down
17 changes: 7 additions & 10 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,25 @@
}

if $conf_hash != {} {
deprecation('conf_hash', 'Replace with confs')
tp::fail('notify', 'Parameter conf_hash in class tp is deprecated, replace it with confs')
}
if $dir_hash != {} {
deprecation('dir_hash', 'Replace with dirs')
tp::fail('notify', 'Parameter dir_hash in class tp is deprecated, replace it with dirs')
}
if $install_hash != {} {
deprecation('install_hash', 'Replace with installs')
tp::fail('notify', 'Parameter install_hash in class tp is deprecated, replace it with installs')
}
if $concat_hash != {} {
deprecation('concat_hash', 'No more supported')
tp::fail('notify', 'Parameter concat_hash in class tp is no more supported')
}
if $stdmod_hash != {} {
deprecation('stdmod__hash', 'No more supported')
tp::fail('notify', 'Parameter stdmod_hash in class tp is no more supported')
}
if $puppi_hash != {} {
deprecation('puppi_hash', 'No more supported')
tp::fail('notify', 'Parameter puppi_hash in class tp is no more supported')
}
if $repo_hash != {} {
deprecation('repo_hash', 'Replace with repos')
}
if $options_hash != {} {
deprecation('options_hash', 'Replace with options')
tp::fail('notify', 'Parameter repo_hash in class tp is no more supported')
}

if 'identity' in $facts {
Expand Down
Loading
Loading