bolt 0.23.0 → 0.24.0
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/bolt-modules/boltlib/lib/puppet/functions/apply_prep.rb +5 -2
- data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb +5 -1
- data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +5 -8
- data/lib/bolt/applicator.rb +11 -8
- data/lib/bolt/boltdir.rb +13 -5
- data/lib/bolt/catalog.rb +22 -47
- data/lib/bolt/config.rb +1 -26
- data/lib/bolt/executor.rb +1 -1
- data/lib/bolt/outputter.rb +0 -9
- data/lib/bolt/outputter/human.rb +29 -14
- data/lib/bolt/outputter/json.rb +12 -1
- data/lib/bolt/pal.rb +12 -10
- data/lib/bolt/target.rb +0 -6
- data/lib/bolt/task.rb +53 -10
- data/lib/bolt/transport/base.rb +1 -6
- data/lib/bolt/transport/local.rb +11 -13
- data/lib/bolt/transport/local/shell.rb +2 -2
- data/lib/bolt/transport/ssh.rb +16 -11
- data/lib/bolt/transport/winrm.rb +8 -11
- data/lib/bolt/version.rb +1 -1
- data/lib/bolt_ext/schemas/task.json +12 -5
- data/libexec/apply_catalog.rb +3 -1
- data/libexec/bolt_catalog +4 -0
- data/vendored/puppet/lib/puppet.rb +2 -1
- data/vendored/puppet/lib/puppet/application/agent.rb +2 -6
- data/vendored/puppet/lib/puppet/application/apply.rb +100 -60
- data/vendored/puppet/lib/puppet/application/cert.rb +26 -291
- data/vendored/puppet/lib/puppet/application/device.rb +0 -5
- data/vendored/puppet/lib/puppet/application/lookup.rb +1 -1
- data/vendored/puppet/lib/puppet/application/ssl.rb +133 -0
- data/vendored/puppet/lib/puppet/application_support.rb +1 -2
- data/vendored/puppet/lib/puppet/configurer.rb +34 -50
- data/vendored/puppet/lib/puppet/configurer/downloader.rb +1 -1
- data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +1 -1
- data/vendored/puppet/lib/puppet/daemon.rb +1 -1
- data/vendored/puppet/lib/puppet/defaults.rb +40 -117
- data/vendored/puppet/lib/puppet/face/epp.rb +2 -2
- data/vendored/puppet/lib/puppet/face/help.rb +21 -7
- data/vendored/puppet/lib/puppet/face/node/clean.rb +14 -10
- data/vendored/puppet/lib/puppet/feature/base.rb +7 -23
- data/vendored/puppet/lib/puppet/feature/eventlog.rb +1 -1
- data/vendored/puppet/lib/puppet/file_serving/base.rb +2 -2
- data/vendored/puppet/lib/puppet/file_serving/fileset.rb +1 -1
- data/vendored/puppet/lib/puppet/file_serving/metadata.rb +2 -2
- data/vendored/puppet/lib/puppet/functions.rb +133 -0
- data/vendored/puppet/lib/puppet/functions/eyaml_lookup_key.rb +4 -5
- data/vendored/puppet/lib/puppet/functions/filter.rb +7 -6
- data/vendored/puppet/lib/puppet/functions/new.rb +37 -53
- data/vendored/puppet/lib/puppet/functions/warning.rb +1 -1
- data/vendored/puppet/lib/puppet/functions/yaml_data.rb +4 -5
- data/vendored/puppet/lib/puppet/gettext/config.rb +1 -1
- data/vendored/puppet/lib/puppet/graph.rb +0 -2
- data/vendored/puppet/lib/puppet/indirector/catalog/json.rb +14 -3
- data/vendored/puppet/lib/puppet/indirector/catalog/yaml.rb +0 -16
- data/vendored/puppet/lib/puppet/indirector/certificate/file.rb +0 -1
- data/vendored/puppet/lib/puppet/indirector/facts/yaml.rb +4 -2
- data/vendored/puppet/lib/puppet/indirector/key/file.rb +1 -6
- data/vendored/puppet/lib/puppet/indirector/node/exec.rb +1 -3
- data/vendored/puppet/lib/puppet/indirector/node/yaml.rb +0 -6
- data/vendored/puppet/lib/puppet/indirector/request.rb +1 -1
- data/vendored/puppet/lib/puppet/indirector/ssl_file.rb +3 -44
- data/vendored/puppet/lib/puppet/indirector/yaml.rb +4 -4
- data/vendored/puppet/lib/puppet/info_service/task_information_service.rb +7 -3
- data/vendored/puppet/lib/puppet/loaders.rb +1 -0
- data/vendored/puppet/lib/puppet/module/task.rb +198 -29
- data/vendored/puppet/lib/puppet/module_tool/applications/unpacker.rb +1 -1
- data/vendored/puppet/lib/puppet/network/format_support.rb +13 -8
- data/vendored/puppet/lib/puppet/network/formats.rb +93 -2
- data/vendored/puppet/lib/puppet/network/http/api/indirected_routes.rb +10 -3
- data/vendored/puppet/lib/puppet/node/facts.rb +11 -1
- data/vendored/puppet/lib/puppet/parser/catalog_compiler.rb +56 -0
- data/vendored/puppet/lib/puppet/parser/compiler.rb +3 -1
- data/vendored/puppet/lib/puppet/parser/functions.rb +3 -1
- data/vendored/puppet/lib/puppet/parser/functions/filter.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/functions/generate.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/functions/sprintf.rb +12 -1
- data/vendored/puppet/lib/puppet/parser/functions/tagged.rb +1 -4
- data/vendored/puppet/lib/puppet/parser/scope.rb +1 -1
- data/vendored/puppet/lib/puppet/parser/script_compiler.rb +7 -2
- data/vendored/puppet/lib/puppet/pops/evaluator/deferred_resolver.rb +5 -3
- data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_converter.rb +23 -4
- data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_support.rb +3 -4
- data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +4 -0
- data/vendored/puppet/lib/puppet/pops/issues.rb +8 -0
- data/vendored/puppet/lib/puppet/pops/loader/loader.rb +2 -2
- data/vendored/puppet/lib/puppet/pops/loader/loader_paths.rb +3 -1
- data/vendored/puppet/lib/puppet/pops/loader/module_loaders.rb +30 -9
- data/vendored/puppet/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +62 -0
- data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +0 -1
- data/vendored/puppet/lib/puppet/pops/loader/task_instantiator.rb +13 -70
- data/vendored/puppet/lib/puppet/pops/loaders.rb +19 -29
- data/vendored/puppet/lib/puppet/pops/lookup/hiera_config.rb +1 -1
- data/vendored/puppet/lib/puppet/pops/model/model_label_provider.rb +4 -1
- data/vendored/puppet/lib/puppet/pops/pcore.rb +10 -33
- data/vendored/puppet/lib/puppet/pops/serialization.rb +2 -0
- data/vendored/puppet/lib/puppet/pops/serialization/from_data_converter.rb +2 -1
- data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +11 -3
- data/vendored/puppet/lib/puppet/pops/serialization/to_stringified_converter.rb +226 -0
- data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +3 -0
- data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +97 -47
- data/vendored/puppet/lib/puppet/pops/validation/validator_factory_4_0.rb +7 -8
- data/vendored/puppet/lib/puppet/property/keyvalue.rb +70 -8
- data/vendored/puppet/lib/puppet/provider/aix_object.rb +483 -0
- data/vendored/puppet/lib/puppet/provider/file/windows.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/group/aix.rb +51 -112
- data/vendored/puppet/lib/puppet/provider/package/gem.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/pip.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/puppet_gem.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/rpm.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/windows/package.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/package/zypper.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/service/systemd.rb +1 -1
- data/vendored/puppet/lib/puppet/provider/service/windows.rb +37 -40
- data/vendored/puppet/lib/puppet/provider/user/aix.rb +142 -254
- data/vendored/puppet/lib/puppet/resource.rb +20 -3
- data/vendored/puppet/lib/puppet/resource/catalog.rb +2 -12
- data/vendored/puppet/lib/puppet/rest/routes.rb +97 -34
- data/vendored/puppet/lib/puppet/settings.rb +1 -1
- data/vendored/puppet/lib/puppet/settings/file_setting.rb +1 -1
- data/vendored/puppet/lib/puppet/ssl/base.rb +1 -9
- data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +1 -13
- data/vendored/puppet/lib/puppet/ssl/certificate_request_attributes.rb +1 -1
- data/vendored/puppet/lib/puppet/ssl/host.rb +114 -232
- data/vendored/puppet/lib/puppet/ssl/key.rb +1 -5
- data/vendored/puppet/lib/puppet/ssl/oids.rb +1 -1
- data/vendored/puppet/lib/puppet/test/test_helper.rb +0 -4
- data/vendored/puppet/lib/puppet/transaction/event.rb +3 -7
- data/vendored/puppet/lib/puppet/transaction/persistence.rb +1 -1
- data/vendored/puppet/lib/puppet/type/exec.rb +18 -16
- data/vendored/puppet/lib/puppet/type/file.rb +3 -3
- data/vendored/puppet/lib/puppet/type/file/source.rb +20 -7
- data/vendored/puppet/lib/puppet/type/group.rb +3 -5
- data/vendored/puppet/lib/puppet/type/notify.rb +1 -1
- data/vendored/puppet/lib/puppet/type/package.rb +2 -5
- data/vendored/puppet/lib/puppet/type/schedule.rb +1 -1
- data/vendored/puppet/lib/puppet/type/service.rb +3 -6
- data/vendored/puppet/lib/puppet/type/tidy.rb +1 -1
- data/vendored/puppet/lib/puppet/type/user.rb +13 -20
- data/vendored/puppet/lib/puppet/util.rb +8 -9
- data/vendored/puppet/lib/puppet/util/execution.rb +3 -3
- data/vendored/puppet/lib/puppet/util/feature.rb +61 -39
- data/vendored/puppet/lib/puppet/util/log/destinations.rb +1 -1
- data/vendored/puppet/lib/puppet/util/rdoc.rb +1 -1
- data/vendored/puppet/lib/puppet/util/run_mode.rb +1 -1
- data/vendored/puppet/lib/puppet/util/storage.rb +1 -1
- data/vendored/puppet/lib/puppet/util/suidmanager.rb +7 -5
- data/vendored/puppet/lib/puppet/util/tag_set.rb +1 -1
- data/vendored/puppet/lib/puppet/util/tagging.rb +1 -1
- data/vendored/puppet/lib/puppet/util/windows.rb +18 -2
- data/vendored/puppet/lib/puppet/util/windows/adsi.rb +154 -205
- data/vendored/puppet/lib/puppet/util/windows/service.rb +770 -0
- data/vendored/puppet/lib/puppet/util/yaml.rb +41 -5
- data/vendored/puppet/lib/puppet/version.rb +1 -1
- data/vendored/puppet/lib/puppet_pal.rb +280 -24
- metadata +8 -38
- data/lib/bolt/catalog/compiler.rb +0 -48
- data/lib/bolt/catalog/loaders.rb +0 -19
- data/vendored/puppet/lib/puppet/application/ca.rb +0 -11
- data/vendored/puppet/lib/puppet/application/certificate.rb +0 -17
- data/vendored/puppet/lib/puppet/application/certificate_request.rb +0 -7
- data/vendored/puppet/lib/puppet/application/certificate_revocation_list.rb +0 -7
- data/vendored/puppet/lib/puppet/face/ca.rb +0 -266
- data/vendored/puppet/lib/puppet/face/certificate.rb +0 -167
- data/vendored/puppet/lib/puppet/face/certificate_request.rb +0 -56
- data/vendored/puppet/lib/puppet/face/certificate_revocation_list.rb +0 -56
- data/vendored/puppet/lib/puppet/graph/random_prioritizer.rb +0 -16
- data/vendored/puppet/lib/puppet/graph/title_hash_prioritizer.rb +0 -16
- data/vendored/puppet/lib/puppet/indirector/certificate/ca.rb +0 -9
- data/vendored/puppet/lib/puppet/indirector/certificate/disabled_ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/certificate_request/ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/certificate_request/disabled_ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/ca.rb +0 -8
- data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/disabled_ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/file.rb +0 -8
- data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/rest.rb +0 -11
- data/vendored/puppet/lib/puppet/indirector/certificate_status.rb +0 -4
- data/vendored/puppet/lib/puppet/indirector/certificate_status/file.rb +0 -91
- data/vendored/puppet/lib/puppet/indirector/certificate_status/rest.rb +0 -11
- data/vendored/puppet/lib/puppet/indirector/key/ca.rb +0 -16
- data/vendored/puppet/lib/puppet/indirector/key/disabled_ca.rb +0 -22
- data/vendored/puppet/lib/puppet/indirector/ldap.rb +0 -86
- data/vendored/puppet/lib/puppet/indirector/node/ldap.rb +0 -275
- data/vendored/puppet/lib/puppet/provider/aixobject.rb +0 -392
- data/vendored/puppet/lib/puppet/provider/cron/crontab.rb +0 -297
- data/vendored/puppet/lib/puppet/ssl/certificate_authority.rb +0 -475
- data/vendored/puppet/lib/puppet/ssl/certificate_authority/autosign_command.rb +0 -45
- data/vendored/puppet/lib/puppet/ssl/certificate_authority/interface.rb +0 -324
- data/vendored/puppet/lib/puppet/ssl/certificate_factory.rb +0 -219
- data/vendored/puppet/lib/puppet/ssl/certificate_revocation_list.rb +0 -111
- data/vendored/puppet/lib/puppet/ssl/inventory.rb +0 -55
- data/vendored/puppet/lib/puppet/type/cron.rb +0 -480
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'puppet/ssl/base'
|
2
|
-
require 'puppet/indirector'
|
3
|
-
require 'puppet/ssl/certificate_signer'
|
4
|
-
|
5
|
-
# Manage the CRL.
|
6
|
-
class Puppet::SSL::CertificateRevocationList < Puppet::SSL::Base
|
7
|
-
FIVE_YEARS = 5 * 365*24*60*60
|
8
|
-
|
9
|
-
wraps OpenSSL::X509::CRL
|
10
|
-
|
11
|
-
extend Puppet::Indirector
|
12
|
-
indirects :certificate_revocation_list, :terminus_class => :file, :doc => <<DOC
|
13
|
-
This indirection wraps an `OpenSSL::X509::CRL` object, representing a certificate revocation list (CRL).
|
14
|
-
The indirection key is the CA name (usually literally `ca`).
|
15
|
-
DOC
|
16
|
-
|
17
|
-
# Convert a string into an instance.
|
18
|
-
def self.from_s(string)
|
19
|
-
super(string, 'foo') # The name doesn't matter
|
20
|
-
end
|
21
|
-
|
22
|
-
# Because of how the format handler class is included, this
|
23
|
-
# can't be in the base class.
|
24
|
-
def self.supported_formats
|
25
|
-
[:s]
|
26
|
-
end
|
27
|
-
|
28
|
-
# Knows how to create a CRL with our system defaults.
|
29
|
-
def generate(cert, cakey)
|
30
|
-
Puppet.info _("Creating a new certificate revocation list")
|
31
|
-
|
32
|
-
create_crl_issued_by(cert)
|
33
|
-
start_at_initial_crl_number
|
34
|
-
update_valid_time_range_to_start_at(Time.now)
|
35
|
-
sign_with(cakey)
|
36
|
-
|
37
|
-
@content
|
38
|
-
end
|
39
|
-
|
40
|
-
# The name doesn't actually matter; there's only one CRL.
|
41
|
-
# We just need the name so our Indirector stuff all works more easily.
|
42
|
-
def initialize(fakename)
|
43
|
-
@name = "crl"
|
44
|
-
end
|
45
|
-
|
46
|
-
# Revoke the certificate with serial number SERIAL issued by this
|
47
|
-
# CA, then write the CRL back to disk. The REASON must be one of the
|
48
|
-
# OpenSSL::OCSP::REVOKED_* reasons
|
49
|
-
def revoke(serial, cakey, reason = OpenSSL::OCSP::REVOKED_STATUS_KEYCOMPROMISE)
|
50
|
-
Puppet.notice _("Revoked certificate with serial %{serial}") % { serial: serial }
|
51
|
-
time = Time.now
|
52
|
-
|
53
|
-
add_certificate_revocation_for(serial, reason, time)
|
54
|
-
update_to_next_crl_number
|
55
|
-
update_valid_time_range_to_start_at(time)
|
56
|
-
sign_with(cakey)
|
57
|
-
|
58
|
-
Puppet::SSL::CertificateRevocationList.indirection.save(self)
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def create_crl_issued_by(cert)
|
64
|
-
ef = OpenSSL::X509::ExtensionFactory.new(cert)
|
65
|
-
@content = wrapped_class.new
|
66
|
-
@content.issuer = cert.subject
|
67
|
-
@content.add_extension(ef.create_ext("authorityKeyIdentifier", "keyid:always"))
|
68
|
-
@content.version = 1
|
69
|
-
end
|
70
|
-
|
71
|
-
def start_at_initial_crl_number
|
72
|
-
@content.add_extension(crl_number_of(0))
|
73
|
-
end
|
74
|
-
|
75
|
-
def add_certificate_revocation_for(serial, reason, time)
|
76
|
-
revoked = OpenSSL::X509::Revoked.new
|
77
|
-
revoked.serial = serial
|
78
|
-
revoked.time = time
|
79
|
-
enum = OpenSSL::ASN1::Enumerated(reason)
|
80
|
-
ext = OpenSSL::X509::Extension.new("CRLReason", enum)
|
81
|
-
revoked.add_extension(ext)
|
82
|
-
@content.add_revoked(revoked)
|
83
|
-
end
|
84
|
-
|
85
|
-
def update_valid_time_range_to_start_at(time)
|
86
|
-
# The CRL is not valid if the time of checking == the time of last_update.
|
87
|
-
# So to have it valid right now we need to say that it was updated one second ago.
|
88
|
-
@content.last_update = time - 1
|
89
|
-
@content.next_update = time + FIVE_YEARS
|
90
|
-
end
|
91
|
-
|
92
|
-
def update_to_next_crl_number
|
93
|
-
@content.extensions = with_next_crl_number_from(@content.extensions)
|
94
|
-
end
|
95
|
-
|
96
|
-
def with_next_crl_number_from(existing_extensions)
|
97
|
-
existing_crl_num = existing_extensions.find { |e| e.oid == 'crlNumber' }
|
98
|
-
new_crl_num = existing_crl_num ? existing_crl_num.value.to_i + 1 : 0
|
99
|
-
|
100
|
-
extensions_without_crl_num = existing_extensions.reject { |e| e.oid == 'crlNumber' }
|
101
|
-
extensions_without_crl_num + [crl_number_of(new_crl_num)]
|
102
|
-
end
|
103
|
-
|
104
|
-
def crl_number_of(number)
|
105
|
-
OpenSSL::X509::Extension.new('crlNumber', OpenSSL::ASN1::Integer(number))
|
106
|
-
end
|
107
|
-
|
108
|
-
def sign_with(cakey)
|
109
|
-
Puppet::SSL::CertificateSigner.new.sign(@content, cakey)
|
110
|
-
end
|
111
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'puppet/ssl'
|
2
|
-
require 'puppet/ssl/certificate'
|
3
|
-
|
4
|
-
# Keep track of all of our known certificates.
|
5
|
-
class Puppet::SSL::Inventory
|
6
|
-
attr_reader :path
|
7
|
-
|
8
|
-
# Add a certificate to our inventory.
|
9
|
-
def add(cert)
|
10
|
-
cert = cert.content if cert.is_a?(Puppet::SSL::Certificate)
|
11
|
-
# RFC 5280 says the cert subject may contain UTF8 - https://www.ietf.org/rfc/rfc5280.txt
|
12
|
-
# Note however that Puppet generated SSL files must only contain ASCII characters
|
13
|
-
# based on the validate_certname method of Puppet::SSL::Base
|
14
|
-
Puppet.settings.setting(:cert_inventory).open('a:UTF-8') do |f|
|
15
|
-
f.print format(cert)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Format our certificate for output.
|
20
|
-
def format(cert)
|
21
|
-
iso = '%Y-%m-%dT%H:%M:%S%Z'
|
22
|
-
"0x%04x %s %s %s\n" % [cert.serial, cert.not_before.strftime(iso), cert.not_after.strftime(iso), cert.subject]
|
23
|
-
end
|
24
|
-
|
25
|
-
def initialize
|
26
|
-
@path = Puppet[:cert_inventory]
|
27
|
-
end
|
28
|
-
|
29
|
-
# Rebuild the inventory from scratch. This should happen if
|
30
|
-
# the file is entirely missing or if it's somehow corrupted.
|
31
|
-
def rebuild
|
32
|
-
Puppet.notice _("Rebuilding inventory file")
|
33
|
-
|
34
|
-
# RFC 5280 says the cert subject may contain UTF8 - https://www.ietf.org/rfc/rfc5280.txt
|
35
|
-
Puppet.settings.setting(:cert_inventory).open('w:UTF-8') do |f|
|
36
|
-
Puppet::SSL::Certificate.indirection.search("*").each do |cert|
|
37
|
-
f.print format(cert.content)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Find all serial numbers for a given certificate. If none can be found, returns
|
43
|
-
# an empty array.
|
44
|
-
def serials(name)
|
45
|
-
return [] unless Puppet::FileSystem.exist?(@path)
|
46
|
-
|
47
|
-
# RFC 5280 says the cert subject may contain UTF8 - https://www.ietf.org/rfc/rfc5280.txt
|
48
|
-
# Note however that Puppet generated SSL files must only contain ASCII characters
|
49
|
-
# based on the validate_certname method of Puppet::SSL::Base
|
50
|
-
File.readlines(@path, :encoding => Encoding::UTF_8).collect do |line|
|
51
|
-
/^(\S+).+\/CN=#{name}$/.match(line)
|
52
|
-
end.compact.map { |m| Integer(m[1]) }
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
@@ -1,480 +0,0 @@
|
|
1
|
-
require 'etc'
|
2
|
-
require 'facter'
|
3
|
-
require 'puppet/util/filetype'
|
4
|
-
|
5
|
-
Puppet::Type.newtype(:cron) do
|
6
|
-
@doc = <<-'EOT'
|
7
|
-
Installs and manages cron jobs. Every cron resource created by Puppet
|
8
|
-
requires a command and at least one periodic attribute (hour, minute,
|
9
|
-
month, monthday, weekday, or special). While the name of the cron job is
|
10
|
-
not part of the actual job, the name is stored in a comment beginning with
|
11
|
-
`# Puppet Name: `. These comments are used to match crontab entries created
|
12
|
-
by Puppet with cron resources.
|
13
|
-
|
14
|
-
If an existing crontab entry happens to match the scheduling and command of a
|
15
|
-
cron resource that has never been synced, Puppet will defer to the existing
|
16
|
-
crontab entry and will not create a new entry tagged with the `# Puppet Name: `
|
17
|
-
comment.
|
18
|
-
|
19
|
-
Example:
|
20
|
-
|
21
|
-
cron { 'logrotate':
|
22
|
-
command => '/usr/sbin/logrotate',
|
23
|
-
user => 'root',
|
24
|
-
hour => 2,
|
25
|
-
minute => 0,
|
26
|
-
}
|
27
|
-
|
28
|
-
Note that all periodic attributes can be specified as an array of values:
|
29
|
-
|
30
|
-
cron { 'logrotate':
|
31
|
-
command => '/usr/sbin/logrotate',
|
32
|
-
user => 'root',
|
33
|
-
hour => [2, 4],
|
34
|
-
}
|
35
|
-
|
36
|
-
...or using ranges or the step syntax `*/2` (although there's no guarantee
|
37
|
-
that your `cron` daemon supports these):
|
38
|
-
|
39
|
-
cron { 'logrotate':
|
40
|
-
command => '/usr/sbin/logrotate',
|
41
|
-
user => 'root',
|
42
|
-
hour => ['2-4'],
|
43
|
-
minute => '*/10',
|
44
|
-
}
|
45
|
-
|
46
|
-
An important note: _the Cron type will not reset parameters that are
|
47
|
-
removed from a manifest_. For example, removing a `minute => 10` parameter
|
48
|
-
will not reset the minute component of the associated cronjob to `*`.
|
49
|
-
These changes must be expressed by setting the parameter to
|
50
|
-
`minute => absent` because Puppet only manages parameters that are out of
|
51
|
-
sync with manifest entries.
|
52
|
-
|
53
|
-
**Autorequires:** If Puppet is managing the user account specified by the
|
54
|
-
`user` property of a cron resource, then the cron resource will autorequire
|
55
|
-
that user.
|
56
|
-
EOT
|
57
|
-
ensurable
|
58
|
-
|
59
|
-
# A base class for all of the Cron parameters, since they all have
|
60
|
-
# similar argument checking going on.
|
61
|
-
class CronParam < Puppet::Property
|
62
|
-
class << self
|
63
|
-
attr_accessor :boundaries, :default
|
64
|
-
end
|
65
|
-
|
66
|
-
# We have to override the parent method, because we consume the entire
|
67
|
-
# "should" array
|
68
|
-
def insync?(is)
|
69
|
-
self.is_to_s(is) == self.should_to_s
|
70
|
-
end
|
71
|
-
|
72
|
-
# A method used to do parameter input handling. Converts integers
|
73
|
-
# in string form to actual integers, and returns the value if it's
|
74
|
-
# an integer or false if it's just a normal string.
|
75
|
-
def numfix(num)
|
76
|
-
if num =~ /^\d+$/
|
77
|
-
return num.to_i
|
78
|
-
elsif num.is_a?(Integer)
|
79
|
-
return num
|
80
|
-
else
|
81
|
-
return false
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Verify that a number is within the specified limits. Return the
|
86
|
-
# number if it is, or false if it is not.
|
87
|
-
def limitcheck(num, lower, upper)
|
88
|
-
(num >= lower and num <= upper) && num
|
89
|
-
end
|
90
|
-
|
91
|
-
# Verify that a value falls within the specified array. Does case
|
92
|
-
# insensitive matching, and supports matching either the entire word
|
93
|
-
# or the first three letters of the word.
|
94
|
-
def alphacheck(value, ary)
|
95
|
-
tmp = value.downcase
|
96
|
-
|
97
|
-
# If they specified a shortened version of the name, then see
|
98
|
-
# if we can lengthen it (e.g., mon => monday).
|
99
|
-
if tmp.length == 3
|
100
|
-
ary.each_with_index { |name, index|
|
101
|
-
if tmp.upcase == name[0..2].upcase
|
102
|
-
return index
|
103
|
-
end
|
104
|
-
}
|
105
|
-
else
|
106
|
-
return ary.index(tmp) if ary.include?(tmp)
|
107
|
-
end
|
108
|
-
|
109
|
-
false
|
110
|
-
end
|
111
|
-
|
112
|
-
def should_to_s(value = @should)
|
113
|
-
if value
|
114
|
-
if value.is_a?(Array) && (name == :command || value[0].is_a?(Symbol))
|
115
|
-
value = value[0]
|
116
|
-
end
|
117
|
-
super(value)
|
118
|
-
else
|
119
|
-
nil
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def is_to_s(value = @is)
|
124
|
-
if value
|
125
|
-
if value.is_a?(Array) && (name == :command || value[0].is_a?(Symbol))
|
126
|
-
value = value[0]
|
127
|
-
end
|
128
|
-
super(value)
|
129
|
-
else
|
130
|
-
nil
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def should
|
135
|
-
if @should and @should[0] == :absent
|
136
|
-
:absent
|
137
|
-
else
|
138
|
-
@should
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def should=(ary)
|
143
|
-
super
|
144
|
-
@should.flatten!
|
145
|
-
end
|
146
|
-
|
147
|
-
# The method that does all of the actual parameter value
|
148
|
-
# checking; called by all of the +param<name>=+ methods.
|
149
|
-
# Requires the value, type, and bounds, and optionally supports
|
150
|
-
# a boolean of whether to do alpha checking, and if so requires
|
151
|
-
# the ary against which to do the checking.
|
152
|
-
munge do |value|
|
153
|
-
# Support 'absent' as a value, so that they can remove
|
154
|
-
# a value
|
155
|
-
if value == "absent" or value == :absent
|
156
|
-
return :absent
|
157
|
-
end
|
158
|
-
|
159
|
-
# Allow the */2 syntax
|
160
|
-
if value =~ /^\*\/[0-9]+$/
|
161
|
-
return value
|
162
|
-
end
|
163
|
-
|
164
|
-
# Allow ranges
|
165
|
-
if value =~ /^[0-9]+-[0-9]+$/
|
166
|
-
return value
|
167
|
-
end
|
168
|
-
|
169
|
-
# Allow ranges + */2
|
170
|
-
if value =~ /^[0-9]+-[0-9]+\/[0-9]+$/
|
171
|
-
return value
|
172
|
-
end
|
173
|
-
|
174
|
-
if value == "*"
|
175
|
-
return :absent
|
176
|
-
end
|
177
|
-
|
178
|
-
return value unless self.class.boundaries
|
179
|
-
lower, upper = self.class.boundaries
|
180
|
-
retval = nil
|
181
|
-
if num = numfix(value)
|
182
|
-
retval = limitcheck(num, lower, upper)
|
183
|
-
elsif respond_to?(:alpha)
|
184
|
-
# If it has an alpha method defined, then we check
|
185
|
-
# to see if our value is in that list and if so we turn
|
186
|
-
# it into a number
|
187
|
-
retval = alphacheck(value, alpha)
|
188
|
-
end
|
189
|
-
|
190
|
-
if retval
|
191
|
-
return retval.to_s
|
192
|
-
else
|
193
|
-
self.fail _("%{value} is not a valid %{name}") % { value: value, name: self.class.name }
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
# Somewhat uniquely, this property does not actually change anything -- it
|
199
|
-
# just calls +@resource.sync+, which writes out the whole cron tab for
|
200
|
-
# the user in question. There is no real way to change individual cron
|
201
|
-
# jobs without rewriting the entire cron file.
|
202
|
-
#
|
203
|
-
# Note that this means that managing many cron jobs for a given user
|
204
|
-
# could currently result in multiple write sessions for that user.
|
205
|
-
newproperty(:command, :parent => CronParam) do
|
206
|
-
desc "The command to execute in the cron job. The environment
|
207
|
-
provided to the command varies by local system rules, and it is
|
208
|
-
best to always provide a fully qualified command. The user's
|
209
|
-
profile is not sourced when the command is run, so if the
|
210
|
-
user's environment is desired it should be sourced manually.
|
211
|
-
|
212
|
-
All cron parameters support `absent` as a value; this will
|
213
|
-
remove any existing values for that field."
|
214
|
-
|
215
|
-
def retrieve
|
216
|
-
return_value = super
|
217
|
-
return_value = return_value[0] if return_value && return_value.is_a?(Array)
|
218
|
-
|
219
|
-
return_value
|
220
|
-
end
|
221
|
-
|
222
|
-
def should
|
223
|
-
if @should
|
224
|
-
if @should.is_a? Array
|
225
|
-
@should[0]
|
226
|
-
else
|
227
|
-
devfail "command is not an array"
|
228
|
-
end
|
229
|
-
else
|
230
|
-
nil
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
def munge(value)
|
235
|
-
value.strip
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
newproperty(:special) do
|
240
|
-
desc "A special value such as 'reboot' or 'annually'.
|
241
|
-
Only available on supported systems such as Vixie Cron.
|
242
|
-
Overrides more specific time of day/week settings.
|
243
|
-
Set to 'absent' to make puppet revert to a plain numeric schedule."
|
244
|
-
|
245
|
-
def specials
|
246
|
-
%w{reboot yearly annually monthly weekly daily midnight hourly absent} +
|
247
|
-
[ :absent ]
|
248
|
-
end
|
249
|
-
|
250
|
-
validate do |value|
|
251
|
-
raise ArgumentError, _("Invalid special schedule %{value}") % { value: value.inspect } unless specials.include?(value)
|
252
|
-
end
|
253
|
-
|
254
|
-
def munge(value)
|
255
|
-
# Support value absent so that a schedule can be
|
256
|
-
# forced to change to numeric.
|
257
|
-
if value == "absent" or value == :absent
|
258
|
-
return :absent
|
259
|
-
end
|
260
|
-
value
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
newproperty(:minute, :parent => CronParam) do
|
265
|
-
self.boundaries = [0, 59]
|
266
|
-
desc "The minute at which to run the cron job.
|
267
|
-
Optional; if specified, must be between 0 and 59, inclusive."
|
268
|
-
end
|
269
|
-
|
270
|
-
newproperty(:hour, :parent => CronParam) do
|
271
|
-
self.boundaries = [0, 23]
|
272
|
-
desc "The hour at which to run the cron job. Optional;
|
273
|
-
if specified, must be between 0 and 23, inclusive."
|
274
|
-
end
|
275
|
-
|
276
|
-
newproperty(:weekday, :parent => CronParam) do
|
277
|
-
def alpha
|
278
|
-
%w{sunday monday tuesday wednesday thursday friday saturday}
|
279
|
-
end
|
280
|
-
self.boundaries = [0, 7]
|
281
|
-
desc "The weekday on which to run the command. Optional; if specified,
|
282
|
-
must be either:
|
283
|
-
|
284
|
-
- A number between 0 and 7, inclusive, with 0 or 7 being Sunday
|
285
|
-
- The name of the day, such as 'Tuesday'."
|
286
|
-
end
|
287
|
-
|
288
|
-
newproperty(:month, :parent => CronParam) do
|
289
|
-
def alpha
|
290
|
-
# The ___placeholder accounts for the fact that month is unique among
|
291
|
-
# "nameable" crontab entries in that it does not use 0-based indexing.
|
292
|
-
# Padding the array with a placeholder introduces the appropriate shift
|
293
|
-
# in indices.
|
294
|
-
%w{___placeholder january february march april may june july
|
295
|
-
august september october november december}
|
296
|
-
end
|
297
|
-
self.boundaries = [1, 12]
|
298
|
-
desc "The month of the year. Optional; if specified,
|
299
|
-
must be either:
|
300
|
-
|
301
|
-
- A number between 1 and 12, inclusive, with 1 being January
|
302
|
-
- The name of the month, such as 'December'."
|
303
|
-
end
|
304
|
-
|
305
|
-
newproperty(:monthday, :parent => CronParam) do
|
306
|
-
self.boundaries = [1, 31]
|
307
|
-
desc "The day of the month on which to run the
|
308
|
-
command. Optional; if specified, must be between 1 and 31."
|
309
|
-
end
|
310
|
-
|
311
|
-
newproperty(:environment) do
|
312
|
-
desc "Any environment settings associated with this cron job. They
|
313
|
-
will be stored between the header and the job in the crontab. There
|
314
|
-
can be no guarantees that other, earlier settings will not also
|
315
|
-
affect a given cron job.
|
316
|
-
|
317
|
-
|
318
|
-
Also, Puppet cannot automatically determine whether an existing,
|
319
|
-
unmanaged environment setting is associated with a given cron
|
320
|
-
job. If you already have cron jobs with environment settings,
|
321
|
-
then Puppet will keep those settings in the same place in the file,
|
322
|
-
but will not associate them with a specific job.
|
323
|
-
|
324
|
-
Settings should be specified exactly as they should appear in
|
325
|
-
the crontab, like `PATH=/bin:/usr/bin:/usr/sbin`."
|
326
|
-
|
327
|
-
validate do |value|
|
328
|
-
unless value =~ /^\s*(\w+)\s*=\s*(.*)\s*$/ or value == :absent or value == "absent"
|
329
|
-
raise ArgumentError, _("Invalid environment setting %{value}") % { value: value.inspect }
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
def insync?(is)
|
334
|
-
if is.is_a? Array
|
335
|
-
return is.sort == @should.sort
|
336
|
-
else
|
337
|
-
return is == @should
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
def should
|
342
|
-
@should
|
343
|
-
end
|
344
|
-
|
345
|
-
def should_to_s(newvalue = @should)
|
346
|
-
if newvalue
|
347
|
-
newvalue.join(",")
|
348
|
-
else
|
349
|
-
nil
|
350
|
-
end
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
newparam(:name) do
|
355
|
-
desc "The symbolic name of the cron job. This name
|
356
|
-
is used for human reference only and is generated automatically
|
357
|
-
for cron jobs found on the system. This generally won't
|
358
|
-
matter, as Puppet will do its best to match existing cron jobs
|
359
|
-
against specified jobs (and Puppet adds a comment to cron jobs it adds),
|
360
|
-
but it is at least possible that converting from unmanaged jobs to
|
361
|
-
managed jobs might require manual intervention."
|
362
|
-
|
363
|
-
isnamevar
|
364
|
-
end
|
365
|
-
|
366
|
-
newproperty(:user) do
|
367
|
-
desc "The user who owns the cron job. This user must
|
368
|
-
be allowed to run cron jobs, which is not currently checked by
|
369
|
-
Puppet.
|
370
|
-
|
371
|
-
This property defaults to the user running Puppet or `root`.
|
372
|
-
|
373
|
-
The default crontab provider executes the system `crontab` using
|
374
|
-
the user account specified by this property."
|
375
|
-
|
376
|
-
defaultto {
|
377
|
-
if not provider.is_a?(@resource.class.provider(:crontab))
|
378
|
-
struct = Etc.getpwuid(Process.uid)
|
379
|
-
struct.respond_to?(:name) && struct.name or 'root'
|
380
|
-
end
|
381
|
-
}
|
382
|
-
end
|
383
|
-
|
384
|
-
# Autorequire the owner of the crontab entry.
|
385
|
-
autorequire(:user) do
|
386
|
-
self[:user]
|
387
|
-
end
|
388
|
-
|
389
|
-
newproperty(:target) do
|
390
|
-
desc "The name of the crontab file in which the cron job should be stored.
|
391
|
-
|
392
|
-
This property defaults to the value of the `user` property if set, the
|
393
|
-
user running Puppet or `root`.
|
394
|
-
|
395
|
-
For the default crontab provider, this property is functionally
|
396
|
-
equivalent to the `user` property and should be avoided. In particular,
|
397
|
-
setting both `user` and `target` to different values will result in
|
398
|
-
undefined behavior."
|
399
|
-
|
400
|
-
defaultto {
|
401
|
-
if provider.is_a?(@resource.class.provider(:crontab))
|
402
|
-
if val = @resource.should(:user)
|
403
|
-
val
|
404
|
-
else
|
405
|
-
struct = Etc.getpwuid(Process.uid)
|
406
|
-
struct.respond_to?(:name) && struct.name or 'root'
|
407
|
-
end
|
408
|
-
elsif provider.class.ancestors.include?(Puppet::Provider::ParsedFile)
|
409
|
-
provider.class.default_target
|
410
|
-
else
|
411
|
-
nil
|
412
|
-
end
|
413
|
-
}
|
414
|
-
end
|
415
|
-
|
416
|
-
validate do
|
417
|
-
return true unless self[:special]
|
418
|
-
return true if self[:special] == :absent
|
419
|
-
# there is a special schedule in @should, so we don't want to see
|
420
|
-
# any numeric should values
|
421
|
-
[ :minute, :hour, :weekday, :monthday, :month ].each do |field|
|
422
|
-
next unless self[field]
|
423
|
-
next if self[field] == :absent
|
424
|
-
raise ArgumentError, _("%{cron} cannot specify both a special schedule and a value for %{field}") % { cron: self.ref, field: field }
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
# We have to reorder things so that :provide is before :target
|
429
|
-
|
430
|
-
attr_accessor :uid
|
431
|
-
|
432
|
-
# Marks the resource as "being purged".
|
433
|
-
#
|
434
|
-
# @api public
|
435
|
-
#
|
436
|
-
# @note This overrides the Puppet::Type method in order to handle
|
437
|
-
# an edge case that has so far been observed during testing only.
|
438
|
-
# Without forcing the should-value for the user property to be
|
439
|
-
# identical to the original cron file, purging from a fixture
|
440
|
-
# will not work, because the user property defaults to the user
|
441
|
-
# running the test. It is not clear whether this scenario can apply
|
442
|
-
# during normal operation.
|
443
|
-
#
|
444
|
-
# @note Also, when not forcing the should-value for the target
|
445
|
-
# property, unpurged file content (such as comments) can end up
|
446
|
-
# being written to the default target (i.e. the current login name).
|
447
|
-
def purging
|
448
|
-
self[:target] = provider.target
|
449
|
-
self[:user] = provider.target
|
450
|
-
super
|
451
|
-
end
|
452
|
-
|
453
|
-
def value(name)
|
454
|
-
name = name.intern
|
455
|
-
ret = nil
|
456
|
-
if obj = @parameters[name]
|
457
|
-
ret = obj.should
|
458
|
-
|
459
|
-
ret ||= obj.retrieve
|
460
|
-
|
461
|
-
if ret == :absent
|
462
|
-
ret = nil
|
463
|
-
end
|
464
|
-
end
|
465
|
-
|
466
|
-
unless ret
|
467
|
-
case name
|
468
|
-
when :command
|
469
|
-
when :special
|
470
|
-
# nothing
|
471
|
-
else
|
472
|
-
#ret = (self.class.validproperty?(name).default || "*").to_s
|
473
|
-
ret = "*"
|
474
|
-
end
|
475
|
-
end
|
476
|
-
|
477
|
-
ret
|
478
|
-
end
|
479
|
-
end
|
480
|
-
|