bolt 0.21.7 → 0.21.8
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bolt might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/bolt/transport/ssh/connection.rb +4 -5
- data/lib/bolt/transport/ssh.rb +4 -1
- data/lib/bolt/transport/winrm/connection.rb +3 -4
- data/lib/bolt/transport/winrm.rb +4 -1
- data/lib/bolt/version.rb +1 -1
- data/libexec/apply_catalog.rb +10 -2
- data/vendored/puppet/lib/puppet/application/apply.rb +20 -9
- data/vendored/puppet/lib/puppet/application/cert.rb +3 -1
- data/vendored/puppet/lib/puppet/application/device.rb +22 -5
- data/vendored/puppet/lib/puppet/configurer/fact_handler.rb +5 -1
- data/vendored/puppet/lib/puppet/configurer.rb +15 -2
- data/vendored/puppet/lib/puppet/defaults.rb +36 -25
- data/vendored/puppet/lib/puppet/face/certificate.rb +2 -0
- data/vendored/puppet/lib/puppet/feature/base.rb +0 -3
- data/vendored/puppet/lib/puppet/functions/call.rb +37 -0
- data/vendored/puppet/lib/puppet/functions.rb +5 -0
- data/vendored/puppet/lib/puppet/indirector/ldap.rb +6 -0
- data/vendored/puppet/lib/puppet/node/environment.rb +4 -2
- data/vendored/puppet/lib/puppet/parser/scope.rb +2 -2
- data/vendored/puppet/lib/puppet/pops/adapters.rb +14 -0
- data/vendored/puppet/lib/puppet/pops/evaluator/deferred_resolver.rb +128 -0
- data/vendored/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb +4 -1
- data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +2 -0
- data/vendored/puppet/lib/puppet/pops/issues.rb +9 -1
- data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +0 -16
- data/vendored/puppet/lib/puppet/pops/loaders.rb +1 -3
- data/vendored/puppet/lib/puppet/pops/parser/eparser.rb +6 -6
- data/vendored/puppet/lib/puppet/pops/pcore.rb +11 -0
- data/vendored/puppet/lib/puppet/pops/types/type_factory.rb +17 -0
- data/vendored/puppet/lib/puppet/pops/validation/tasks_checker.rb +13 -5
- data/vendored/puppet/lib/puppet/pops.rb +1 -0
- data/vendored/puppet/lib/puppet/provider/service/debian.rb +1 -0
- data/vendored/puppet/lib/puppet/provider/service/smf.rb +2 -3
- data/vendored/puppet/lib/puppet/provider/service/upstart.rb +10 -2
- data/vendored/puppet/lib/puppet/ssl/certificate_authority.rb +6 -84
- data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +11 -3
- data/vendored/puppet/lib/puppet/type/file.rb +3 -0
- data/vendored/puppet/lib/puppet/type/user.rb +17 -3
- data/vendored/puppet/lib/puppet/util/autoload.rb +36 -31
- data/vendored/puppet/lib/puppet/util.rb +2 -0
- metadata +3 -43
- data/vendored/puppet/lib/puppet/indirector/node/write_only_yaml.rb +0 -39
- data/vendored/puppet/lib/puppet/provider/augeas/augeas.rb +0 -573
- data/vendored/puppet/lib/puppet/provider/cisco.rb +0 -9
- data/vendored/puppet/lib/puppet/provider/computer/computer.rb +0 -20
- data/vendored/puppet/lib/puppet/provider/host/parsed.rb +0 -46
- data/vendored/puppet/lib/puppet/provider/interface/cisco.rb +0 -27
- data/vendored/puppet/lib/puppet/provider/macauthorization/macauthorization.rb +0 -298
- data/vendored/puppet/lib/puppet/provider/mcx/mcxcontent.rb +0 -173
- data/vendored/puppet/lib/puppet/provider/mount/parsed.rb +0 -282
- data/vendored/puppet/lib/puppet/provider/mount.rb +0 -76
- data/vendored/puppet/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +0 -590
- data/vendored/puppet/lib/puppet/provider/selboolean/getsetsebool.rb +0 -47
- data/vendored/puppet/lib/puppet/provider/selmodule/semodule.rb +0 -140
- data/vendored/puppet/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -105
- data/vendored/puppet/lib/puppet/provider/sshkey/parsed.rb +0 -50
- data/vendored/puppet/lib/puppet/provider/vlan/cisco.rb +0 -28
- data/vendored/puppet/lib/puppet/provider/yumrepo/inifile.rb +0 -315
- data/vendored/puppet/lib/puppet/type/augeas.rb +0 -211
- data/vendored/puppet/lib/puppet/type/computer.rb +0 -66
- data/vendored/puppet/lib/puppet/type/host.rb +0 -95
- data/vendored/puppet/lib/puppet/type/interface.rb +0 -121
- data/vendored/puppet/lib/puppet/type/k5login.rb +0 -165
- data/vendored/puppet/lib/puppet/type/macauthorization.rb +0 -167
- data/vendored/puppet/lib/puppet/type/mcx.rb +0 -98
- data/vendored/puppet/lib/puppet/type/mount.rb +0 -314
- data/vendored/puppet/lib/puppet/type/router.rb +0 -17
- data/vendored/puppet/lib/puppet/type/scheduled_task.rb +0 -183
- data/vendored/puppet/lib/puppet/type/selboolean.rb +0 -26
- data/vendored/puppet/lib/puppet/type/selmodule.rb +0 -59
- data/vendored/puppet/lib/puppet/type/ssh_authorized_key.rb +0 -143
- data/vendored/puppet/lib/puppet/type/sshkey.rb +0 -83
- data/vendored/puppet/lib/puppet/type/vlan.rb +0 -26
- data/vendored/puppet/lib/puppet/type/yumrepo.rb +0 -430
- data/vendored/puppet/lib/puppet/util/network_device/cisco/device.rb +0 -285
- data/vendored/puppet/lib/puppet/util/network_device/cisco/facts.rb +0 -72
- data/vendored/puppet/lib/puppet/util/network_device/cisco/interface.rb +0 -94
- data/vendored/puppet/lib/puppet/util/network_device/cisco.rb +0 -4
- data/vendored/puppet/lib/puppet/util/network_device/ipcalc.rb +0 -68
- data/vendored/puppet/lib/puppet/util/network_device/transport/ssh.rb +0 -126
- data/vendored/puppet/lib/puppet/util/network_device/transport/telnet.rb +0 -47
- data/vendored/puppet/lib/puppet/util/windows/taskscheduler.rb +0 -1267
@@ -1,140 +0,0 @@
|
|
1
|
-
Puppet::Type.type(:selmodule).provide(:semodule) do
|
2
|
-
desc "Manage SELinux policy modules using the semodule binary."
|
3
|
-
|
4
|
-
commands :semodule => "/usr/sbin/semodule"
|
5
|
-
|
6
|
-
def create
|
7
|
-
begin
|
8
|
-
execoutput("#{command(:semodule)} --install #{selmod_name_to_filename}")
|
9
|
-
rescue Puppet::ExecutionFailure => detail
|
10
|
-
raise Puppet::Error, "Could not load policy module: #{detail}", detail.backtrace
|
11
|
-
end
|
12
|
-
:true
|
13
|
-
end
|
14
|
-
|
15
|
-
def destroy
|
16
|
-
execoutput("#{command(:semodule)} --remove #{@resource[:name]}")
|
17
|
-
rescue Puppet::ExecutionFailure => detail
|
18
|
-
raise Puppet::Error, "Could not remove policy module: #{detail}", detail.backtrace
|
19
|
-
end
|
20
|
-
|
21
|
-
def exists?
|
22
|
-
self.debug "Checking for module #{@resource[:name]}"
|
23
|
-
execpipe("#{command(:semodule)} --list") do |out|
|
24
|
-
out.each_line do |line|
|
25
|
-
if line =~ /^#{@resource[:name]}\b/
|
26
|
-
return :true
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
nil
|
31
|
-
end
|
32
|
-
|
33
|
-
def syncversion
|
34
|
-
self.debug "Checking syncversion on #{@resource[:name]}"
|
35
|
-
|
36
|
-
loadver = selmodversion_loaded
|
37
|
-
|
38
|
-
if(loadver) then
|
39
|
-
filever = selmodversion_file
|
40
|
-
if (filever == loadver)
|
41
|
-
return :true
|
42
|
-
end
|
43
|
-
end
|
44
|
-
:false
|
45
|
-
end
|
46
|
-
|
47
|
-
def syncversion= (dosync)
|
48
|
-
execoutput("#{command(:semodule)} --upgrade #{selmod_name_to_filename}")
|
49
|
-
rescue Puppet::ExecutionFailure => detail
|
50
|
-
raise Puppet::Error, "Could not upgrade policy module: #{detail}", detail.backtrace
|
51
|
-
end
|
52
|
-
|
53
|
-
# Helper functions
|
54
|
-
|
55
|
-
def execoutput (cmd)
|
56
|
-
output = ''
|
57
|
-
begin
|
58
|
-
execpipe(cmd) do |out|
|
59
|
-
output = out.readlines.join('').chomp!
|
60
|
-
end
|
61
|
-
rescue Puppet::ExecutionFailure
|
62
|
-
raise Puppet::ExecutionFailure, output.split("\n")[0], $!.backtrace
|
63
|
-
end
|
64
|
-
output
|
65
|
-
end
|
66
|
-
|
67
|
-
def selmod_name_to_filename
|
68
|
-
if @resource[:selmodulepath]
|
69
|
-
return @resource[:selmodulepath]
|
70
|
-
else
|
71
|
-
return "#{@resource[:selmoduledir]}/#{@resource[:name]}.pp"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def selmod_readnext (handle)
|
76
|
-
len = handle.read(4).unpack('V')[0]
|
77
|
-
handle.read(len)
|
78
|
-
end
|
79
|
-
|
80
|
-
def selmodversion_file
|
81
|
-
magic = 0xF97CFF8F
|
82
|
-
v = nil
|
83
|
-
|
84
|
-
filename = selmod_name_to_filename
|
85
|
-
# Open a file handle and parse the bytes until version is found
|
86
|
-
Puppet::FileSystem.open(filename, nil, 'rb') do |mod|
|
87
|
-
|
88
|
-
(hdr, ver, numsec) = mod.read(12).unpack('VVV')
|
89
|
-
|
90
|
-
raise Puppet::Error, "Found #{hdr} instead of magic #{magic} in #{filename}" if hdr != magic
|
91
|
-
|
92
|
-
raise Puppet::Error, "Unknown policy file version #{ver} in #{filename}" if ver != 1
|
93
|
-
|
94
|
-
# Read through (and throw away) the file section offsets, and also
|
95
|
-
# the magic header for the first section.
|
96
|
-
|
97
|
-
mod.read((numsec + 1) * 4)
|
98
|
-
|
99
|
-
## Section 1 should be "SE Linux Module"
|
100
|
-
|
101
|
-
selmod_readnext(mod)
|
102
|
-
selmod_readnext(mod)
|
103
|
-
|
104
|
-
# Skip past the section headers
|
105
|
-
mod.read(14)
|
106
|
-
|
107
|
-
# Module name
|
108
|
-
selmod_readnext(mod)
|
109
|
-
|
110
|
-
# At last! the version
|
111
|
-
|
112
|
-
v = selmod_readnext(mod)
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
self.debug "file version #{v}"
|
117
|
-
v
|
118
|
-
end
|
119
|
-
|
120
|
-
def selmodversion_loaded
|
121
|
-
selmod_output = []
|
122
|
-
selmodule_cmd = "#{command(:semodule)} --list"
|
123
|
-
begin
|
124
|
-
execpipe(selmodule_cmd) do |output|
|
125
|
-
output.each_line do |line|
|
126
|
-
line.chomp!
|
127
|
-
selmod_output << line
|
128
|
-
bits = line.split
|
129
|
-
if bits[0] == @resource[:name]
|
130
|
-
self.debug "load version #{bits[1]}"
|
131
|
-
return bits[1]
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
rescue Puppet::ExecutionFailure
|
136
|
-
raise Puppet::ExecutionFailure, _("Could not list policy modules: \"%{selmodule_command}\" failed with \"%{selmod_output}\"") % { selmodule_command: selmodule_cmd, selmod_output: selmod_output.join(' ') }
|
137
|
-
end
|
138
|
-
nil
|
139
|
-
end
|
140
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
require 'puppet/provider/parsedfile'
|
2
|
-
|
3
|
-
Puppet::Type.type(:ssh_authorized_key).provide(
|
4
|
-
:parsed,
|
5
|
-
:parent => Puppet::Provider::ParsedFile,
|
6
|
-
:filetype => :flat,
|
7
|
-
:default_target => ''
|
8
|
-
) do
|
9
|
-
desc "Parse and generate authorized_keys files for SSH."
|
10
|
-
|
11
|
-
text_line :comment, :match => /^\s*#/
|
12
|
-
text_line :blank, :match => /^\s*$/
|
13
|
-
|
14
|
-
record_line :parsed,
|
15
|
-
:fields => %w{options type key name},
|
16
|
-
:optional => %w{options},
|
17
|
-
:rts => /^\s+/,
|
18
|
-
:match => Puppet::Type.type(:ssh_authorized_key).keyline_regex,
|
19
|
-
:post_parse => proc { |h|
|
20
|
-
h[:name] = "" if h[:name] == :absent
|
21
|
-
h[:options] ||= [:absent]
|
22
|
-
h[:options] = Puppet::Type::Ssh_authorized_key::ProviderParsed.parse_options(h[:options]) if h[:options].is_a? String
|
23
|
-
},
|
24
|
-
:pre_gen => proc { |h|
|
25
|
-
# if this name was generated, don't write it back to disk
|
26
|
-
h[:name] = "" if h[:unnamed]
|
27
|
-
h[:options] = [] if h[:options].include?(:absent)
|
28
|
-
h[:options] = h[:options].join(',')
|
29
|
-
}
|
30
|
-
|
31
|
-
record_line :key_v1,
|
32
|
-
:fields => %w{options bits exponent modulus name},
|
33
|
-
:optional => %w{options},
|
34
|
-
:rts => /^\s+/,
|
35
|
-
:match => /^(?:(.+) )?(\d+) (\d+) (\d+)(?: (.+))?$/
|
36
|
-
|
37
|
-
def dir_perm
|
38
|
-
0700
|
39
|
-
end
|
40
|
-
|
41
|
-
def file_perm
|
42
|
-
0600
|
43
|
-
end
|
44
|
-
|
45
|
-
def user
|
46
|
-
uid = Puppet::FileSystem.stat(target).uid
|
47
|
-
Etc.getpwuid(uid).name
|
48
|
-
end
|
49
|
-
|
50
|
-
def flush
|
51
|
-
raise Puppet::Error, "Cannot write SSH authorized keys without user" unless @resource.should(:user)
|
52
|
-
raise Puppet::Error, "User '#{@resource.should(:user)}' does not exist" unless Puppet::Util.uid(@resource.should(:user))
|
53
|
-
# ParsedFile usually calls backup_target much later in the flush process,
|
54
|
-
# but our SUID makes that fail to open filebucket files for writing.
|
55
|
-
# Fortunately, there's already logic to make sure it only ever happens once,
|
56
|
-
# so calling it here suppresses the later attempt by our superclass's flush method.
|
57
|
-
self.class.backup_target(target)
|
58
|
-
|
59
|
-
Puppet::Util::SUIDManager.asuser(@resource.should(:user)) do
|
60
|
-
unless Puppet::FileSystem.exist?(dir = File.dirname(target))
|
61
|
-
Puppet.debug "Creating #{dir} as #{@resource.should(:user)}"
|
62
|
-
Dir.mkdir(dir, dir_perm)
|
63
|
-
end
|
64
|
-
|
65
|
-
super
|
66
|
-
|
67
|
-
File.chmod(file_perm, target)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# Parse sshv2 option strings, which is a comma-separated list of
|
72
|
-
# either key="values" elements or bare-word elements
|
73
|
-
def self.parse_options(options)
|
74
|
-
result = []
|
75
|
-
scanner = StringScanner.new(options)
|
76
|
-
while !scanner.eos?
|
77
|
-
scanner.skip(/[ \t]*/)
|
78
|
-
# scan a long option
|
79
|
-
if out = scanner.scan(/[-a-z0-9A-Z_]+=\".*?[^\\]\"/) or out = scanner.scan(/[-a-z0-9A-Z_]+/)
|
80
|
-
result << out
|
81
|
-
else
|
82
|
-
# found an unscannable token, let's abort
|
83
|
-
break
|
84
|
-
end
|
85
|
-
# eat a comma
|
86
|
-
scanner.skip(/[ \t]*,[ \t]*/)
|
87
|
-
end
|
88
|
-
result
|
89
|
-
end
|
90
|
-
|
91
|
-
def self.prefetch_hook(records)
|
92
|
-
name_index = 0
|
93
|
-
records.each do |record|
|
94
|
-
if record[:record_type] == :parsed && record[:name].empty?
|
95
|
-
record[:unnamed] = true
|
96
|
-
# Generate a unique ID for unnamed keys, in case they need purging.
|
97
|
-
# If you change this, you have to keep
|
98
|
-
# Puppet::Type::User#unknown_keys_in_file in sync! (PUP-3357)
|
99
|
-
record[:name] = "#{record[:target]}:unnamed-#{ name_index += 1 }"
|
100
|
-
Puppet.debug("generating name for on-disk ssh_authorized_key #{record[:key]}: #{record[:name]}")
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'puppet/provider/parsedfile'
|
2
|
-
|
3
|
-
Puppet::Type.type(:sshkey).provide(
|
4
|
-
:parsed,
|
5
|
-
:parent => Puppet::Provider::ParsedFile,
|
6
|
-
:filetype => :flat
|
7
|
-
) do
|
8
|
-
desc "Parse and generate host-wide known hosts files for SSH."
|
9
|
-
|
10
|
-
text_line :comment, :match => /^#/
|
11
|
-
text_line :blank, :match => /^\s*$/
|
12
|
-
|
13
|
-
record_line :parsed, :fields => %w{name type key},
|
14
|
-
:post_parse => proc { |hash|
|
15
|
-
names = hash[:name].split(",", -1)
|
16
|
-
hash[:name] = names.shift
|
17
|
-
hash[:host_aliases] = names
|
18
|
-
},
|
19
|
-
:pre_gen => proc { |hash|
|
20
|
-
if hash[:host_aliases]
|
21
|
-
hash[:name] = [hash[:name], hash[:host_aliases]].flatten.join(",")
|
22
|
-
hash.delete(:host_aliases)
|
23
|
-
end
|
24
|
-
}
|
25
|
-
|
26
|
-
# Make sure to use mode 644 if ssh_known_hosts is newly created
|
27
|
-
def self.default_mode
|
28
|
-
0644
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.default_target
|
32
|
-
case Facter.value(:operatingsystem)
|
33
|
-
when "Darwin"
|
34
|
-
# Versions 10.11 and up use /etc/ssh/ssh_known_hosts
|
35
|
-
version = Facter.value(:macosx_productversion_major)
|
36
|
-
if version
|
37
|
-
if Puppet::Util::Package.versioncmp(version, '10.11') >= 0
|
38
|
-
"/etc/ssh/ssh_known_hosts"
|
39
|
-
else
|
40
|
-
"/etc/ssh_known_hosts"
|
41
|
-
end
|
42
|
-
else
|
43
|
-
"/etc/ssh_known_hosts"
|
44
|
-
end
|
45
|
-
else
|
46
|
-
"/etc/ssh/ssh_known_hosts"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'puppet/provider/cisco'
|
2
|
-
|
3
|
-
Puppet::Type.type(:vlan).provide :cisco, :parent => Puppet::Provider::Cisco do
|
4
|
-
|
5
|
-
desc "Cisco switch/router provider for vlans."
|
6
|
-
|
7
|
-
mk_resource_methods
|
8
|
-
|
9
|
-
def self.lookup(device, id)
|
10
|
-
vlans = {}
|
11
|
-
device.command do |dev|
|
12
|
-
vlans = dev.parse_vlans || {}
|
13
|
-
end
|
14
|
-
vlans[id]
|
15
|
-
end
|
16
|
-
|
17
|
-
def initialize(device, *args)
|
18
|
-
super
|
19
|
-
end
|
20
|
-
|
21
|
-
# Clear out the cached values.
|
22
|
-
def flush
|
23
|
-
device.command do |dev|
|
24
|
-
dev.update_vlan(resource[:name], former_properties, properties)
|
25
|
-
end
|
26
|
-
super
|
27
|
-
end
|
28
|
-
end
|
@@ -1,315 +0,0 @@
|
|
1
|
-
require 'puppet/util/inifile'
|
2
|
-
|
3
|
-
Puppet::Type.type(:yumrepo).provide(:inifile) do
|
4
|
-
desc <<-EOD
|
5
|
-
Manage yum repo configurations by parsing yum INI configuration files.
|
6
|
-
|
7
|
-
### Fetching instances
|
8
|
-
|
9
|
-
When fetching repo instances, directory entries in '/etc/yum/repos.d',
|
10
|
-
'/etc/yum.repos.d', and the directory optionally specified by the reposdir
|
11
|
-
key in '/etc/yum.conf' will be checked. If a given directory does not exist it
|
12
|
-
will be ignored. In addition, all sections in '/etc/yum.conf' aside from
|
13
|
-
'main' will be created as sections.
|
14
|
-
|
15
|
-
### Storing instances
|
16
|
-
|
17
|
-
When creating a new repository, a new section will be added in the first
|
18
|
-
yum repo directory that exists. The custom directory specified by the
|
19
|
-
'/etc/yum.conf' reposdir property is checked first, followed by
|
20
|
-
'/etc/yum/repos.d', and then '/etc/yum.repos.d'. If none of these exist, the
|
21
|
-
section will be created in '/etc/yum.conf'.
|
22
|
-
EOD
|
23
|
-
|
24
|
-
PROPERTIES = Puppet::Type.type(:yumrepo).validproperties
|
25
|
-
|
26
|
-
# Retrieve all providers based on existing yum repositories
|
27
|
-
#
|
28
|
-
# @api public
|
29
|
-
# @return [Array<Puppet::Provider>] providers generated from existing yum
|
30
|
-
# repository definitions.
|
31
|
-
def self.instances
|
32
|
-
instances = []
|
33
|
-
|
34
|
-
virtual_inifile.each_section do |section|
|
35
|
-
# Ignore the 'main' section in yum.conf since it's not a repository.
|
36
|
-
next if section.name == "main"
|
37
|
-
|
38
|
-
attributes_hash = {:name => section.name, :ensure => :present, :provider => :yumrepo}
|
39
|
-
|
40
|
-
section.entries.each do |key, value|
|
41
|
-
key = key.to_sym
|
42
|
-
if valid_property?(key)
|
43
|
-
attributes_hash[key] = value
|
44
|
-
elsif key == :name
|
45
|
-
attributes_hash[:descr] = value
|
46
|
-
end
|
47
|
-
end
|
48
|
-
instances << new(attributes_hash)
|
49
|
-
end
|
50
|
-
|
51
|
-
instances
|
52
|
-
end
|
53
|
-
|
54
|
-
# Match catalog type instances to provider instances.
|
55
|
-
#
|
56
|
-
# @api public
|
57
|
-
# @param resources [Array<Puppet::Type::Yumrepo>] Resources to prefetch.
|
58
|
-
# @return [void]
|
59
|
-
def self.prefetch(resources)
|
60
|
-
repos = instances
|
61
|
-
resources.each_key do |name|
|
62
|
-
if provider = repos.find { |repo| repo.name == name }
|
63
|
-
resources[name].provider = provider
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# Return a list of existing directories that could contain repo files.
|
69
|
-
#
|
70
|
-
# @api private
|
71
|
-
# @param conf [String] Configuration file to look for directories in.
|
72
|
-
# @param dirs [Array<String>] Default locations for yum repos.
|
73
|
-
# @return [Array<String>] All present directories that may contain yum repo configs.
|
74
|
-
def self.reposdir(conf='/etc/yum.conf', dirs=['/etc/yum.repos.d', '/etc/yum/repos.d'])
|
75
|
-
reposdir = find_conf_value('reposdir', conf)
|
76
|
-
# Use directories in reposdir if they are set instead of default
|
77
|
-
if reposdir
|
78
|
-
# Follow the code from the yum/config.py
|
79
|
-
reposdir.gsub!("\n", ' ')
|
80
|
-
reposdir.gsub!(',', ' ')
|
81
|
-
dirs = reposdir.split
|
82
|
-
end
|
83
|
-
dirs.select! { |dir| Puppet::FileSystem.exist?(dir) }
|
84
|
-
if dirs.empty?
|
85
|
-
Puppet.debug('No yum directories were found on the local filesystem')
|
86
|
-
end
|
87
|
-
|
88
|
-
dirs
|
89
|
-
end
|
90
|
-
|
91
|
-
# Used for testing only
|
92
|
-
# @api private
|
93
|
-
def self.clear
|
94
|
-
@virtual = nil
|
95
|
-
end
|
96
|
-
|
97
|
-
# Helper method to look up specific values in ini style files.
|
98
|
-
#
|
99
|
-
# @api private
|
100
|
-
# @param value [String] Value to look for in the configuration file.
|
101
|
-
# @param conf [String] Configuration file to check for value.
|
102
|
-
# @return [String] The value of a looked up key from the configuration file.
|
103
|
-
def self.find_conf_value(value, conf='/etc/yum.conf')
|
104
|
-
if Puppet::FileSystem.exist?(conf)
|
105
|
-
file = Puppet::Util::IniConfig::PhysicalFile.new(conf)
|
106
|
-
file.read
|
107
|
-
if (main = file.get_section('main'))
|
108
|
-
main[value]
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# Enumerate all files that may contain yum repository configs.
|
114
|
-
# '/etc/yum.conf' is always included.
|
115
|
-
#
|
116
|
-
# @api private
|
117
|
-
# @return [Array<String>
|
118
|
-
def self.repofiles
|
119
|
-
files = ["/etc/yum.conf"]
|
120
|
-
reposdir.each do |dir|
|
121
|
-
Dir.glob("#{dir}/*.repo").each do |file|
|
122
|
-
files << file
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
files
|
127
|
-
end
|
128
|
-
|
129
|
-
# Build a virtual inifile by reading in numerous .repo files into a single
|
130
|
-
# virtual file to ease manipulation.
|
131
|
-
# @api private
|
132
|
-
# @return [Puppet::Util::IniConfig::File] The virtual inifile representing
|
133
|
-
# multiple real files.
|
134
|
-
def self.virtual_inifile
|
135
|
-
unless @virtual
|
136
|
-
@virtual = Puppet::Util::IniConfig::File.new
|
137
|
-
self.repofiles.each do |file|
|
138
|
-
@virtual.read(file) if Puppet::FileSystem.file?(file)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
return @virtual
|
142
|
-
end
|
143
|
-
|
144
|
-
# Is the given key a valid type property?
|
145
|
-
#
|
146
|
-
# @api private
|
147
|
-
# @param key [String] The property to look up.
|
148
|
-
# @return [Boolean] Returns true if the property is defined in the type.
|
149
|
-
def self.valid_property?(key)
|
150
|
-
PROPERTIES.include?(key)
|
151
|
-
end
|
152
|
-
|
153
|
-
# Return an existing INI section or create a new section in the default location
|
154
|
-
#
|
155
|
-
# The default location is determined based on what yum repo directories
|
156
|
-
# and files are present. If /etc/yum.conf has a value for 'reposdir' then that
|
157
|
-
# is preferred. If no such INI property is found then the first default yum
|
158
|
-
# repo directory that is present is used. If no default directories exist then
|
159
|
-
# /etc/yum.conf is used.
|
160
|
-
#
|
161
|
-
# @param name [String] Section name to lookup in the virtual inifile.
|
162
|
-
# @return [Puppet::Util::IniConfig] The IniConfig section
|
163
|
-
def self.section(name)
|
164
|
-
result = self.virtual_inifile[name]
|
165
|
-
# Create a new section if not found.
|
166
|
-
unless result
|
167
|
-
path = getRepoPath(name)
|
168
|
-
result = self.virtual_inifile.add_section(name, path)
|
169
|
-
end
|
170
|
-
result
|
171
|
-
end
|
172
|
-
|
173
|
-
# Save all yum repository files and force the mode to 0644
|
174
|
-
# @api private
|
175
|
-
# @return [void]
|
176
|
-
def self.store(resource)
|
177
|
-
inifile = self.virtual_inifile
|
178
|
-
inifile.store
|
179
|
-
|
180
|
-
target_mode = 0644
|
181
|
-
inifile.each_file do |file|
|
182
|
-
next unless Puppet::FileSystem.exist?(file)
|
183
|
-
current_mode = Puppet::FileSystem.stat(file).mode & 0777
|
184
|
-
unless current_mode == target_mode
|
185
|
-
resource.info _("changing mode of %{file} from %{current_mode} to %{target_mode}") %
|
186
|
-
{ file: file, current_mode: "%03o" % current_mode, target_mode: "%03o" % target_mode }
|
187
|
-
Puppet::FileSystem.chmod(target_mode, file)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def self.getRepoPath(name)
|
193
|
-
dirs = reposdir()
|
194
|
-
if dirs.empty?
|
195
|
-
# If no repo directories are present, default to using yum.conf.
|
196
|
-
path = '/etc/yum.conf'
|
197
|
-
else
|
198
|
-
# The ordering of reposdir is [defaults, custom], and we want to use
|
199
|
-
# the custom directory if present.
|
200
|
-
path = File.join(dirs.last, "#{name}.repo")
|
201
|
-
end
|
202
|
-
path
|
203
|
-
end
|
204
|
-
|
205
|
-
# Create a new section for the given repository and set all the specified
|
206
|
-
# properties in the section.
|
207
|
-
#
|
208
|
-
# @api public
|
209
|
-
# @return [void]
|
210
|
-
def create
|
211
|
-
@property_hash[:ensure] = :present
|
212
|
-
|
213
|
-
# Check to see if the file that would be created in the
|
214
|
-
# default location for the yumrepo already exists on disk.
|
215
|
-
# If it does, read it in to the virtual inifile
|
216
|
-
path = self.class.getRepoPath(name)
|
217
|
-
self.class.virtual_inifile.read(path) if Puppet::FileSystem.file?(path)
|
218
|
-
|
219
|
-
# We fetch a list of properties from the type, then iterate
|
220
|
-
# over them, avoiding ensure. We're relying on .should to
|
221
|
-
# check if the property has been set and should be modified,
|
222
|
-
# and if so we set it in the virtual inifile.
|
223
|
-
PROPERTIES.each do |property|
|
224
|
-
next if property == :ensure
|
225
|
-
|
226
|
-
if value = @resource.should(property)
|
227
|
-
self.send("#{property}=", value)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
# Does the given repository already exist?
|
233
|
-
#
|
234
|
-
# @api public
|
235
|
-
# @return [Boolean]
|
236
|
-
def exists?
|
237
|
-
@property_hash[:ensure] == :present
|
238
|
-
end
|
239
|
-
|
240
|
-
# Mark the given repository section for destruction.
|
241
|
-
#
|
242
|
-
# The actual removal of the section will be handled by {#flush} after the
|
243
|
-
# resource has been fully evaluated.
|
244
|
-
#
|
245
|
-
# @api public
|
246
|
-
# @return [void]
|
247
|
-
def destroy
|
248
|
-
# Flag file for deletion on flush.
|
249
|
-
current_section.destroy=(true)
|
250
|
-
|
251
|
-
@property_hash.clear
|
252
|
-
end
|
253
|
-
|
254
|
-
# Finalize the application of the given resource.
|
255
|
-
#
|
256
|
-
# @api public
|
257
|
-
# @return [void]
|
258
|
-
def flush
|
259
|
-
self.class.store(self)
|
260
|
-
end
|
261
|
-
|
262
|
-
# Generate setters and getters for our INI properties.
|
263
|
-
PROPERTIES.each do |property|
|
264
|
-
# The ensure property uses #create, #exists, and #destroy we can't generate
|
265
|
-
# meaningful setters and getters for this
|
266
|
-
next if property == :ensure
|
267
|
-
|
268
|
-
define_method(property) do
|
269
|
-
get_property(property)
|
270
|
-
end
|
271
|
-
|
272
|
-
define_method("#{property}=") do |value|
|
273
|
-
set_property(property, value)
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
# Map the yumrepo 'descr' type property to the 'name' INI property.
|
278
|
-
def descr
|
279
|
-
if ! @property_hash.has_key?(:descr)
|
280
|
-
@property_hash[:descr] = current_section['name']
|
281
|
-
end
|
282
|
-
value = @property_hash[:descr]
|
283
|
-
value.nil? ? :absent : value
|
284
|
-
end
|
285
|
-
|
286
|
-
def descr=(value)
|
287
|
-
value = (value == :absent ? nil : value)
|
288
|
-
current_section['name'] = value
|
289
|
-
@property_hash[:descr] = value
|
290
|
-
end
|
291
|
-
|
292
|
-
private
|
293
|
-
|
294
|
-
def get_property(property)
|
295
|
-
if ! @property_hash.has_key?(property)
|
296
|
-
@property_hash[property] = current_section[property.to_s]
|
297
|
-
end
|
298
|
-
value = @property_hash[property]
|
299
|
-
value.nil? ? :absent : value
|
300
|
-
end
|
301
|
-
|
302
|
-
def set_property(property, value)
|
303
|
-
value = (value == :absent ? nil : value)
|
304
|
-
current_section[property.to_s] = value
|
305
|
-
@property_hash[property] = value
|
306
|
-
end
|
307
|
-
|
308
|
-
def section(name)
|
309
|
-
self.class.section(name)
|
310
|
-
end
|
311
|
-
|
312
|
-
def current_section
|
313
|
-
self.class.section(self.name)
|
314
|
-
end
|
315
|
-
end
|