On Wednesday, September 4, 2013 2:07:07 AM UTC-5, Andreas Dvorak wrote:
>
> Hi,
>
> I need an idea to write modules that have a time condition, so software
> should only be installed between 1 and 2 o'clock.
> But in special situations I need to run the software installation right
> now and can not wait for the time frame.
>
> Here is my idea for the time frame condition. Is that a good method?
> if "$timestamp" > "01:00:00" && "$timestamp" < "02:00:00" {
> # exec resource
> }
>
> In cfengine I can define time conditions with (run in hour 1
> Hr01::
> # exec resource
> I did not find anything like this in puppet.
>
> And then I could do in cfengine (run in hour 1 or if agent is call with
> the condition go
> Hr01|go::
> # exec resource
> Is there something like this in puppet?
>
>
Puppet has a built-in mechanism for specifying limited windows in which
particular resources can be applied: schedules (see
http://docs.puppetlabs.com/references/3.2.latest/type.html#schedule). So,
you might write something like this:
modules/mymodule/manifests/init.pp:
----
class mymodule {
schedule { 'mymodule-schedule':
range => "01:00:00 - 01:59:59"
}
# or any other resource(s), including of defined types
package { 'mypackage':
endure => 'latest',
schedule => 'mymodule-schedule'
}
}
If you declare that class for the target node, then the resources having
schedule 'mymodule-schedule' will be applied only during the times
specified in that schedule, so that addresses the first part of the problem.
As to how to override the schedule at need, there are multiple approaches,
but all of them revolve around either changing the schedule to allow the
access or changing the resources so that the schedule does not apply to
them. For example, you might define a parameter to your 'mymodule' class
that allows you to override the schedule's 'range' or prevent the schedule
from being assigned to resources. Alternatively, you could override the
schedule or other resource properties via a subclass or a collector.
Here's an example. It's a bit old school, but I like the idea of a
completely canned approach to such a specific ability as the one you want
to make provision for:
modules/mymodule/manifests/now.pp
----
class mymodule::now inherits mymodule {
# override the schedule to allow application
# any time:
Schedule['mymodule-schedule'] {
range => '00:00:00 - 23:59:59'
}
}
If you declare class 'mymodule::now' on a target node, either instead of or
in addition to class 'mymodule', then everything declared by class
'mymodule' will be applied, regardless of the time of day.
John
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.