Files
puppet-openstacklib/manifests/policy.pp
Takashi Kajinami 2a53c66ed3 Re-implement openstacklib::policy
openstacklib::policy has never been used in any other modules because
it was implemented as a class not reusable for each service.
This change re-implements openstacklib::policy as a defined resource
type so that we can use this implementation from each puppet modules.

The openstacklib::policy resource type provides the purge_config
parameter. When this parameter is set to true, a policy file is cleared
during configuration process. This allows users to remove any existing
rules before applying their own (no) rules.

Change-Id: I9bb486c9191c50c11717dcb9c6af00d17c3aa8f5
2021-08-10 10:25:12 +09:00

68 lines
1.6 KiB
Puppet

# == Define: openstacklib::policies
#
# This resource is an helper to call the policy definition
#
# == Parameters:
#
# [*policy_path*]
# (Optional) Path to the policy file
# Defaults to $name
#
# [*policies*]
# (Optional) Set of policies to configure
#
# [*file_mode*]
# (Optional) Permission mode for the policy file
# Defaults to '0640'
#
# [*file_user*]
# (Optional) User for the policy file
# Defaults to undef
#
# [*file_group*]
# (Optional) Group for the policy file
# Defaults to undef
#
# [*file_format*]
# (Optional) Format for file contents. Valid values
# are 'json' or 'yaml'.
# Defaults to 'json'.
#
# [*purge_config*]
# (Optional) Whether to set only the specified policy rules in the policy
# file.
# Defaults to false.
#
define openstacklib::policy (
$policy_path = $name,
$policies = {},
$file_mode = '0640',
$file_user = undef,
$file_group = undef,
$file_format = 'json',
$purge_config = false,
) {
validate_legacy(Hash, 'validate_hash', $policies)
if empty($policies) {
create_resources('openstacklib::policy::default', { $policy_path => {
file_mode => $file_mode,
file_user => $file_user,
file_group => $file_group,
file_format => $file_format,
purge_config => $purge_config,
}})
} else {
$policy_defaults = {
file_path => $policy_path,
file_mode => $file_mode,
file_user => $file_user,
file_group => $file_group,
file_format => $file_format,
purge_config => $purge_config
}
create_resources('openstacklib::policy::base', $policies, $policy_defaults)
}
}