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 <[email protected]> wrote:
> On Wed, Jan 5, 2011 at 8:27 AM, Ace <[email protected]> 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 <[email protected]> wrote:
> > > On Mon, Jan 3, 2011 at 1:51 PM, Ace <[email protected]> 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 [email protected].
> > > > To unsubscribe from this group, send email to
> > > > [email protected]<puppet-users%[email protected]>
> > <puppet-users%[email protected]<puppet-users%[email protected]>
>
> > > > .
> > > > 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 [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<puppet-users%[email protected]>
> > .
> > 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.