10. dijkstra
"The art of programming is the art of organizing complexity,
of mastering multitude and avoiding its bastard chaos as
effectively as possible."
11. dijkstra
"Simplicity is a great virtue but it requires hard work to
achieve it and education to appreciate it. And to make
matters worse: complexity sells better."
19. "simple" type
Puppet::Type.newtype(:trafficserver_record) do
desc 'trafficserver_record is a type to manage records.config entries'
newparam(:record, :namevar => true) do
desc "record entry"
end
newproperty(:value) do
desc "Value of this record"
end
end
21. "simple" provider
Puppet::Type.type(:trafficserver_record).provide(:traffic_line) do
desc 'Manage traffic server records.config entries using traffic_line command'
commands :traffic_line => 'traffic_line'
mk_resource_methods
ConfigPattern = 'proxy.(config|local|cluster).*'
def initialize(value={})
super(value)
end
def name=(value)
@property_hash[:name] = value
end
# this method is only called when value isn't insync?
def value=(value)
@property_hash[:name] = resource[:name]
25. type
Puppet::Type.newtype(:git_config) do
validate do
fail('it is required to pass "value"') if self[:value].nil? || self[:value].em
end
newparam(:name) do
desc "The default namevar"
end
newparam(:user) do
desc "The user for which the config will be set. Default value: root"
defaultto "root"
end
newparam(:section, :namevar => true) do
desc "The configuration section. Example: user."
end
newparam(:key, :namevar => true) do
desc "The configuration key. Example: email."
end
26. implementation (correct)
Puppet::Type.type(:git_config).provide(:git_config) do
mk_resource_methods
def check_current?(value)
require 'etc'
user = @resource[:user]
key = @resource[:key]
section = @resource[:section]
home = Etc.getpwnam(user)[:dir]
current = Puppet::Util::Execution.execute(
"git config --global --get #{section}.#{key}",
:uid => user,
:failonfail => false,
:custom_environment => { 'HOME' => home }
)
return value == current.strip
end
def update