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-us...@googlegroups.com. > >> > > > To unsubscribe from this group, send email to > >> > > > puppet-users+unsubscr...@googlegroups.com<puppet-users%2bunsubscr...@googlegroups.com> > >> > <puppet-users%2bunsubscr...@googlegroups.com<puppet-users%252bunsubscr...@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-us...@googlegroups.com. > >> > To unsubscribe from this group, send email to > >> > puppet-users+unsubscr...@googlegroups.com<puppet-users%2bunsubscr...@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-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > puppet-users+unsubscr...@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-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.