Showing with 41 additions and 15 deletions.
  1. +13 −5 CHANGELOG.md
  2. +2 −2 REFERENCE.md
  3. +1 −1 metadata.json
  4. +12 −5 spec/acceptance/init_spec.rb
  5. +2 −2 tasks/init.json
  6. +11 −0 tasks/init.rb
18 changes: 13 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).

## [v1.0.0](https://github.com/puppetlabs/puppetlabs-puppet_conf/tree/v1.0.0) (2021-02-27)
## [v1.1.0](https://github.com/puppetlabs/puppetlabs-puppet_conf/tree/v1.1.0) (2021-03-13)

[Full Changelog](https://github.com/puppetlabs/puppetlabs-puppet_conf/compare/v1.0.0...v1.1.0)

### Added

- Add delete action [\#140](https://github.com/puppetlabs/puppetlabs-puppet_conf/pull/140) ([fetzerms](https://github.com/fetzerms))

## [v1.0.0](https://github.com/puppetlabs/puppetlabs-puppet_conf/tree/v1.0.0) (2021-03-01)

[Full Changelog](https://github.com/puppetlabs/puppetlabs-puppet_conf/compare/v0.8.0...v1.0.0)

Expand All @@ -18,10 +26,6 @@ All notable changes to this project will be documented in this file. The format

- pdksync - \(feat\) Add support for Puppet 7 [\#125](https://github.com/puppetlabs/puppetlabs-puppet_conf/pull/125) ([daianamezdrea](https://github.com/daianamezdrea))

### Fixed

- pdksync - \(FM-7655\) Fix rubygems-update for ruby \< 2.3 [\#46](https://github.com/puppetlabs/puppetlabs-puppet_conf/pull/46) ([tphoney](https://github.com/tphoney))

## [v.0.7.0](https://github.com/puppetlabs/puppetlabs-puppet_conf/tree/v.0.7.0) (2020-11-16)

[Full Changelog](https://github.com/puppetlabs/puppetlabs-puppet_conf/compare/v0.6.0...v.0.7.0)
Expand Down Expand Up @@ -64,6 +68,10 @@ All notable changes to this project will be documented in this file. The format

[Full Changelog](https://github.com/puppetlabs/puppetlabs-puppet_conf/compare/0.3.0...0.3.1)

### Fixed

- pdksync - \(FM-7655\) Fix rubygems-update for ruby \< 2.3 [\#46](https://github.com/puppetlabs/puppetlabs-puppet_conf/pull/46) ([tphoney](https://github.com/tphoney))

## [0.3.0](https://github.com/puppetlabs/puppetlabs-puppet_conf/tree/0.3.0) (2018-09-27)

[Full Changelog](https://github.com/puppetlabs/puppetlabs-puppet_conf/compare/0.2.1...0.3.0)
Expand Down
4 changes: 2 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Inspect puppet agent configuration settings

##### `action`

Data type: `Enum[get, set]`
Data type: `Enum[get, set, delete]`

The operation (get, set) to perform on the configuration setting
The operation (get, set, delete) to perform on the configuration setting

##### `section`

Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-puppet_conf",
"version": "1.0.0",
"version": "1.1.0",
"author": "puppetlabs",
"summary": "Tasks that manipulates a puppet configuration file",
"license": "Apache-2.0",
Expand Down
17 changes: 12 additions & 5 deletions spec/acceptance/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,36 @@

describe 'puppet_conf task' do
describe 'puppet_conf' do
it 'set/get a puppet configuration' do
it 'set/get/delete a puppet configuration' do
result = run_bolt_task('puppet_conf', 'action' => 'set', 'setting' => 'vardir', 'value' => '/tmp/bla')
expect(result.exit_code).to eq(0)
expect(result['result']['status']).to match %r{.*/tmp/bla}
expect(result['result']).to include 'setting' => 'vardir', 'section' => 'main'

result = run_bolt_task('puppet_conf', 'action' => 'get', 'setting' => 'vardir')

expect(result.exit_code).to eq(0)
expect(result['result']['status']).to match %r{.*/tmp/bla}
expect(result['result']).to include 'setting' => 'vardir', 'section' => 'main'

result = run_bolt_task('puppet_conf', 'action' => 'delete', 'setting' => 'vardir')
expect(result.exit_code).to eq(0)
expect(result['result']['status']).to match %r{.*Deleted.*/tmp/bla}
expect(result['result']).to include 'setting' => 'vardir', 'section' => 'main'
end

it 'set/get a puppet configuration with section' do
it 'set/get/delete a puppet configuration with section' do
result = run_bolt_task('puppet_conf', 'action' => 'set', 'setting' => 'storeconfigs', 'value' => 'false', 'section' => 'server')

expect(result.exit_code).to eq(0)
expect(result['result']).to include 'status' => 'false', 'setting' => 'storeconfigs', 'section' => 'server'

result = run_bolt_task('puppet_conf', 'action' => 'get', 'setting' => 'storeconfigs', 'section' => 'server')

expect(result.exit_code).to eq(0)
expect(result['result']).to include 'status' => 'false', 'setting' => 'storeconfigs', 'section' => 'server'

result = run_bolt_task('puppet_conf', 'action' => 'delete', 'setting' => 'storeconfigs', 'section' => 'server')
expect(result.exit_code).to eq(0)
expect(result['result']['status']).to match %r{.*Deleted.*storeconfigs.*}
expect(result['result']).to include 'setting' => 'storeconfigs', 'section' => 'server'
end
end
end
4 changes: 2 additions & 2 deletions tasks/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"input_method": "stdin",
"parameters": {
"action": {
"description": "The operation (get, set) to perform on the configuration setting",
"type": "Enum[get, set]"
"description": "The operation (get, set, delete) to perform on the configuration setting",
"type": "Enum[get, set, delete]"
},
"section": {
"description": "The section of the config file. Defaults to main",
Expand Down
11 changes: 11 additions & 0 deletions tasks/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ def get(setting, section, _value)
{ status: stdout.strip, setting: setting, section: section }
end

def delete(setting, section, _value)
cmd = [puppet_cmd, 'config', 'delete']
cmd += ['--section', section]
cmd += [setting]
stdout, stderr, status = Open3.capture3(*cmd)
raise Puppet::Error, stderr if status != 0
{ status: stdout.strip, setting: setting, section: section }
end

params = JSON.parse(STDIN.read)
action = params['action']
setting = params['setting']
Expand All @@ -70,6 +79,8 @@ def get(setting, section, _value)
begin
result = if action == 'get'
get(setting, section, value)
elsif action == 'delete'
delete(setting, section, value)
else
raise Puppet::Error, 'You must pass a value argument' if value.nil?
set(setting, section, value)
Expand Down