Skip to content

Commit

Permalink
(#46) add config file purge handler
Browse files Browse the repository at this point in the history
- Add a puppet4 DSL function to generate a static condig file with
sorted keys
- Refactor ini_settting to mcollective::hash2config
- Remove puppetlabs-inifile depencency
- Add default values to hiera data
  • Loading branch information
helge000 committed Jun 21, 2017
1 parent 110ae24 commit 0c81374
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 36 deletions.
10 changes: 10 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ mcollective::common_config:
securityprovider: "choria"
identity: "%{trusted.certname}"
connector: "nats"
main_collective: "mcollective"
collectives: "mcollective"
libdir: "/opt/puppetlabs/mcollective/plugins"

mcollective::policy_default: "deny"

Expand All @@ -20,6 +23,13 @@ mcollective::server_config:
plugin.yaml: "/etc/puppetlabs/mcollective/generated-facts.yaml"
registerinterval: 10
registration: "Choria"
logfile: "/var/log/puppetlabs/mcollective.log"
daemonize: 1

mcollective::client_config:
logger_type: "console"
loglevel: "warn"
connection_timeout: "3"

mcollective::rpcutil_policies:
- action: "allow"
Expand Down
8 changes: 8 additions & 0 deletions functions/hash2config.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generates configuration files for mcollective. Keys are sorted alphabetically:
# key = value
function mcollective::hash2config(Hash $confighash) >> String {
$result = $confighash.keys.sort.map |$key| {
sprintf("%s = %s", $key, $confighash[$key])
}
($result << []).join("\n")
}
26 changes: 9 additions & 17 deletions manifests/config_file.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Utility to create mcollective config files
#
# Can either manipulate an existing config file
# via ini settings or manage a whole file
#
# @param settings hash of settings to add via ini_setting
# @param owner File ownership - only used when content is set
# @param group File group ownership - only used when content is set
Expand All @@ -17,20 +14,15 @@
Enum["present", "absent"] $ensure = "present"
) {
if $content {
file{$name:
owner => $owner,
group => $group,
mode => $mode,
content => $content,
ensure => $ensure
}
$body = $content
} else {
$settings.each |$item, $value| {
ini_setting{"${name}_${item}":
path => $name,
setting => $item,
value => $value
}
}
$body = mcollective::hash2config($settings)
}
file{$name:
owner => $owner,
group => $group,
mode => $mode,
content => $body,
ensure => $ensure
}
}
23 changes: 6 additions & 17 deletions manifests/module_plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,12 @@
}

unless $merged_conf.empty {
file{"${configdir}/plugin.d/${config_name}.cfg":
owner => $owner,
group => $group,
mode => $mode,
ensure => $ensure
}

$merged_conf.each |$item, $value| {
ini_setting{"${name}-${config_name}-${item}":
ensure => $ensure,
path => "${configdir}/plugin.d/${config_name}.cfg",
setting => $item,
value => $value,
require => File["${configdir}/plugin.d/${config_name}.cfg"]
}

Package <| tag == "mcollective_plugin_${name}_packages" |> -> Ini_setting["${name}-${config_name}-${item}"]
mcollective::config_file { "${configdir}/plugin.d/${config_name}.cfg":
ensure => $ensure,
settings => $merged_conf,
owner => $owner,
group => $group,
mode => $mode
}
}

Expand Down
3 changes: 1 addition & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"project_page": "https://github.com/choria-io/puppet-mcollective",
"issues_url": "https://github.com/choria-io/puppet-mcollective/issues",
"dependencies": [
{ "name": "puppetlabs/stdlib", "version_requirement": ">= 4.12.0 < 5.0.0" },
{ "name": "puppetlabs/inifile", "version_requirement": ">= 1.5.0 < 2.0.0" }
{ "name": "puppetlabs/stdlib", "version_requirement": ">= 4.12.0 < 5.0.0" }
],
"operatingsystem_support": [
{
Expand Down

0 comments on commit 0c81374

Please sign in to comment.