Skip to content

Commit b03ccf8

Browse files
authored
Merge pull request #20 from jps-help/templates
Switch to templates for db and lock files
2 parents c3bbba7 + 483dea3 commit b03ccf8

9 files changed

Lines changed: 50 additions & 61 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# Changelog
22

33
All notable changes to this project will be documented in this file.
4+
## Release 0.2.2
5+
### Added
6+
- Declare support for Puppet 8
7+
- Declare support for Ubuntu 24.04
8+
- Add templates for db and locks files
9+
- Add commented headers for managed files
10+
### Changed
11+
- Use templates for db and locks files instead of inifile
12+
- Update spec tests for db and lock file generation
13+
### Removed
14+
- Remove dependency on puppetlabs-inifile
15+
416
## Release 0.2.1
517
### Added
618
- Ensure `/etc/dconf` directory

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ dconf::dbs:
157157
locks: []
158158
```
159159
## Limitations
160-
161-
This module only ensures the specified settings are present in your dconf keyfiles. Unmanaged INI settings in your keyfiles will not be automatically removed.
162-
This is a limitation of the `puppetlabs/inifile` module used to generate the dconf keyfiles.
160+
No known limitations
163161

164162
## Development
165163

REFERENCE.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ The following parameters are available in the `dconf::db` defined type:
167167
* [`locks_file_mode`](#-dconf--db--locks_file_mode)
168168
* [`purge`](#-dconf--db--purge)
169169
* [`ensure`](#-dconf--db--ensure)
170-
* [`inifile_defaults`](#-dconf--db--inifile_defaults)
171170

172171
##### <a name="-dconf--db--settings"></a>`settings`
173172

@@ -281,14 +280,6 @@ Whether to ensure presence or absence of the resource
281280

282281
Default value: `'present'`
283282

284-
##### <a name="-dconf--db--inifile_defaults"></a>`inifile_defaults`
285-
286-
Data type: `Hash`
287-
288-
Default parameters to parse to inifile provider
289-
290-
Default value: `{ ensure => 'present', path => $db_file, notify => Exec['dconf_update'], require => File[$db_file], }`
291-
292283
### <a name="dconf--profile"></a>`dconf::profile`
293284

294285
Create dconf profiles

manifests/db.pp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@
7474
#
7575
# @param ensure Whether to ensure presence or absence of the resource
7676
#
77-
# @param inifile_defaults Default parameters to parse to inifile provider
78-
#
7977
define dconf::db (
8078
Optional[Hash] $settings = undef,
8179
Optional[Array] $locks = undef,
@@ -91,7 +89,6 @@
9189
String $locks_file_mode = '0644',
9290
Boolean $purge = true,
9391
Enum['present','absent'] $ensure = 'present',
94-
Hash $inifile_defaults = { ensure => 'present', path => $db_file, notify => Exec['dconf_update'], require => File[$db_file], },
9592
) {
9693
case $ensure {
9794
'present': {
@@ -102,23 +99,17 @@
10299
recurse => $purge,
103100
force => $purge,
104101
})
102+
$_db_file_header = epp('dconf/header.epp')
103+
$_db_file_body = epp('dconf/db.epp', {
104+
'settings' => $settings
105+
}
106+
)
105107
file { $db_file:
106108
ensure => 'file',
107109
mode => $db_file_mode,
110+
content => "${_db_file_header}${_db_file_body}",
108111
require => File[$db_dir],
109-
}
110-
if $settings {
111-
$settings.each |String $section, Hash $key_vals| {
112-
$key_vals.each |String $setting, $value| {
113-
ini_setting { "db_${name}_settings_${section}_${setting}":
114-
path => $db_file,
115-
section => $section,
116-
setting => $setting,
117-
value => $value,
118-
notify => Exec['dconf_update'],
119-
}
120-
}
121-
}
112+
notify => Exec['dconf_update'],
122113
}
123114
if $locks {
124115
ensure_resource(file, $locks_dir, {
@@ -127,19 +118,18 @@
127118
purge => $purge,
128119
recurse => $purge,
129120
})
130-
concat { "db_${name}_locks":
121+
$_locks_file_header = epp('dconf/header.epp')
122+
$_locks_file_body = epp('dconf/locks.epp', {
123+
'locks' => $locks
124+
}
125+
)
126+
file { "db_${name}_locks":
127+
ensure => $ensure,
131128
path => $locks_file,
132129
mode => $locks_file_mode,
133-
order => 'alpha',
130+
content => "${_locks_file_header}${_locks_file_body}",
134131
require => File[$locks_dir],
135-
}
136-
$locks.each |$lock| {
137-
concat::fragment { "db_${name}_locks_${lock}":
138-
target => $locks_file,
139-
content => "${lock}\n",
140-
require => Concat["db_${name}_locks"],
141-
notify => Exec['dconf_update'],
142-
}
132+
notify => Exec['dconf_update'],
143133
}
144134
}
145135
}

metadata.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jmckenzie-dconf",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"author": "James McKenzie",
55
"summary": "Install and configure dconf",
66
"license": "Apache-2.0",
@@ -9,10 +9,6 @@
99
"source": "git://github.com/jps-help/dconf.git",
1010
"tags": ["dconf","gnome","gdm"],
1111
"dependencies": [
12-
{
13-
"name": "puppetlabs/inifile",
14-
"version_requirement": ">= 4.2.0 < 7.0.0"
15-
},
1612
{
1713
"name": "puppetlabs/concat",
1814
"version_requirement": ">= 4.1.0 < 10.0.0"
@@ -58,14 +54,15 @@
5854
"operatingsystemrelease": [
5955
"18.04",
6056
"20.04",
61-
"22.04"
57+
"22.04",
58+
"24.04"
6259
]
6360
}
6461
],
6562
"requirements": [
6663
{
6764
"name": "puppet",
68-
"version_requirement": ">= 6.21.0 < 8.0.0"
65+
"version_requirement": ">= 6.21.0 < 9.0.0"
6966
}
7067
],
7168
"pdk-version": "2.7.1",

spec/defines/db_spec.rb

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,24 @@
2222

2323
it { is_expected.to compile }
2424
it { is_expected.to contain_file("/etc/dconf/db/#{title}.d").with_ensure('directory') }
25-
it { is_expected.to contain_file("/etc/dconf/db/#{title}.d/00-default").with_ensure('file') }
26-
it {
27-
params['settings'].each do |section, key_vals|
28-
key_vals.each do |setting, _value|
29-
is_expected.to contain_ini_setting("db_#{title}_settings_#{section}_#{setting}").with_notify('Exec[dconf_update]')
30-
end
31-
end
32-
}
25+
it { is_expected.to contain_file("/etc/dconf/db/#{title}.d/00-default").with_ensure('file').with_content(%r{[system/proxy/http]}) }
26+
it { is_expected.to contain_file("/etc/dconf/db/#{title}.d/00-default").with_ensure('file').with_content(%r{host = '172.16.0.1'}) }
27+
it { is_expected.to contain_file("/etc/dconf/db/#{title}.d/00-default").with_ensure('file').with_content(%r{enabled = true}) }
3328

3429
context 'with locks' do
3530
let(:params) do
3631
super().merge(
3732
{
3833
'locks' => [
39-
'system/proxy/http/host',
40-
'system/proxy/http/enabled',
34+
'/system/proxy/http/host',
35+
'/system/proxy/http/enabled',
4136
],
4237
},
4338
)
4439
end
4540

4641
it { is_expected.to contain_file("/etc/dconf/db/#{title}.d/locks").with_ensure('directory') }
47-
it { is_expected.to contain_concat("db_#{title}_locks").with_ensure('present') }
48-
it {
49-
params['locks'].each do |lock|
50-
is_expected.to contain_concat__fragment("db_#{title}_locks_#{lock}").with_notify('Exec[dconf_update]')
51-
end
52-
}
42+
it { is_expected.to contain_file("db_#{title}_locks").with_ensure('present').with_content(%r{/system/proxy/http/host\n/system/proxy/http/enabled}) }
5343

5444
context 'with purge' do
5545
let(:params) do

templates/db.epp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<% | Hash $settings | -%>
2+
<% $settings.each |String $section, Hash $key_vals| { -%>
3+
[<%= $section %>]
4+
<% $key_vals.each |String $key, $value| { -%>
5+
<%= $key %> = <%= $value %>
6+
<% }} -%>

templates/header.epp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This file is managed by Puppet. DO NOT EDIT.

templates/locks.epp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<% | Array[String] $locks | -%>
2+
<% $locks.each | String $lock | { -%>
3+
<%= $lock %>
4+
<% } -%>

0 commit comments

Comments
 (0)