560bbc622f
The quote_char is used to quote the entire setting when it is modified as a result of changes to some subsettings. For an example let's assume we have a setting of this form: JAVA_ARGS=-Xmx256m and we want to add the '-Xms' parameter to the setting, for that purpose we define a resource like this: ini_subsetting { '-Xms': ensure => present, path => '/some/config/file', section => '', setting => 'JAVA_ARGS', subsetting => '-Xms' value => '256m', } which results into the following setting: JAVA_ARGS=-Xmx256m -Xms256m But this is not what we intended - if this setting is read by the bash shell the '-Xms256m' parameter is interpreted as a command to be executed rather than a value to be assigned to the JAVA_ARGS variable. To fix this problem the quote_char parameter was added to the ini_subsetting resource type, and we'll take advantage of it to fix the problem in the above example like so: ini_subsetting { '-Xms': ensure => present, path => '/some/config/file', section => '', setting => 'JAVA_ARGS', quote_char => '"', subsetting => '-Xms' value => '256m', } which will result into: JAVA_ARGS="-Xmx256m -Xms256m" which is what we intended.
73 lines
1.5 KiB
Ruby
73 lines
1.5 KiB
Ruby
require File.expand_path('../../../util/ini_file', __FILE__)
|
|
require File.expand_path('../../../util/setting_value', __FILE__)
|
|
|
|
Puppet::Type.type(:ini_subsetting).provide(:ruby) do
|
|
|
|
def exists?
|
|
setting_value.get_subsetting_value(subsetting)
|
|
end
|
|
|
|
def create
|
|
setting_value.add_subsetting(subsetting, resource[:value])
|
|
ini_file.set_value(section, setting, setting_value.get_value)
|
|
ini_file.save
|
|
@ini_file = nil
|
|
@setting_value = nil
|
|
end
|
|
|
|
def destroy
|
|
setting_value.remove_subsetting(subsetting)
|
|
ini_file.set_value(section, setting, setting_value.get_value)
|
|
ini_file.save
|
|
@ini_file = nil
|
|
@setting_value = nil
|
|
end
|
|
|
|
def value
|
|
setting_value.get_subsetting_value(subsetting)
|
|
end
|
|
|
|
def value=(value)
|
|
setting_value.add_subsetting(subsetting, resource[:value])
|
|
ini_file.set_value(section, setting, setting_value.get_value)
|
|
ini_file.save
|
|
end
|
|
|
|
def section
|
|
resource[:section]
|
|
end
|
|
|
|
def setting
|
|
resource[:setting]
|
|
end
|
|
|
|
def subsetting
|
|
resource[:subsetting]
|
|
end
|
|
|
|
def subsetting_separator
|
|
resource[:subsetting_separator]
|
|
end
|
|
|
|
def file_path
|
|
resource[:path]
|
|
end
|
|
|
|
def separator
|
|
resource[:key_val_separator] || '='
|
|
end
|
|
|
|
def quote_char
|
|
resource[:quote_char]
|
|
end
|
|
|
|
private
|
|
def ini_file
|
|
@ini_file ||= Puppet::Util::IniFile.new(file_path, separator)
|
|
end
|
|
|
|
def setting_value
|
|
@setting_value ||= Puppet::Util::SettingValue.new(ini_file.get_value(section, setting), subsetting_separator, quote_char)
|
|
end
|
|
|
|
end
|