2040b31029
With the move of existing policy.json files into code, the file may no longer be shipped by packaging. The json augeas lens requires that the file exist or it fails. This change adds a file resource to ensure the file exists with a basic json construct prior to managing the contents with augeas. Change-Id: I26e8b1384f4f69712da9d06a4c565dfd1f17c9ed Related-Bug: #1742154
72 lines
1.7 KiB
Puppet
72 lines
1.7 KiB
Puppet
# == Definition: openstacklib::policy::base
|
|
#
|
|
# This resource configures the policy.json file for an OpenStack service
|
|
#
|
|
# == Parameters:
|
|
#
|
|
# [*file_path*]
|
|
# Path to the policy.json file
|
|
# string; required
|
|
#
|
|
# [*key*]
|
|
# The key to replace the value for
|
|
# string; required; the key to replace the value for
|
|
#
|
|
# [*value*]
|
|
# The value to set
|
|
# string; optional; the value to set
|
|
#
|
|
# [*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
|
|
#
|
|
define openstacklib::policy::base (
|
|
$file_path,
|
|
$key,
|
|
$value = '',
|
|
$file_mode = '0640',
|
|
$file_user = undef,
|
|
$file_group = undef,
|
|
) {
|
|
|
|
ensure_resource('file', $file_path, {
|
|
mode => $file_mode,
|
|
owner => $file_user,
|
|
group => $file_group,
|
|
replace => false, # augeas will manage the content, we just need to make sure it exists
|
|
content => '{}'
|
|
})
|
|
|
|
# Add entry if it doesn't exists
|
|
augeas { "${file_path}-${key}-${value}-add":
|
|
lens => 'Json.lns',
|
|
incl => $file_path,
|
|
changes => [
|
|
"set dict/entry[last()+1] \"${key}\"",
|
|
"set dict/entry[last()]/string \"${value}\"",
|
|
],
|
|
onlyif => "match dict/entry[*][.=\"${key}\"] size == 0",
|
|
}
|
|
|
|
# Requires that the entry is added before this call or it will fail.
|
|
augeas { "${file_path}-${key}-${value}" :
|
|
lens => 'Json.lns',
|
|
incl => $file_path,
|
|
changes => "set dict/entry[*][.=\"${key}\"]/string \"${value}\"",
|
|
}
|
|
|
|
File<| title == $file_path |>
|
|
-> Augeas<| title == "${file_path}-${key}-${value}-add" |>
|
|
~> Augeas<| title == "${file_path}-${key}-${value}" |>
|
|
|
|
}
|
|
|