diff --git a/REFERENCE.md b/REFERENCE.md index 6b7a8eb..61e1973 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1,112 +1,118 @@ # Reference ## Table of Contents ### Resource types * [`debconf`](#debconf): Manage debconf database entries on Debian based systems. ## Resource types ### `debconf` This type can either set or remove a value for a debconf database entry. It uses multiple programs from the `debconf` package. #### Examples ##### Set a select value ```puppet debconf { 'tzdata/Areas': type => 'select', value => 'Europe', } ``` ##### Set a boolean value ```puppet debconf { 'dash/sh': type => 'boolean', value => 'true', } ``` ##### Set a boolean value in a specified package and mark as seen ```puppet debconf { 'libraries/restart-without-asking': package => 'libc6', type => 'boolean', value => 'true', seen => true, } ``` #### Properties The following properties are available in the `debconf` type. ##### `ensure` Valid values: `present`, `absent` Specifies whether the resource should exist. Setting this to "absent" tells Puppet to remove the debconf entry if it exists, and negates the effect of any other parameters. Default value: `present` ##### `seen` Valid values: ``true``, ``false`` The value of the 'seen' flag. This can be left undefined or be one of the boolean values true or false. ##### `value` Valid values: `%r{\S}` The value for the item (e.g. 'Europe'). #### Parameters The following parameters are available in the `debconf` type. * [`item`](#item) +* [`name`](#name) * [`package`](#package) * [`provider`](#provider) * [`type`](#type) ##### `item` Valid values: `%r{^[a-z0-9][a-z0-9:.+-]+\/[a-zA-Z0-9\/_.+-]+$}` The item name. This string must have the following format: the package name, a literal slash char and the name of the question (e.g. -'tzdata/Areas'). +'tzdata/Areas'). defaults to the title of the resource + +##### `name` + +namevar + ##### `package` Valid values: `%r{^[a-z0-9][a-z0-9:.+-]+$}` The package the item belongs to. The default is the first part (up to the first '/') of the item parameter (e.g. 'tzdata'). ##### `provider` The specific backend to use for this `debconf` resource. You will seldom need to specify this --- Puppet will usually discover the appropriate provider for your platform. ##### `type` Valid values: `string`, `boolean`, `select`, `multiselect`, `note`, `text`, `password`, `title` The type of the item. This can only be one of the following values: string, boolean, select, multiselect, note, text, password, title. diff --git a/lib/puppet/type/debconf.rb b/lib/puppet/type/debconf.rb index 95a6029..7c67ea5 100644 --- a/lib/puppet/type/debconf.rb +++ b/lib/puppet/type/debconf.rb @@ -1,102 +1,106 @@ # debconf.rb --- The debconf type Puppet::Type.newtype(:debconf) do desc <<-EOT @summary Manage debconf database entries on Debian based systems. This type can either set or remove a value for a debconf database entry. It uses multiple programs from the `debconf` package. @example Set a select value debconf { 'tzdata/Areas': type => 'select', value => 'Europe', } @example Set a boolean value debconf { 'dash/sh': type => 'boolean', value => 'true', } @example Set a boolean value in a specified package and mark as seen debconf { 'libraries/restart-without-asking': package => 'libc6', type => 'boolean', value => 'true', seen => true, } EOT def munge_boolean(value) case value when true, 'true', :true :true when false, 'false', :false :false else raise(Puppet::Error, 'munge_boolean only takes booleans') end end ensurable do desc 'Specifies whether the resource should exist. Setting this to "absent" tells Puppet to remove the debconf entry if it exists, and negates the effect of any other parameters.' defaultvalues defaultto :present end - newparam(:item, namevar: true) do + newparam(:name, namevar: true) do + end + + newparam(:item) do desc "The item name. This string must have the following format: the package name, a literal slash char and the name of the question (e.g. - 'tzdata/Areas')." + 'tzdata/Areas'). defaults to the title of the resource" + defaultto { @resource[:name] } newvalues(%r{^[a-z0-9][a-z0-9:.+-]+\/[a-zA-Z0-9\/_.+-]+$}) end newparam(:package) do desc "The package the item belongs to. The default is the first part (up to the first '/') of the item parameter (e.g. 'tzdata')." newvalues(%r{^[a-z0-9][a-z0-9:.+-]+$}) defaultto { @resource[:item].split('/', 2).first } end newparam(:type) do desc "The type of the item. This can only be one of the following values: string, boolean, select, multiselect, note, text, password, title." newvalues(:string, :boolean, :select, :multiselect, :note, :text, :password, :title) end newproperty(:value) do desc "The value for the item (e.g. 'Europe')." newvalues(%r{\S}) munge { |value| value.strip } # Remove leading and trailing spaces end newproperty(:seen, boolean: true) do desc "The value of the 'seen' flag. This can be left undefined or be one of the boolean values true or false." newvalues(:true, :false) munge do |value| @resource.munge_boolean(value) end end validate do unless self[:type] unless self[:ensure].to_s == 'absent' raise(Puppet::Error, 'type is a required attribute') end end end end diff --git a/spec/unit/type/debconf_spec.rb b/spec/unit/type/debconf_spec.rb index f090237..2237300 100644 --- a/spec/unit/type/debconf_spec.rb +++ b/spec/unit/type/debconf_spec.rb @@ -1,30 +1,30 @@ require 'spec_helper' describe Puppet::Type.type(:debconf) do on_supported_os.each do |os, _facts| context "on #{os}" do before(:each) do Facter.clear end describe 'when validating attributes' do [:item, :package, :type].each do |param| it "has a #{param} parameter" do expect(described_class.attrtype(param)).to eq(:param) end end [:value].each do |prop| it "has a #{prop} property" do expect(described_class.attrtype(prop)).to eq(:property) end end end describe 'namevar validation' do it 'has :item as its namevar' do - expect(described_class.key_attributes).to eq([:item]) + expect(described_class.key_attributes).to eq([:name]) end end end end end