Merge pull request #207 from jonnytpuppet/refreshonly
Added refreshonly Parameter
This commit is contained in:
commit
56b24fa819
2 changed files with 50 additions and 0 deletions
|
@ -331,6 +331,33 @@ Global show_diff configuraton takes priority over this one -
|
|||
|
||||
*Optional.* Designates the string that will appear after the section's name. Default value: "]".
|
||||
|
||||
##### `refreshonly`
|
||||
|
||||
*Optional.* A boolean to indicate whether or not the value associated with the setting should be updated if this resource is only part of a refresh event. Default value: **false**.
|
||||
|
||||
For example, if we want a timestamp associated with the last time a setting's value was updated, we could do something like this:
|
||||
|
||||
~~~
|
||||
ini_setting { 'foosetting':
|
||||
ensure => present,
|
||||
path => '/tmp/file.ini',
|
||||
section => 'foo',
|
||||
setting => 'foosetting',
|
||||
value => 'bar',
|
||||
notify => Ini_Setting['foosetting_timestamp'],
|
||||
}
|
||||
|
||||
$now = strftime('%Y-%m-%d %H:%M:%S')
|
||||
ini_setting {'foosetting_timestamp':
|
||||
ensure => present,
|
||||
path => '/tmp/file.ini',
|
||||
section => 'foo',
|
||||
setting => 'foosetting_timestamp',
|
||||
value => $now,
|
||||
refreshonly => true,
|
||||
}
|
||||
~~~
|
||||
|
||||
**NOTE:** This type finds all sections in the file by looking for lines like `${section_prefix}${title}${section_suffix}`.
|
||||
|
||||
### Type: ini_subsetting
|
||||
|
|
|
@ -88,6 +88,15 @@ Puppet::Type.newtype(:ini_setting) do
|
|||
def is_to_s(value)
|
||||
should_to_s(value)
|
||||
end
|
||||
|
||||
def insync?(current)
|
||||
if (@resource[:refreshonly]) then
|
||||
true
|
||||
else
|
||||
current == should
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
newparam(:section_prefix) do
|
||||
|
@ -102,4 +111,18 @@ Puppet::Type.newtype(:ini_setting) do
|
|||
defaultto(']')
|
||||
end
|
||||
|
||||
newparam(:refreshonly) do
|
||||
desc 'A flag indicating whether or not the ini_setting should be updated '+
|
||||
'only when called as part of a refresh event'
|
||||
defaultto false
|
||||
newvalues(true,false)
|
||||
end
|
||||
|
||||
def refresh
|
||||
if self[:refreshonly] then
|
||||
# update the value in the provider, which will save the value to the ini file
|
||||
provider.value = self[:value]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue