Andreas Dvorak
2013-Sep-04 07:07 UTC
[Puppet Users] run module although with time condition, but also possibilty execute even so not in that time frame
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? Best regards, Andreas -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Sep-04 13:35 UTC
[Puppet Users] Re: run module although with time condition, but also possibilty execute even so not in that time frame
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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Andreas Dvorak
2013-Sep-06 05:08 UTC
[Puppet Users] Re: run module although with time condition, but also possibilty execute even so not in that time frame
Hi John, many thanks for this full description. After my holiday next week I will try to set this up. Best regards, Andreas -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Andreas Dvorak
2013-Sep-13 10:16 UTC
[Puppet Users] Re: run module although with time condition, but also possibilty execute even so not in that time frame
Hi, now I have used the "schedule" successfully. But I don''t understand the method to override the schedule completely. Is it true that I have to change vom node.pp file from node ''vm6741.muc.baag'' inherits base { $motd_function = "Puppet Agent" $motd_environment = "Test" $motd_description = "RedHat 5 Test" include motd *include copy_file* } to node ''vm6741.muc.baag'' inherits base { $motd_function = "Puppet Agent" $motd_environment = "Test" $motd_description = "RedHat 5 Test" include motd *include copy_file::now* } That would not be nice because I need to change a file. There is no option to run the puppet agent like this: puppet agent --class copy_file::now or puppet agent --ignore_schedule Best regards Andreas -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Sep-13 14:07 UTC
[Puppet Users] Re: run module although with time condition, but also possibilty execute even so not in that time frame
On Friday, September 13, 2013 5:16:06 AM UTC-5, Andreas Dvorak wrote:> > Hi, > > now I have used the "schedule" successfully. > But I don''t understand the method to override the schedule completely. Is > it true that I have to change vom node.pp file from > node ''vm6741.muc.baag'' inherits base { > $motd_function = "Puppet Agent" > $motd_environment = "Test" > $motd_description = "RedHat 5 Test" > include motd > *include copy_file* > } > > to > node ''vm6741.muc.baag'' inherits base { > $motd_function = "Puppet Agent" > $motd_environment = "Test" > $motd_description = "RedHat 5 Test" > include motd > *include copy_file::now* > } > > That would not be nice because I need to change a file. >There is a variety of ways to do what you ask. Some involve tags, some involve facts, and a few involve agent command-line options. For example, you could leverage Facter''s environment-defined facts or stdlib''s fact.d/ facts to communicate to the master via a fact that you want to override the schedule, then use a conditional statement based on the fact value to control whather class copy_file::now is included. Alternatively, you could flip the places of classes copy_file and copy_file::now to give you copy_file::scheduled and copy_file, so that the base class does not declare a schedule, but the subclass overrides it to do. Declare class copy_file::scheduled. I think then you can override the schedule from the command line like so: puppet agent --tags ''copy_file'' That should select the copy_file class but NOT the copy_file::sheduled class that adds a schedule to it.> > There is no option to run the puppet agent like this: > puppet agent --class copy_file::now > or > puppet agent --ignore_schedule > >Or there''s that, provided you spell it correctly: puppet agent --ignoreschedules (http://docs.puppetlabs.com/references/latest/configuration.html#ignoreschedules). With that you should be able to forget about subclassing altogether, but do be aware that it will override ALL schedules. If that turns out to be an issue then you could narrow the parts of your configuration to apply to those bearing particular tags, maybe puppet agent --ignoreschedules --tags copy_file 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Andreas Dvorak
2013-Sep-13 15:05 UTC
[Puppet Users] Re: run module although with time condition, but also possibilty execute even so not in that time frame
Great John, the command puppet agent --ignoreschedules --tags copy_file is working and exactly what I need. Thank you very much. Andreas -- 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.