Ace
2011-Jan-03 21:51 UTC
[Puppet Users] Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
I want to manage cronjobs as a " file " in solaris through puppet and not using the puppet cron resource. I will be managing the file /var/spool/cron/crontabs/root. I want the cron file to be same across all servers except some servers will have additional cron entries. How can I append to the file /var/spool/cron/crontabs/root , something like appendifnosuchline in cfengine? Can "appendifnosuchline" be implemented through puppet even through the file /var/spool/cron/crontabs/root is being managed through puppet? Thanks, Ace -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Alan Barrett
2011-Jan-04 08:08 UTC
Re: [Puppet Users] Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
On Mon, 03 Jan 2011, Ace wrote:> I will be managing the file /var/spool/cron/crontabs/root. > > I want the cron file to be same across all servers except some servers > will have additional cron entries.Since you want to avoid the puppet "cron" type, I''d suggest using the "concat" module from <https://github.com/ripienaar/puppet-concat>.> How can I append to the file /var/spool/cron/crontabs/root , something > like appendifnosuchline in cfengine?You could probably use augeas for that, if you try hard enough, but I recommend concat. Some of the comments at <http://www.devco.net/archives/2010/02/19/building_files_from_fragments_with_puppet.php> discuss tradeoffs between concat and augeas. --apb (Alan Barrett) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Felix Frank
2011-Jan-04 09:02 UTC
Re: [Puppet Users] Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
On 01/03/2011 10:51 PM, Ace wrote:> I want to manage cronjobs as a " file " in solaris through puppet and > not using the puppet cron resource. > > I will be managing the file /var/spool/cron/crontabs/root. > > I want the cron file to be same across all servers except some servers > will have additional cron entries. > > How can I append to the file /var/spool/cron/crontabs/root , something > like appendifnosuchline in cfengine? > > Can "appendifnosuchline" be implemented through puppet even through > the file /var/spool/cron/crontabs/root is being managed through > puppet?I think not. Usually, this is approached in either of two ways: 1. You create a template and there are facts or variables that control where your exceptions are included. 2. You create different versions of your crontab. Your manifests select sources using variables and if/else- or case-constructs, or using class inheritance (which is often more elegant). There may be more approaches still. HTH, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Rene Cunningham
2011-Jan-04 10:56 UTC
Re: [Puppet Users] Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
On Tue, Jan 4, 2011 at 8:02 PM, Felix Frank <felix.frank@alumni.tu-berlin.de> wrote:> On 01/03/2011 10:51 PM, Ace wrote: > > I want to manage cronjobs as a " file " in solaris through puppet and > > not using the puppet cron resource. > > > > I will be managing the file /var/spool/cron/crontabs/root. > > > > I want the cron file to be same across all servers except some servers > > will have additional cron entries. > > > > How can I append to the file /var/spool/cron/crontabs/root , something > > like appendifnosuchline in cfengine? > > > > Can "appendifnosuchline" be implemented through puppet even through > > the file /var/spool/cron/crontabs/root is being managed through > > puppet? > > I think not. Usually, this is approached in either of two ways: > > 1. You create a template and there are facts or variables that control > where your exceptions are included. > 2. You create different versions of your crontab. Your manifests select > sources using variables and if/else- or case-constructs, or using class > inheritance (which is often more elegant). > > There may be more approaches still. >Ive recently started using the method described below which is working well so far. It may not be able to work with the ''appendifnosuchline'' approach. http://linuxman.wikispaces.com/Creating+a+cron+job+with+puppet -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Felix Frank
2011-Jan-04 11:12 UTC
Re: [Puppet Users] Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
> Ive recently started using the method described below which is working > well so far. It may not be able to work with the ''appendifnosuchline'' > approach. > > http://linuxman.wikispaces.com/Creating+a+cron+job+with+puppetHmm, interesting. Have you considered using the ubiquitous file concat mechanism? (I forget the download link, sorry). I''ve got to add: Your assumption that "you can''t really have puppet-managed and non-puppet-managed jobs in the same crontab" is just not true. You are usually *not* supposed to managed crontabs as files (except the cron provider is broken on your platform, as in Ace''s case). Cheers, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Nigel Kersten
2011-Jan-04 16:04 UTC
Re: [Puppet Users] Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
On Mon, Jan 3, 2011 at 1:51 PM, Ace <tejas.zzz@gmail.com> wrote:> I want to manage cronjobs as a " file " in solaris through puppet and > not using the puppet cron resource. > > I will be managing the file /var/spool/cron/crontabs/root. > > I want the cron file to be same across all servers except some servers > will have additional cron entries. > > How can I append to the file /var/spool/cron/crontabs/root , something > like appendifnosuchline in cfengine? > > Can "appendifnosuchline" be implemented through puppet even through > the file /var/spool/cron/crontabs/root is being managed through > puppet? >There are a bunch of recipes around where people construct an Exec with an onlyif/unless conditional to achieve this. Here''s something I just whipped up that looks to work ok. define appendifnosuchline($file="", $line="") { exec { "appendline_${file}_${line}": path => "/bin:/usr/bin", command => "echo ${text} >> ${line}", unless => "grep -qx ${text} ${line}", } } appendifnosuchline { "ensure_foobar_in_filetest": file => "/tmp/filetest", line => "foobar", } You could do something trickier with composite namevars, but this works. You don''t want to do this and manage the *contents* of the file with Puppet. You''ll get changes on every run then. You can however manage the attributes of the file, and could require the given File resource when using the defined type so that those settings are always applied first.> > Thanks, > Ace > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ace
2011-Jan-05 16:27 UTC
[Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
Yep I have tried the code below and I got changes everytime I ran it. Could you elaborate on the below lines that you mentioned. Thanks. I will also try the concat method. You can however manage the attributes of the file, and could require the given File resource when using the defined type so that those settings are always applied first. On Jan 4, 11:04 am, Nigel Kersten <ni...@puppetlabs.com> wrote:> On Mon, Jan 3, 2011 at 1:51 PM, Ace <tejas....@gmail.com> wrote: > > I want to manage cronjobs as a " file " in solaris through puppet and > > not using the puppet cron resource. > > > I will be managing the file /var/spool/cron/crontabs/root. > > > I want the cron file to be same across all servers except some servers > > will have additional cron entries. > > > How can I append to the file /var/spool/cron/crontabs/root , something > > like appendifnosuchline in cfengine? > > > Can "appendifnosuchline" be implemented through puppet even through > > the file /var/spool/cron/crontabs/root is being managed through > > puppet? > > There are a bunch of recipes around where people construct an Exec with an > onlyif/unless conditional to achieve this. > > Here''s something I just whipped up that looks to work ok. > > define appendifnosuchline($file="", $line="") { > exec { "appendline_${file}_${line}": > path => "/bin:/usr/bin", > command => "echo ${text} >> ${line}", > unless => "grep -qx ${text} ${line}", > } > > } > > appendifnosuchline { "ensure_foobar_in_filetest": > file => "/tmp/filetest", > line => "foobar", > > } > > You could do something trickier with composite namevars, but this works. > > You don''t want to do this and manage the *contents* of the file with Puppet. > You''ll get changes on every run then. > > You can however manage the attributes of the file, and could require the > given File resource when using the defined type so that those settings are > always applied first. > > > > > Thanks, > > Ace > > > -- > > You received this message because you are subscribed to the Google Groups > > "Puppet Users" group. > > To post to this group, send email to puppet-users@googlegroups.com. > > To unsubscribe from this group, send email to > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ace
2011-Jan-05 16:45 UTC
[Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
Is there something simpler than the concat module ? Is there a way to control which classes/modules execute first in puppet to make the code mentioned by Nigel work? On Jan 4, 3:08 am, Alan Barrett <a...@cequrux.com> wrote:> On Mon, 03 Jan 2011, Ace wrote: > > I will be managing the file /var/spool/cron/crontabs/root. > > > I want the cron file to be same across all servers except some servers > > will have additional cron entries. > > Since you want to avoid the puppet "cron" type, I''d suggest using the > "concat" module from <https://github.com/ripienaar/puppet-concat>. > > > How can I append to the file /var/spool/cron/crontabs/root , something > > like appendifnosuchline in cfengine? > > You could probably use augeas for that, if you try hard > enough, but I recommend concat. Some of the comments at > <http://www.devco.net/archives/2010/02/19/building_files_from_fragment...> > discuss tradeoffs between concat and augeas. > > --apb (Alan Barrett)-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ace
2011-Jan-05 16:45 UTC
[Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
Is there something simpler than the concat module ? Is there a way to control which classes/modules execute first in puppet to make the code mentioned by Nigel work? On Jan 4, 3:08 am, Alan Barrett <a...@cequrux.com> wrote:> On Mon, 03 Jan 2011, Ace wrote: > > I will be managing the file /var/spool/cron/crontabs/root. > > > I want the cron file to be same across all servers except some servers > > will have additional cron entries. > > Since you want to avoid the puppet "cron" type, I''d suggest using the > "concat" module from <https://github.com/ripienaar/puppet-concat>. > > > How can I append to the file /var/spool/cron/crontabs/root , something > > like appendifnosuchline in cfengine? > > You could probably use augeas for that, if you try hard > enough, but I recommend concat. Some of the comments at > <http://www.devco.net/archives/2010/02/19/building_files_from_fragment...> > discuss tradeoffs between concat and augeas. > > --apb (Alan Barrett)-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Nigel Kersten
2011-Jan-05 18:22 UTC
Re: [Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
On Wed, Jan 5, 2011 at 8:27 AM, Ace <tejas.zzz@gmail.com> wrote:> Yep I have tried the code below and I got changes everytime I ran it. > Could you elaborate on the below lines that you mentioned. Thanks. > I will also try the concat method. >That would be because I gave you an entirely broken example :) define appendifnosuchline($file="", $line="") { exec { "appendline_${file}_${line}": path => "/bin:/usr/bin", command => "/bin/echo ${line} >> ${file}", unless => "grep -qx ${line} ${file}", } } appendifnosuchline { "ensure_foobar_in_filetest": file => "/tmp/filetest", line => "foobar", } That looks to work.> > You can however manage the attributes of the file, and could require > the > given File resource when using the defined type so that those settings > are > always applied first. > > > > > > > > On Jan 4, 11:04 am, Nigel Kersten <ni...@puppetlabs.com> wrote: > > On Mon, Jan 3, 2011 at 1:51 PM, Ace <tejas....@gmail.com> wrote: > > > I want to manage cronjobs as a " file " in solaris through puppet and > > > not using the puppet cron resource. > > > > > I will be managing the file /var/spool/cron/crontabs/root. > > > > > I want the cron file to be same across all servers except some servers > > > will have additional cron entries. > > > > > How can I append to the file /var/spool/cron/crontabs/root , something > > > like appendifnosuchline in cfengine? > > > > > Can "appendifnosuchline" be implemented through puppet even through > > > the file /var/spool/cron/crontabs/root is being managed through > > > puppet? > > > > There are a bunch of recipes around where people construct an Exec with > an > > onlyif/unless conditional to achieve this. > > > > Here''s something I just whipped up that looks to work ok. > > > > define appendifnosuchline($file="", $line="") { > > exec { "appendline_${file}_${line}": > > path => "/bin:/usr/bin", > > command => "echo ${text} >> ${line}", > > unless => "grep -qx ${text} ${line}", > > } > > > > } > > > > appendifnosuchline { "ensure_foobar_in_filetest": > > file => "/tmp/filetest", > > line => "foobar", > > > > } > > > > You could do something trickier with composite namevars, but this works. > > > > You don''t want to do this and manage the *contents* of the file with > Puppet. > > You''ll get changes on every run then. > > > > You can however manage the attributes of the file, and could require the > > given File resource when using the defined type so that those settings > are > > always applied first. > > > > > > > > > Thanks, > > > Ace > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Puppet Users" group. > > > To post to this group, send email to puppet-users@googlegroups.com. > > > To unsubscribe from this group, send email to > > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > <puppet-users%2Bunsubscribe@googlegroups.com<puppet-users%252Bunsubscribe@googlegroups.com> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/puppet-users?hl=en. > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ace
2011-Jan-05 20:16 UTC
[Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
Yes this definitely works although it replaces the file and appends the line to it every time it runs. Is there a cleaner way of doing it? tmp/filetest is a file managed by puppet who''s contents are two lines "testme" and "hmm what does this do". The append function appends line "works" everytime it runs. [root@ /]$ cat /tmp/filetest testme hmm what does this do works [root@ /]$ puppetd --test info: Caching catalog for dc116.usatlas.bnl.gov info: Applying configuration version ''1294258209'' --- /tmp/filetest Wed Jan 5 15:12:27 2011 +++ /tmp/puppet-file20110105-13134-1p9lv09-0 Wed Jan 5 15:13:47 2011 @@ -1,3 +1,2 @@ testme hmm what does this do -works info: FileBucket got a duplicate file /tmp/filetest ({md5} a1e1337e26fd34816281fbb48b4db945) info: /Stage[main]/Sys_files_dc116/File[/tmp/filetest]: Filebucketed / tmp/filetest to puppet with sum a1e1337e26fd34816281fbb48b4db945 notice: /Stage[main]/Sys_files_dc116/File[/tmp/filetest]/content: content changed ''{md5}a1e1337e26fd34816281fbb48b4db945'' to ''{md5} fcf03823146b78fb73e8df3c3494ef6d'' notice: /Stage[main]/Append/ Append::Appendifnosuchline[ensure_foobar_in_filetest]/Exec[appendline_/ tmp/filetest_works]/returns: executed successfully notice: Finished catalog run in 6.28 seconds [root@ /]$ cat /tmp/filetest testme hmm what does this do works On Jan 5, 1:22 pm, Nigel Kersten <ni...@puppetlabs.com> wrote:> On Wed, Jan 5, 2011 at 8:27 AM, Ace <tejas....@gmail.com> wrote: > > Yep I have tried the code below and I got changes everytime I ran it. > > Could you elaborate on the below lines that you mentioned. Thanks. > > I will also try the concat method. > > That would be because I gave you an entirely broken example :) > > define appendifnosuchline($file="", $line="") { > exec { "appendline_${file}_${line}": > path => "/bin:/usr/bin", > command => "/bin/echo ${line} >> ${file}", > unless => "grep -qx ${line} ${file}", > } > > } > > appendifnosuchline { "ensure_foobar_in_filetest": > file => "/tmp/filetest", > line => "foobar", > > } > > That looks to work. > > > > > You can however manage the attributes of the file, and could require > > the > > given File resource when using the defined type so that those settings > > are > > always applied first. > > > On Jan 4, 11:04 am, Nigel Kersten <ni...@puppetlabs.com> wrote: > > > On Mon, Jan 3, 2011 at 1:51 PM, Ace <tejas....@gmail.com> wrote: > > > > I want to manage cronjobs as a " file " in solaris through puppet and > > > > not using the puppet cron resource. > > > > > I will be managing the file /var/spool/cron/crontabs/root. > > > > > I want the cron file to be same across all servers except some servers > > > > will have additional cron entries. > > > > > How can I append to the file /var/spool/cron/crontabs/root , something > > > > like appendifnosuchline in cfengine? > > > > > Can "appendifnosuchline" be implemented through puppet even through > > > > the file /var/spool/cron/crontabs/root is being managed through > > > > puppet? > > > > There are a bunch of recipes around where people construct an Exec with > > an > > > onlyif/unless conditional to achieve this. > > > > Here''s something I just whipped up that looks to work ok. > > > > define appendifnosuchline($file="", $line="") { > > > exec { "appendline_${file}_${line}": > > > path => "/bin:/usr/bin", > > > command => "echo ${text} >> ${line}", > > > unless => "grep -qx ${text} ${line}", > > > } > > > > } > > > > appendifnosuchline { "ensure_foobar_in_filetest": > > > file => "/tmp/filetest", > > > line => "foobar", > > > > } > > > > You could do something trickier with composite namevars, but this works. > > > > You don''t want to do this and manage the *contents* of the file with > > Puppet. > > > You''ll get changes on every run then. > > > > You can however manage the attributes of the file, and could require the > > > given File resource when using the defined type so that those settings > > are > > > always applied first. > > > > > Thanks, > > > > Ace > > > > > -- > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Puppet Users" group. > > > > To post to this group, send email to puppet-users@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > > <puppet-users%2Bunsubscribe@googlegroups.com<puppet-users%252Bunsubscribe@googlegroups.com> > > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/puppet-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Puppet Users" group. > > To post to this group, send email to puppet-users@googlegroups.com. > > To unsubscribe from this group, send email to > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ace
2011-Jan-05 20:20 UTC
[Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
Yes this definitely works although it replaces the file and appends the line to it every time it runs. Is there a cleaner way of doing it? tmp/filetest is a file managed by puppet who''s contents are two lines "testme" and "hmm what does this do". The append function appends line "works" everytime it runs. [root@ /]$ cat /tmp/filetest testme hmm what does this do works [root@ /]$ puppetd --test info: Caching catalog for xxx info: Applying configuration version ''1294258209'' --- /tmp/filetest Wed Jan 5 15:12:09 2011 +++ /tmp/puppet-file20110105-13009-1lgt6q-0 Wed Jan 5 15:12:26 2011 @@ -1,3 +1,2 @@ testme hmm what does this do -works info: FileBucket adding /tmp/filetest as {md5} a1e1337e26fd34816281fbb48b4db945 info: /Stage[main]/Sys_files/File[/tmp/filetest]: Filebucketed /tmp/ filetest to puppet with sum a1e1337e26fd34816281fbb48b4db945 notice: /Stage[main]/Sys_files/File[/tmp/filetest]/content: content changed ''{md5}a1e1337e26fd34816281fbb48b4db945'' to ''{md5} fcf03823146b78fb73e8df3c3494ef6d'' notice: /Stage[main]/Append/ Append::Appendifnosuchline[ensure_foobar_in_filetest]/Exec[appendline_/ tmp/filetest_works]/returns: executed successfully notice: Finished catalog run in 6.86 seconds [root@ /]$ cat /tmp/filetest testme hmm what does this do works [root@ /]$ puppetd --test info: Caching catalog for xxx info: Applying configuration version ''1294258209'' --- /tmp/filetest Wed Jan 5 15:12:27 2011 +++ /tmp/puppet-file20110105-13134-1p9lv09-0 Wed Jan 5 15:13:47 2011 @@ -1,3 +1,2 @@ testme hmm what does this do -works info: FileBucket got a duplicate file /tmp/filetest ({md5} a1e1337e26fd34816281fbb48b4db945) info: /Stage[main]/Sys_files/File[/tmp/filetest]: Filebucketed /tmp/ filetest to puppet with sum a1e1337e26fd34816281fbb48b4db945 notice: /Stage[main]/Sys_files/File[/tmp/filetest]/content: content changed ''{md5}a1e1337e26fd34816281fbb48b4db945'' to ''{md5} fcf03823146b78fb73e8df3c3494ef6d'' notice: /Stage[main]/Append/ Append::Appendifnosuchline[ensure_foobar_in_filetest]/Exec[appendline_/ tmp/filetest_works]/returns: executed successfully notice: Finished catalog run in 6.28 seconds [root@/]$ cat /tmp/filetest testme hmm what does this do works On Jan 5, 1:22 pm, Nigel Kersten <ni...@puppetlabs.com> wrote:> On Wed, Jan 5, 2011 at 8:27 AM, Ace <tejas....@gmail.com> wrote: > > Yep I have tried the code below and I got changes everytime I ran it. > > Could you elaborate on the below lines that you mentioned. Thanks. > > I will also try the concat method. > > That would be because I gave you an entirely broken example :) > > define appendifnosuchline($file="", $line="") { > exec { "appendline_${file}_${line}": > path => "/bin:/usr/bin", > command => "/bin/echo ${line} >> ${file}", > unless => "grep -qx ${line} ${file}", > } > > } > > appendifnosuchline { "ensure_foobar_in_filetest": > file => "/tmp/filetest", > line => "foobar", > > } > > That looks to work. > > > > > You can however manage the attributes of the file, and could require > > the > > given File resource when using the defined type so that those settings > > are > > always applied first. > > > On Jan 4, 11:04 am, Nigel Kersten <ni...@puppetlabs.com> wrote: > > > On Mon, Jan 3, 2011 at 1:51 PM, Ace <tejas....@gmail.com> wrote: > > > > I want to manage cronjobs as a " file " in solaris through puppet and > > > > not using the puppet cron resource. > > > > > I will be managing the file /var/spool/cron/crontabs/root. > > > > > I want the cron file to be same across all servers except some servers > > > > will have additional cron entries. > > > > > How can I append to the file /var/spool/cron/crontabs/root , something > > > > like appendifnosuchline in cfengine? > > > > > Can "appendifnosuchline" be implemented through puppet even through > > > > the file /var/spool/cron/crontabs/root is being managed through > > > > puppet? > > > > There are a bunch of recipes around where people construct an Exec with > > an > > > onlyif/unless conditional to achieve this. > > > > Here''s something I just whipped up that looks to work ok. > > > > define appendifnosuchline($file="", $line="") { > > > exec { "appendline_${file}_${line}": > > > path => "/bin:/usr/bin", > > > command => "echo ${text} >> ${line}", > > > unless => "grep -qx ${text} ${line}", > > > } > > > > } > > > > appendifnosuchline { "ensure_foobar_in_filetest": > > > file => "/tmp/filetest", > > > line => "foobar", > > > > } > > > > You could do something trickier with composite namevars, but this works. > > > > You don''t want to do this and manage the *contents* of the file with > > Puppet. > > > You''ll get changes on every run then. > > > > You can however manage the attributes of the file, and could require the > > > given File resource when using the defined type so that those settings > > are > > > always applied first. > > > > > Thanks, > > > > Ace > > > > > -- > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Puppet Users" group. > > > > To post to this group, send email to puppet-users@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > > <puppet-users%2Bunsubscribe@googlegroups.com<puppet-users%252Bunsubscribe@googlegroups.com> > > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/puppet-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Puppet Users" group. > > To post to this group, send email to puppet-users@googlegroups.com. > > To unsubscribe from this group, send email to > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Alan Barrett
2011-Jan-05 20:40 UTC
Re: [Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
On Wed, 05 Jan 2011, Nigel Kersten wrote:> define appendifnosuchline($file="", $line="") { > exec { "appendline_${file}_${line}": > path => "/bin:/usr/bin", > command => "/bin/echo ${line} >> ${file}", > unless => "grep -qx ${line} ${file}", > } > } > > appendifnosuchline { "ensure_foobar_in_filetest": > file => "/tmp/filetest", > line => "foobar", > } > > That looks to work.... unless $line begins with "-" (which will confuse grep or some versions of echo), or contains space or other shell special characters (which will confuse the shell), or contains backslash (which is special to some versions of /bin/echo), or contains regexp secial characters (which will confuse grep). Here''s my untested attempt: define appendifnosuchline($file, $line) { $escaped_line = shellquote($line) exec { "appendline_${title}": path => "/bin:/usr/bin", command => "printf ''%s\\n'' ${escaped_line} >> ${file}", unless => "grep -qFx -e ${escaped_line} ${file}", } } This is untested, and still doesn''t handle spaces or shell special characters in the file name, but it attempts to deal with the other issues: * Escape shell special characters in $line; * Use printf instead of echo to avoid portability problems with different versions of echo interpreting "-" or "\" differently. * Use grep -F option to make it search for a fixed string instead of a regular expression; * Use grep -e option to avoid problems if $line begins with "-"; I also made the $file and $line parameters compulsory, and derived the title of the exec from the title of the appendifnosuchline instead of from the file name and line contents (which might be long or ugly). --apb (Alan Barrett) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ace
2011-Jan-05 20:44 UTC
[Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
As you can see the append function is running last and hence all this is working. What controls the sequence in which the modules/classes/ function execute in puppet? Is this random or during the catalog compilation, puppet understands that it needs to run specific modules earlier and other modules later. On Jan 5, 3:20 pm, Ace <tejas....@gmail.com> wrote:> Yes this definitely works although it replaces the file and appends > the line to it every time it runs. Is there a cleaner way of doing > it? > > tmp/filetest is a file managed by puppet who''s contents are two lines > "testme" and "hmm what does this do". The append function appends line > "works" everytime it runs. > > [root@ /]$ cat /tmp/filetest > testme > hmm what does this do > works > [root@ /]$ puppetd --test > info: Caching catalog for xxx > info: Applying configuration version ''1294258209'' > --- /tmp/filetest Wed Jan 5 15:12:09 2011 > +++ /tmp/puppet-file20110105-13009-1lgt6q-0 Wed Jan 5 15:12:26 > 2011 > @@ -1,3 +1,2 @@ > testme > hmm what does this do > -works > info: FileBucket adding /tmp/filetest as {md5} > a1e1337e26fd34816281fbb48b4db945 > info: /Stage[main]/Sys_files/File[/tmp/filetest]: Filebucketed /tmp/ > filetest to puppet with sum a1e1337e26fd34816281fbb48b4db945 > notice: /Stage[main]/Sys_files/File[/tmp/filetest]/content: content > changed ''{md5}a1e1337e26fd34816281fbb48b4db945'' to ''{md5} > fcf03823146b78fb73e8df3c3494ef6d'' > notice: /Stage[main]/Append/ > Append::Appendifnosuchline[ensure_foobar_in_filetest]/Exec[appendline_/ > tmp/filetest_works]/returns: executed successfully > notice: Finished catalog run in 6.86 seconds > [root@ /]$ cat /tmp/filetest > testme > hmm what does this do > works > [root@ /]$ puppetd --test > info: Caching catalog for xxx > info: Applying configuration version ''1294258209'' > --- /tmp/filetest Wed Jan 5 15:12:27 2011 > +++ /tmp/puppet-file20110105-13134-1p9lv09-0 Wed Jan 5 15:13:47 > 2011 > @@ -1,3 +1,2 @@ > testme > hmm what does this do > -works > info: FileBucket got a duplicate file /tmp/filetest ({md5} > a1e1337e26fd34816281fbb48b4db945) > info: /Stage[main]/Sys_files/File[/tmp/filetest]: Filebucketed /tmp/ > filetest to puppet with sum a1e1337e26fd34816281fbb48b4db945 > notice: /Stage[main]/Sys_files/File[/tmp/filetest]/content: content > changed ''{md5}a1e1337e26fd34816281fbb48b4db945'' to ''{md5} > fcf03823146b78fb73e8df3c3494ef6d'' > notice: /Stage[main]/Append/ > Append::Appendifnosuchline[ensure_foobar_in_filetest]/Exec[appendline_/ > tmp/filetest_works]/returns: executed successfully > notice: Finished catalog run in 6.28 seconds > [root@/]$ cat /tmp/filetest > testme > hmm what does this do > works > > On Jan 5, 1:22 pm, Nigel Kersten <ni...@puppetlabs.com> wrote: > > > On Wed, Jan 5, 2011 at 8:27 AM, Ace <tejas....@gmail.com> wrote: > > > Yep I have tried the code below and I got changes everytime I ran it. > > > Could you elaborate on the below lines that you mentioned. Thanks. > > > I will also try the concat method. > > > That would be because I gave you an entirely broken example :) > > > define appendifnosuchline($file="", $line="") { > > exec { "appendline_${file}_${line}": > > path => "/bin:/usr/bin", > > command => "/bin/echo ${line} >> ${file}", > > unless => "grep -qx ${line} ${file}", > > } > > > } > > > appendifnosuchline { "ensure_foobar_in_filetest": > > file => "/tmp/filetest", > > line => "foobar", > > > } > > > That looks to work. > > > > You can however manage the attributes of the file, and could require > > > the > > > given File resource when using the defined type so that those settings > > > are > > > always applied first. > > > > On Jan 4, 11:04 am, Nigel Kersten <ni...@puppetlabs.com> wrote: > > > > On Mon, Jan 3, 2011 at 1:51 PM, Ace <tejas....@gmail.com> wrote: > > > > > I want to manage cronjobs as a " file " in solaris through puppet and > > > > > not using the puppet cron resource. > > > > > > I will be managing the file /var/spool/cron/crontabs/root. > > > > > > I want the cron file to be same across all servers except some servers > > > > > will have additional cron entries. > > > > > > How can I append to the file /var/spool/cron/crontabs/root , something > > > > > like appendifnosuchline in cfengine? > > > > > > Can "appendifnosuchline" be implemented through puppet even through > > > > > the file /var/spool/cron/crontabs/root is being managed through > > > > > puppet? > > > > > There are a bunch of recipes around where people construct an Exec with > > > an > > > > onlyif/unless conditional to achieve this. > > > > > Here''s something I just whipped up that looks to work ok. > > > > > define appendifnosuchline($file="", $line="") { > > > > exec { "appendline_${file}_${line}": > > > > path => "/bin:/usr/bin", > > > > command => "echo ${text} >> ${line}", > > > > unless => "grep -qx ${text} ${line}", > > > > } > > > > > } > > > > > appendifnosuchline { "ensure_foobar_in_filetest": > > > > file => "/tmp/filetest", > > > > line => "foobar", > > > > > } > > > > > You could do something trickier with composite namevars, but this works. > > > > > You don''t want to do this and manage the *contents* of the file with > > > Puppet. > > > > You''ll get changes on every run then. > > > > > You can however manage the attributes of the file, and could require the > > > > given File resource when using the defined type so that those settings > > > are > > > > always applied first. > > > > > > Thanks, > > > > > Ace > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > Groups > > > > > "Puppet Users" group. > > > > > To post to this group, send email to puppet-users@googlegroups.com. > > > > > To unsubscribe from this group, send email to > > > > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > > > <puppet-users%2Bunsubscribe@googlegroups.com<puppet-users%252Bunsubscribe@googlegroups.com> > > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/puppet-users?hl=en. > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Puppet Users" group. > > > To post to this group, send email to puppet-users@googlegroups.com. > > > To unsubscribe from this group, send email to > > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ace
2011-Jan-05 20:44 UTC
[Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
As you can see the append function is running last and hence all this is working. What controls the sequence in which the modules/classes/ function execute in puppet? Is this random or during the catalog compilation, puppet understands that it needs to run specific modules earlier and other modules later. On Jan 5, 3:20 pm, Ace <tejas....@gmail.com> wrote:> Yes this definitely works although it replaces the file and appends > the line to it every time it runs. Is there a cleaner way of doing > it? > > tmp/filetest is a file managed by puppet who''s contents are two lines > "testme" and "hmm what does this do". The append function appends line > "works" everytime it runs. > > [root@ /]$ cat /tmp/filetest > testme > hmm what does this do > works > [root@ /]$ puppetd --test > info: Caching catalog for xxx > info: Applying configuration version ''1294258209'' > --- /tmp/filetest Wed Jan 5 15:12:09 2011 > +++ /tmp/puppet-file20110105-13009-1lgt6q-0 Wed Jan 5 15:12:26 > 2011 > @@ -1,3 +1,2 @@ > testme > hmm what does this do > -works > info: FileBucket adding /tmp/filetest as {md5} > a1e1337e26fd34816281fbb48b4db945 > info: /Stage[main]/Sys_files/File[/tmp/filetest]: Filebucketed /tmp/ > filetest to puppet with sum a1e1337e26fd34816281fbb48b4db945 > notice: /Stage[main]/Sys_files/File[/tmp/filetest]/content: content > changed ''{md5}a1e1337e26fd34816281fbb48b4db945'' to ''{md5} > fcf03823146b78fb73e8df3c3494ef6d'' > notice: /Stage[main]/Append/ > Append::Appendifnosuchline[ensure_foobar_in_filetest]/Exec[appendline_/ > tmp/filetest_works]/returns: executed successfully > notice: Finished catalog run in 6.86 seconds > [root@ /]$ cat /tmp/filetest > testme > hmm what does this do > works > [root@ /]$ puppetd --test > info: Caching catalog for xxx > info: Applying configuration version ''1294258209'' > --- /tmp/filetest Wed Jan 5 15:12:27 2011 > +++ /tmp/puppet-file20110105-13134-1p9lv09-0 Wed Jan 5 15:13:47 > 2011 > @@ -1,3 +1,2 @@ > testme > hmm what does this do > -works > info: FileBucket got a duplicate file /tmp/filetest ({md5} > a1e1337e26fd34816281fbb48b4db945) > info: /Stage[main]/Sys_files/File[/tmp/filetest]: Filebucketed /tmp/ > filetest to puppet with sum a1e1337e26fd34816281fbb48b4db945 > notice: /Stage[main]/Sys_files/File[/tmp/filetest]/content: content > changed ''{md5}a1e1337e26fd34816281fbb48b4db945'' to ''{md5} > fcf03823146b78fb73e8df3c3494ef6d'' > notice: /Stage[main]/Append/ > Append::Appendifnosuchline[ensure_foobar_in_filetest]/Exec[appendline_/ > tmp/filetest_works]/returns: executed successfully > notice: Finished catalog run in 6.28 seconds > [root@/]$ cat /tmp/filetest > testme > hmm what does this do > works > > On Jan 5, 1:22 pm, Nigel Kersten <ni...@puppetlabs.com> wrote: > > > On Wed, Jan 5, 2011 at 8:27 AM, Ace <tejas....@gmail.com> wrote: > > > Yep I have tried the code below and I got changes everytime I ran it. > > > Could you elaborate on the below lines that you mentioned. Thanks. > > > I will also try the concat method. > > > That would be because I gave you an entirely broken example :) > > > define appendifnosuchline($file="", $line="") { > > exec { "appendline_${file}_${line}": > > path => "/bin:/usr/bin", > > command => "/bin/echo ${line} >> ${file}", > > unless => "grep -qx ${line} ${file}", > > } > > > } > > > appendifnosuchline { "ensure_foobar_in_filetest": > > file => "/tmp/filetest", > > line => "foobar", > > > } > > > That looks to work. > > > > You can however manage the attributes of the file, and could require > > > the > > > given File resource when using the defined type so that those settings > > > are > > > always applied first. > > > > On Jan 4, 11:04 am, Nigel Kersten <ni...@puppetlabs.com> wrote: > > > > On Mon, Jan 3, 2011 at 1:51 PM, Ace <tejas....@gmail.com> wrote: > > > > > I want to manage cronjobs as a " file " in solaris through puppet and > > > > > not using the puppet cron resource. > > > > > > I will be managing the file /var/spool/cron/crontabs/root. > > > > > > I want the cron file to be same across all servers except some servers > > > > > will have additional cron entries. > > > > > > How can I append to the file /var/spool/cron/crontabs/root , something > > > > > like appendifnosuchline in cfengine? > > > > > > Can "appendifnosuchline" be implemented through puppet even through > > > > > the file /var/spool/cron/crontabs/root is being managed through > > > > > puppet? > > > > > There are a bunch of recipes around where people construct an Exec with > > > an > > > > onlyif/unless conditional to achieve this. > > > > > Here''s something I just whipped up that looks to work ok. > > > > > define appendifnosuchline($file="", $line="") { > > > > exec { "appendline_${file}_${line}": > > > > path => "/bin:/usr/bin", > > > > command => "echo ${text} >> ${line}", > > > > unless => "grep -qx ${text} ${line}", > > > > } > > > > > } > > > > > appendifnosuchline { "ensure_foobar_in_filetest": > > > > file => "/tmp/filetest", > > > > line => "foobar", > > > > > } > > > > > You could do something trickier with composite namevars, but this works. > > > > > You don''t want to do this and manage the *contents* of the file with > > > Puppet. > > > > You''ll get changes on every run then. > > > > > You can however manage the attributes of the file, and could require the > > > > given File resource when using the defined type so that those settings > > > are > > > > always applied first. > > > > > > Thanks, > > > > > Ace > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > Groups > > > > > "Puppet Users" group. > > > > > To post to this group, send email to puppet-users@googlegroups.com. > > > > > To unsubscribe from this group, send email to > > > > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > > > <puppet-users%2Bunsubscribe@googlegroups.com<puppet-users%252Bunsubscribe@googlegroups.com> > > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/puppet-users?hl=en. > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Puppet Users" group. > > > To post to this group, send email to puppet-users@googlegroups.com. > > > To unsubscribe from this group, send email to > > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ace
2011-Jan-05 20:45 UTC
[Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
As you can see the append function is running last and hence all this is working. What controls the sequence in which the modules/classes/ function execute in puppet? Is this random or during the catalog compilation, puppet understands that it needs to run specific modules earlier and other modules later. On Jan 5, 3:40 pm, Alan Barrett <a...@cequrux.com> wrote:> On Wed, 05 Jan 2011, Nigel Kersten wrote: > > define appendifnosuchline($file="", $line="") { > > exec { "appendline_${file}_${line}": > > path => "/bin:/usr/bin", > > command => "/bin/echo ${line} >> ${file}", > > unless => "grep -qx ${line} ${file}", > > } > > } > > > appendifnosuchline { "ensure_foobar_in_filetest": > > file => "/tmp/filetest", > > line => "foobar", > > } > > > That looks to work. > > ... unless $line begins with "-" (which will confuse grep or some > versions of echo), or contains space or other shell special characters > (which will confuse the shell), or contains backslash (which is special > to some versions of /bin/echo), or contains regexp secial characters > (which will confuse grep). > > Here''s my untested attempt: > > define appendifnosuchline($file, $line) { > $escaped_line = shellquote($line) > exec { "appendline_${title}": > path => "/bin:/usr/bin", > command => "printf ''%s\\n'' ${escaped_line} >> ${file}", > unless => "grep -qFx -e ${escaped_line} ${file}", > } > } > > This is untested, and still doesn''t handle spaces or shell special > characters in the file name, but it attempts to deal with the other > issues: > > * Escape shell special characters in $line; > * Use printf instead of echo to avoid portability problems with > different versions of echo interpreting "-" or "\" differently. > * Use grep -F option to make it search for a fixed string > instead of a regular expression; > * Use grep -e option to avoid problems if $line begins with "-"; > > I also made the $file and $line parameters compulsory, and derived the > title of the exec from the title of the appendifnosuchline instead of > from the file name and line contents (which might be long or ugly). > > --apb (Alan Barrett)-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Alan Barrett
2011-Jan-05 20:48 UTC
Re: [Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
On Wed, 05 Jan 2011, Ace wrote:> Yes this definitely works although it replaces the file and appends > tmp/filetest is a file managed by puppet who''s contents are two lines > "testme" and "hmm what does this do". The append function appends line > "works" everytime it runs.This is a problem that you were warned about. You have two conflicting rules about the same file; one rule says "it must contain exactly two lines, no more and no less -- the two lines must be ''testme'' and ''hmm what does this do''"; the other rule says "it must contain a line that says ''works''". You can''t simultaneously satisfy both rules, but puppet tries as hard as it can, removing the "works" line when it focuses on the "file" rule, and reinstating the "works" line when it focuses on the "append" rule. --apb (Alan Barrett) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Nigel Kersten
2011-Jan-05 21:12 UTC
Re: [Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
On Wed, Jan 5, 2011 at 12:40 PM, Alan Barrett <apb@cequrux.com> wrote:> On Wed, 05 Jan 2011, Nigel Kersten wrote: > > define appendifnosuchline($file="", $line="") { > > exec { "appendline_${file}_${line}": > > path => "/bin:/usr/bin", > > command => "/bin/echo ${line} >> ${file}", > > unless => "grep -qx ${line} ${file}", > > } > > } > > > > appendifnosuchline { "ensure_foobar_in_filetest": > > file => "/tmp/filetest", > > line => "foobar", > > } > > > > That looks to work. > > ... unless $line begins with "-" (which will confuse grep or some > versions of echo), or contains space or other shell special characters > (which will confuse the shell), or contains backslash (which is special > to some versions of /bin/echo), or contains regexp secial characters > (which will confuse grep). >All excellent points.> > Here''s my untested attempt: > > define appendifnosuchline($file, $line) { > $escaped_line = shellquote($line) > exec { "appendline_${title}": > path => "/bin:/usr/bin", > command => "printf ''%s\\n'' ${escaped_line} >> ${file}", > unless => "grep -qFx -e ${escaped_line} ${file}", > } > } > > This is untested, and still doesn''t handle spaces or shell special > characters in the file name, but it attempts to deal with the other > issues: > > * Escape shell special characters in $line; > * Use printf instead of echo to avoid portability problems with > different versions of echo interpreting "-" or "\" differently. > * Use grep -F option to make it search for a fixed string > instead of a regular expression; > * Use grep -e option to avoid problems if $line begins with "-"; > > I also made the $file and $line parameters compulsory, and derived the > title of the exec from the title of the appendifnosuchline instead of > from the file name and line contents (which might be long or ugly). >That''s a good improvement.> > --apb (Alan Barrett) > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ace
2011-Jan-06 19:49 UTC
[Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
As you can see the append function is running last and hence all this is working. What controls the sequence in which the modules/classes/ function execute in puppet? Is this random or during the catalog compilation, puppet understands that it needs to run specific modules earlier and other modules later. On Jan 5, 4:12 pm, Nigel Kersten <ni...@puppetlabs.com> wrote:> On Wed, Jan 5, 2011 at 12:40 PM, Alan Barrett <a...@cequrux.com> wrote: > > On Wed, 05 Jan 2011, Nigel Kersten wrote: > > > define appendifnosuchline($file="", $line="") { > > > exec { "appendline_${file}_${line}": > > > path => "/bin:/usr/bin", > > > command => "/bin/echo ${line} >> ${file}", > > > unless => "grep -qx ${line} ${file}", > > > } > > > } > > > > appendifnosuchline { "ensure_foobar_in_filetest": > > > file => "/tmp/filetest", > > > line => "foobar", > > > } > > > > That looks to work. > > > ... unless $line begins with "-" (which will confuse grep or some > > versions of echo), or contains space or other shell special characters > > (which will confuse the shell), or contains backslash (which is special > > to some versions of /bin/echo), or contains regexp secial characters > > (which will confuse grep). > > All excellent points. > > > > > > > Here''s my untested attempt: > > > define appendifnosuchline($file, $line) { > > $escaped_line = shellquote($line) > > exec { "appendline_${title}": > > path => "/bin:/usr/bin", > > command => "printf ''%s\\n'' ${escaped_line} >> ${file}", > > unless => "grep -qFx -e ${escaped_line} ${file}", > > } > > } > > > This is untested, and still doesn''t handle spaces or shell special > > characters in the file name, but it attempts to deal with the other > > issues: > > > * Escape shell special characters in $line; > > * Use printf instead of echo to avoid portability problems with > > different versions of echo interpreting "-" or "\" differently. > > * Use grep -F option to make it search for a fixed string > > instead of a regular expression; > > * Use grep -e option to avoid problems if $line begins with "-"; > > > I also made the $file and $line parameters compulsory, and derived the > > title of the exec from the title of the appendifnosuchline instead of > > from the file name and line contents (which might be long or ugly). > > That''s a good improvement. > > > > > --apb (Alan Barrett) > > > -- > > You received this message because you are subscribed to the Google Groups > > "Puppet Users" group. > > To post to this group, send email to puppet-users@googlegroups.com. > > To unsubscribe from this group, send email to > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Nigel Kersten
2011-Jan-06 20:15 UTC
Re: [Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
On Thu, Jan 6, 2011 at 11:49 AM, Ace <tejas.zzz@gmail.com> wrote:> As you can see the append function is running last and hence all this > is working. What controls the sequence in which the modules/classes/ > function execute in puppet? Is this random or during the catalog > compilation, puppet understands that it needs to run specific modules > earlier and other modules later. >It''s random unless you define relationships between the classes. I highly suggest you keep the principle of encapsulation, resources should only require resources within the same class, and intra-class relationships should be defined as class<->class, never to individual resources in a foreign class.> > > > On Jan 5, 4:12 pm, Nigel Kersten <ni...@puppetlabs.com> wrote: > > On Wed, Jan 5, 2011 at 12:40 PM, Alan Barrett <a...@cequrux.com> wrote: > > > On Wed, 05 Jan 2011, Nigel Kersten wrote: > > > > define appendifnosuchline($file="", $line="") { > > > > exec { "appendline_${file}_${line}": > > > > path => "/bin:/usr/bin", > > > > command => "/bin/echo ${line} >> ${file}", > > > > unless => "grep -qx ${line} ${file}", > > > > } > > > > } > > > > > > appendifnosuchline { "ensure_foobar_in_filetest": > > > > file => "/tmp/filetest", > > > > line => "foobar", > > > > } > > > > > > That looks to work. > > > > > ... unless $line begins with "-" (which will confuse grep or some > > > versions of echo), or contains space or other shell special characters > > > (which will confuse the shell), or contains backslash (which is special > > > to some versions of /bin/echo), or contains regexp secial characters > > > (which will confuse grep). > > > > All excellent points. > > > > > > > > > > > > > Here''s my untested attempt: > > > > > define appendifnosuchline($file, $line) { > > > $escaped_line = shellquote($line) > > > exec { "appendline_${title}": > > > path => "/bin:/usr/bin", > > > command => "printf ''%s\\n'' ${escaped_line} >> ${file}", > > > unless => "grep -qFx -e ${escaped_line} ${file}", > > > } > > > } > > > > > This is untested, and still doesn''t handle spaces or shell special > > > characters in the file name, but it attempts to deal with the other > > > issues: > > > > > * Escape shell special characters in $line; > > > * Use printf instead of echo to avoid portability problems with > > > different versions of echo interpreting "-" or "\" differently. > > > * Use grep -F option to make it search for a fixed string > > > instead of a regular expression; > > > * Use grep -e option to avoid problems if $line begins with "-"; > > > > > I also made the $file and $line parameters compulsory, and derived the > > > title of the exec from the title of the appendifnosuchline instead of > > > from the file name and line contents (which might be long or ugly). > > > > That''s a good improvement. > > > > > > > > > --apb (Alan Barrett) > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Puppet Users" group. > > > To post to this group, send email to puppet-users@googlegroups.com. > > > To unsubscribe from this group, send email to > > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > <puppet-users%2Bunsubscribe@googlegroups.com<puppet-users%252Bunsubscribe@googlegroups.com> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/puppet-users?hl=en. > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ace
2011-Jan-07 14:27 UTC
[Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
Can you please state an example explaining how relating classes would execute one class before another? On Jan 6, 3:15 pm, Nigel Kersten <ni...@puppetlabs.com> wrote:> On Thu, Jan 6, 2011 at 11:49 AM, Ace <tejas....@gmail.com> wrote: > > As you can see the append function is running last and hence all this > > is working. What controls the sequence in which the modules/classes/ > > function execute in puppet? Is this random or during the catalog > > compilation, puppet understands that it needs to run specific modules > > earlier and other modules later. > > It''s random unless you define relationships between the classes. > > I highly suggest you keep the principle of encapsulation, resources should > only require resources within the same class, and intra-class relationships > should be defined as class<->class, never to individual resources in a > foreign class. > > > > > On Jan 5, 4:12 pm, Nigel Kersten <ni...@puppetlabs.com> wrote: > > > On Wed, Jan 5, 2011 at 12:40 PM, Alan Barrett <a...@cequrux.com> wrote: > > > > On Wed, 05 Jan 2011, Nigel Kersten wrote: > > > > > define appendifnosuchline($file="", $line="") { > > > > > exec { "appendline_${file}_${line}": > > > > > path => "/bin:/usr/bin", > > > > > command => "/bin/echo ${line} >> ${file}", > > > > > unless => "grep -qx ${line} ${file}", > > > > > } > > > > > } > > > > > > appendifnosuchline { "ensure_foobar_in_filetest": > > > > > file => "/tmp/filetest", > > > > > line => "foobar", > > > > > } > > > > > > That looks to work. > > > > > ... unless $line begins with "-" (which will confuse grep or some > > > > versions of echo), or contains space or other shell special characters > > > > (which will confuse the shell), or contains backslash (which is special > > > > to some versions of /bin/echo), or contains regexp secial characters > > > > (which will confuse grep). > > > > All excellent points. > > > > > Here''s my untested attempt: > > > > > define appendifnosuchline($file, $line) { > > > > $escaped_line = shellquote($line) > > > > exec { "appendline_${title}": > > > > path => "/bin:/usr/bin", > > > > command => "printf ''%s\\n'' ${escaped_line} >> ${file}", > > > > unless => "grep -qFx -e ${escaped_line} ${file}", > > > > } > > > > } > > > > > This is untested, and still doesn''t handle spaces or shell special > > > > characters in the file name, but it attempts to deal with the other > > > > issues: > > > > > * Escape shell special characters in $line; > > > > * Use printf instead of echo to avoid portability problems with > > > > different versions of echo interpreting "-" or "\" differently. > > > > * Use grep -F option to make it search for a fixed string > > > > instead of a regular expression; > > > > * Use grep -e option to avoid problems if $line begins with "-"; > > > > > I also made the $file and $line parameters compulsory, and derived the > > > > title of the exec from the title of the appendifnosuchline instead of > > > > from the file name and line contents (which might be long or ugly). > > > > That''s a good improvement. > > > > > --apb (Alan Barrett) > > > > > -- > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Puppet Users" group. > > > > To post to this group, send email to puppet-users@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > > <puppet-users%2Bunsubscribe@googlegroups.com<puppet-users%252Bunsubscribe@googlegroups.com> > > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/puppet-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Puppet Users" group. > > To post to this group, send email to puppet-users@googlegroups.com. > > To unsubscribe from this group, send email to > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Felix Frank
2011-Jan-07 14:36 UTC
Re: [Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
On 01/07/2011 03:27 PM, Ace wrote:> Can you please state an example explaining how relating classes would > execute one class before another?Ace, in this simple case, you could probably get away with define appendifnosuchline($file="", $line="") { exec { "appendline_${file}_${line}": path => "/bin:/usr/bin", command => "/bin/echo ${line} >> ${file}", unless => "grep -qx ${line} ${file}", require => File[$file], } } Note the require parameter to the exec resource. This will prevent you from using this define on non-puppetmanaged files though. For more flexibility: define appendifnosuchline($file="", $line="", $disable_autorequire => false) { if !$disable_autorequire { Exec { require => File[$file] } } exec { "appendline_${file}_${line}": path => "/bin:/usr/bin", command => "/bin/echo ${line} >> ${file}", unless => "grep -qx ${line} ${file}", } } Then specify "disable_autorequire => true" where applicable. The third route is not to touch the define at all and add the require each time you declare it as a resource. But that''s redundant, and we don''t like that. There, much safer now ;) Cheers, Felix -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Nigel Kersten
2011-Jan-07 15:00 UTC
Re: [Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
On Fri, Jan 7, 2011 at 6:27 AM, Ace <tejas.zzz@gmail.com> wrote:> Can you please state an example explaining how relating classes would > execute one class before another?class foo { require "bar" }> > On Jan 6, 3:15 pm, Nigel Kersten <ni...@puppetlabs.com> wrote: >> On Thu, Jan 6, 2011 at 11:49 AM, Ace <tejas....@gmail.com> wrote: >> > As you can see the append function is running last and hence all this >> > is working. What controls the sequence in which the modules/classes/ >> > function execute in puppet? Is this random or during the catalog >> > compilation, puppet understands that it needs to run specific modules >> > earlier and other modules later. >> >> It''s random unless you define relationships between the classes. >> >> I highly suggest you keep the principle of encapsulation, resources should >> only require resources within the same class, and intra-class relationships >> should be defined as class<->class, never to individual resources in a >> foreign class. >> >> >> >> > On Jan 5, 4:12 pm, Nigel Kersten <ni...@puppetlabs.com> wrote: >> > > On Wed, Jan 5, 2011 at 12:40 PM, Alan Barrett <a...@cequrux.com> wrote: >> > > > On Wed, 05 Jan 2011, Nigel Kersten wrote: >> > > > > define appendifnosuchline($file="", $line="") { >> > > > > exec { "appendline_${file}_${line}": >> > > > > path => "/bin:/usr/bin", >> > > > > command => "/bin/echo ${line} >> ${file}", >> > > > > unless => "grep -qx ${line} ${file}", >> > > > > } >> > > > > } >> >> > > > > appendifnosuchline { "ensure_foobar_in_filetest": >> > > > > file => "/tmp/filetest", >> > > > > line => "foobar", >> > > > > } >> >> > > > > That looks to work. >> >> > > > ... unless $line begins with "-" (which will confuse grep or some >> > > > versions of echo), or contains space or other shell special characters >> > > > (which will confuse the shell), or contains backslash (which is special >> > > > to some versions of /bin/echo), or contains regexp secial characters >> > > > (which will confuse grep). >> >> > > All excellent points. >> >> > > > Here''s my untested attempt: >> >> > > > define appendifnosuchline($file, $line) { >> > > > $escaped_line = shellquote($line) >> > > > exec { "appendline_${title}": >> > > > path => "/bin:/usr/bin", >> > > > command => "printf ''%s\\n'' ${escaped_line} >> ${file}", >> > > > unless => "grep -qFx -e ${escaped_line} ${file}", >> > > > } >> > > > } >> >> > > > This is untested, and still doesn''t handle spaces or shell special >> > > > characters in the file name, but it attempts to deal with the other >> > > > issues: >> >> > > > * Escape shell special characters in $line; >> > > > * Use printf instead of echo to avoid portability problems with >> > > > different versions of echo interpreting "-" or "\" differently. >> > > > * Use grep -F option to make it search for a fixed string >> > > > instead of a regular expression; >> > > > * Use grep -e option to avoid problems if $line begins with "-"; >> >> > > > I also made the $file and $line parameters compulsory, and derived the >> > > > title of the exec from the title of the appendifnosuchline instead of >> > > > from the file name and line contents (which might be long or ugly). >> >> > > That''s a good improvement. >> >> > > > --apb (Alan Barrett) >> >> > > > -- >> > > > You received this message because you are subscribed to the Google >> > Groups >> > > > "Puppet Users" group. >> > > > To post to this group, send email to puppet-users@googlegroups.com. >> > > > To unsubscribe from this group, send email to >> > > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> >> > <puppet-users%2Bunsubscribe@googlegroups.com<puppet-users%252Bunsubscribe@googlegroups.com> >> >> > > > . >> > > > For more options, visit this group at >> > > >http://groups.google.com/group/puppet-users?hl=en. >> >> > -- >> > You received this message because you are subscribed to the Google Groups >> > "Puppet Users" group. >> > To post to this group, send email to puppet-users@googlegroups.com. >> > To unsubscribe from this group, send email to >> > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> >> > . >> > For more options, visit this group at >> >http://groups.google.com/group/puppet-users?hl=en. >> >> > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ace
2011-Jan-07 22:27 UTC
[Puppet Users] Re: Managing cronjobs as a file in solaris with appendifnosuchline for specific servers
Thanks all, finally got it working now. On Jan 7, 10:00 am, Nigel Kersten <ni...@puppetlabs.com> wrote:> On Fri, Jan 7, 2011 at 6:27 AM, Ace <tejas....@gmail.com> wrote: > > Can you please state an example explaining how relating classes would > > execute one class before another? > > class foo { > require "bar" > > } > > > On Jan 6, 3:15 pm, Nigel Kersten <ni...@puppetlabs.com> wrote: > >> On Thu, Jan 6, 2011 at 11:49 AM, Ace <tejas....@gmail.com> wrote: > >> > As you can see the append function is running last and hence all this > >> > is working. What controls the sequence in which the modules/classes/ > >> > function execute in puppet? Is this random or during the catalog > >> > compilation, puppet understands that it needs to run specific modules > >> > earlier and other modules later. > > >> It''s random unless you define relationships between the classes. > > >> I highly suggest you keep the principle of encapsulation, resources should > >> only require resources within the same class, and intra-class relationships > >> should be defined as class<->class, never to individual resources in a > >> foreign class. > > >> > On Jan 5, 4:12 pm, Nigel Kersten <ni...@puppetlabs.com> wrote: > >> > > On Wed, Jan 5, 2011 at 12:40 PM, Alan Barrett <a...@cequrux.com> wrote: > >> > > > On Wed, 05 Jan 2011, Nigel Kersten wrote: > >> > > > > define appendifnosuchline($file="", $line="") { > >> > > > > exec { "appendline_${file}_${line}": > >> > > > > path => "/bin:/usr/bin", > >> > > > > command => "/bin/echo ${line} >> ${file}", > >> > > > > unless => "grep -qx ${line} ${file}", > >> > > > > } > >> > > > > } > > >> > > > > appendifnosuchline { "ensure_foobar_in_filetest": > >> > > > > file => "/tmp/filetest", > >> > > > > line => "foobar", > >> > > > > } > > >> > > > > That looks to work. > > >> > > > ... unless $line begins with "-" (which will confuse grep or some > >> > > > versions of echo), or contains space or other shell special characters > >> > > > (which will confuse the shell), or contains backslash (which is special > >> > > > to some versions of /bin/echo), or contains regexp secial characters > >> > > > (which will confuse grep). > > >> > > All excellent points. > > >> > > > Here''s my untested attempt: > > >> > > > define appendifnosuchline($file, $line) { > >> > > > $escaped_line = shellquote($line) > >> > > > exec { "appendline_${title}": > >> > > > path => "/bin:/usr/bin", > >> > > > command => "printf ''%s\\n'' ${escaped_line} >> ${file}", > >> > > > unless => "grep -qFx -e ${escaped_line} ${file}", > >> > > > } > >> > > > } > > >> > > > This is untested, and still doesn''t handle spaces or shell special > >> > > > characters in the file name, but it attempts to deal with the other > >> > > > issues: > > >> > > > * Escape shell special characters in $line; > >> > > > * Use printf instead of echo to avoid portability problems with > >> > > > different versions of echo interpreting "-" or "\" differently. > >> > > > * Use grep -F option to make it search for a fixed string > >> > > > instead of a regular expression; > >> > > > * Use grep -e option to avoid problems if $line begins with "-"; > > >> > > > I also made the $file and $line parameters compulsory, and derived the > >> > > > title of the exec from the title of the appendifnosuchline instead of > >> > > > from the file name and line contents (which might be long or ugly). > > >> > > That''s a good improvement. > > >> > > > --apb (Alan Barrett) > > >> > > > -- > >> > > > You received this message because you are subscribed to the Google > >> > Groups > >> > > > "Puppet Users" group. > >> > > > To post to this group, send email to puppet-users@googlegroups.com. > >> > > > To unsubscribe from this group, send email to > >> > > > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > >> > <puppet-users%2Bunsubscribe@googlegroups.com<puppet-users%252Bunsubscribe@googlegroups.com> > > >> > > > . > >> > > > For more options, visit this group at > >> > > >http://groups.google.com/group/puppet-users?hl=en. > > >> > -- > >> > You received this message because you are subscribed to the Google Groups > >> > "Puppet Users" group. > >> > To post to this group, send email to puppet-users@googlegroups.com. > >> > To unsubscribe from this group, send email to > >> > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > >> > . > >> > For more options, visit this group at > >> >http://groups.google.com/group/puppet-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > > To post to this group, send email to puppet-users@googlegroups.com. > > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > > For more options, visit this group athttp://groups.google.com/group/puppet-users?hl=en.-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.