Can I use puppet to ensure that a file includes certain text but not be required to maintain the entire file? For example, I would like /etc/modprobe.conf to contain the following lines but the file will also contain lines that are system dependent. --------------------------------------------------------------------------------------- # Disable IPV6 alias net-pf-10 off alias ipv6 off --------------------------------------------------------------------------------------- So modprobe.conf might look like this on one system: --------------------------------------------------------------------------------------- alias eth0 e1000 alias scsi_hostadapter mptbase alias scsi_hostadapter1 mptscsi alias scsi_hostadapter2 mptfc alias scsi_hostadapter3 mptspi alias scsi_hostadapter4 mptsas alias scsi_hostadapter5 mptscsih alias usb-controller uhci-hcd # Disable IPV6 alias net-pf-10 off alias ipv6 off # Added by VMware Tools install vmnics /sbin/modprobe vmxnet; /sbin/modprobe pcnet32; /bin/true alias char-major-14 sb options sb io=0x220 irq=5 dma=1 dma16=5 mpu_io=0x330 --------------------------------------------------------------------------------------- and like this on another --------------------------------------------------------------------------------------- alias eth0 sis900 alias snd-card-0 snd-intel8x0 options snd-card-0 index=0 options snd-intel8x0 index=0 remove snd-intel8x0 { /usr/sbin/alsactl store 0 >/dev/null 2>&1 || : ; }; /sbin/modprobe -r --ignore-remove snd-intel8x0 # Disable IPV6 alias net-pf-10 off alias ipv6 off --------------------------------------------------------------------------------------- Thanks, Ben.
You can do this a few ways, either have the system specific portion stored in puppet for each host then source both parts and combine the files. I use a little script for adding a line, however it could easily be modified to do more than one line, though I suspect it will work better if you use it for each line. *** This is taken from / based on a puppet cookbook site out there that I seem to not have the link for on this system, but I do want to give credit to whomever I''m ripping this off from. I''m sorry that I don''t have the link right now - if you''re on here please pipe up :) *** Anyhow, my puppet config part looks like: define addline ( $file, $line ) { exec { "echo ''$line'' >> ''$file''" : unless => "grep -Fx ''$line'' ''$file''", } } and I would call it like addline { "IPv6_is_evil" : file => ''/etc/modprobe.conf'', line => ''alias ipv6 off'', } something of a hockery I admit. I try not to write this type of thing, and I don''t call it except as part of other functions (I try to hide the ugly things I do in my manifests..) .r'' On 1/8/07, Abnormaliti <Abnormaliti@clivepeeters.com.au> wrote:> Can I use puppet to ensure that a file includes certain text but not be > required to maintain the entire file? > > For example, > > I would like /etc/modprobe.conf to contain the following lines but the > file will also contain lines that are system dependent. > --------------------------------------------------------------------------------------- > # Disable IPV6 > alias net-pf-10 off > alias ipv6 off > --------------------------------------------------------------------------------------- > > So modprobe.conf might look like this on one system: > --------------------------------------------------------------------------------------- > alias eth0 e1000 > alias scsi_hostadapter mptbase > alias scsi_hostadapter1 mptscsi > alias scsi_hostadapter2 mptfc > alias scsi_hostadapter3 mptspi > alias scsi_hostadapter4 mptsas > alias scsi_hostadapter5 mptscsih > alias usb-controller uhci-hcd > > # Disable IPV6 > alias net-pf-10 off > alias ipv6 off > > # Added by VMware Tools > install vmnics /sbin/modprobe vmxnet; /sbin/modprobe pcnet32; /bin/true > alias char-major-14 sb > options sb io=0x220 irq=5 dma=1 dma16=5 mpu_io=0x330 > --------------------------------------------------------------------------------------- > and like this on another > --------------------------------------------------------------------------------------- > alias eth0 sis900 > alias snd-card-0 snd-intel8x0 > options snd-card-0 index=0 > options snd-intel8x0 index=0 > remove snd-intel8x0 { /usr/sbin/alsactl store 0 >/dev/null 2>&1 || : ; > }; /sbin/modprobe -r --ignore-remove snd-intel8x0 > > # Disable IPV6 > alias net-pf-10 off > alias ipv6 off > --------------------------------------------------------------------------------------- > > Thanks, > > Ben. > > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >
RijilV wrote:> You can do this a few ways, either have the system specific portion > stored in puppet for each host then source both parts and combine the > files. I use a little script for adding a line, however it could > easily be modified to do more than one line, though I suspect it will > work better if you use it for each line. > > *** This is taken from / based on a puppet cookbook site out there > that I seem to not have the link for on this system, but I do want to > give credit to whomever I''m ripping this off from. I''m sorry that I > don''t have the link right now - if you''re on here please pipe up :) > *** > > Anyhow, my puppet config part looks like: > > define addline ( $file, $line ) { > exec { "echo ''$line'' >> ''$file''" : > unless => "grep -Fx ''$line'' ''$file''", > } > } > > and I would call it like > > addline { "IPv6_is_evil" : > file => ''/etc/modprobe.conf'', > line => ''alias ipv6 off'', > } > > something of a hockery I admit. I try not to write this type of > thing, and I don''t call it except as part of other functions (I try to > hide the ugly things I do in my manifests..) > > .r'' > > On 1/8/07, Abnormaliti <Abnormaliti@clivepeeters.com.au> wrote: > >> Can I use puppet to ensure that a file includes certain text but not be >> required to maintain the entire file? >> >> For example, >> >> I would like /etc/modprobe.conf to contain the following lines but the >> file will also contain lines that are system dependent. >> --------------------------------------------------------------------------------------- >> # Disable IPV6 >> alias net-pf-10 off >> alias ipv6 off >> --------------------------------------------------------------------------------------- >> >> So modprobe.conf might look like this on one system: >> --------------------------------------------------------------------------------------- >> alias eth0 e1000 >> alias scsi_hostadapter mptbase >> alias scsi_hostadapter1 mptscsi >> alias scsi_hostadapter2 mptfc >> alias scsi_hostadapter3 mptspi >> alias scsi_hostadapter4 mptsas >> alias scsi_hostadapter5 mptscsih >> alias usb-controller uhci-hcd >> >> # Disable IPV6 >> alias net-pf-10 off >> alias ipv6 off >> >> # Added by VMware Tools >> install vmnics /sbin/modprobe vmxnet; /sbin/modprobe pcnet32; /bin/true >> alias char-major-14 sb >> options sb io=0x220 irq=5 dma=1 dma16=5 mpu_io=0x330 >> --------------------------------------------------------------------------------------- >> and like this on another >> --------------------------------------------------------------------------------------- >> alias eth0 sis900 >> alias snd-card-0 snd-intel8x0 >> options snd-card-0 index=0 >> options snd-intel8x0 index=0 >> remove snd-intel8x0 { /usr/sbin/alsactl store 0 >/dev/null 2>&1 || : ; >> }; /sbin/modprobe -r --ignore-remove snd-intel8x0 >> >> # Disable IPV6 >> alias net-pf-10 off >> alias ipv6 off >> --------------------------------------------------------------------------------------- >> >> Thanks, >> >> Ben. >> >> _______________________________________________ >> Puppet-users mailing list >> Puppet-users@madstop.com >> https://mail.madstop.com/mailman/listinfo/puppet-users >> >> > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users > > >Thankyou for your help, that''ll do the job. I would imagine it would be reasonably trivial to add this functionality to puppet and if no one can offer a native way to achieve it i would consider submitting it as a feature request. If i ever find the time to learn Ruby i would be happy to help. Ben
Another way to do this is following the pattern of a recipe I found somewhere on the website: # Usage: # append_if_no_such_line { dummy_modules: # file => "/etc/modules", # line => dummy # } # # Ensures, that the line "line" exists in "file". define append_if_no_such_line(file, line) { exec { "/bin/echo ''$line'' >> ''$file''": unless => "/bin/grep -Fx ''$line'' ''$file''" } } Peter/Rainhead Abnormaliti wrote:> Can I use puppet to ensure that a file includes certain text but not be > required to maintain the entire file?