help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Editing Files


From: tiperry
Subject: Editing Files
Date: Fri, 14 Nov 2003 12:18:46 -0500


I am trying to use cfengine to automate my configuration changes to linux grub.conf to ensure that the serial console settings are correctly configured.

Part of this process requires the appending of "console=tty0 console=ttyS0,115200" to every kernel line.  This is simple if I only have one kernel installed, but depending on the machine there may be one to unknown number of kernels.  

What I am trying to do is loop through all lines that match a certain regex and "AppendToLineIfNotContains" the "console=tty0 console=ttyS0,115200" to each of those lines, however I can not figure out anyway to loop.  I can easily do this in sed, but was hoping to do this in cfengine for consistency.

Below is the original grub.conf, the desired results, and my current editfiles section for editing this file.  This editfile only modifies the first kernel entry as I figured, but I can get it to edit any of the other additional lines.

Current:  grub.conf
----------
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd0,0)
#          kernel /boot/vmlinuz-version ro root=/dev/sda1
#          initrd /boot/initrd-version.img
#boot=/dev/sda
default=1
timeout=10
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title Red Hat Linux (2.4.9-e.27smp)
 root (hd0,0)
 kernel /boot/vmlinuz-2.4.9-e.27smp ro root=/dev/sda1
 initrd /boot/initrd-2.4.9-e.27smp.img
title Red Hat Linux (2.4.9-e.27enterprise)
 root (hd0,0)
 kernel /boot/vmlinuz-2.4.9-e.27enterprise ro root=/dev/sda1
 initrd /boot/initrd-2.4.9-e.27enterprise.img
title Red Hat Linux (2.4.9-e.27)
 root (hd0,0)
 kernel /boot/vmlinuz-2.4.9-e.27 ro root=/dev/sda1 console=tty0
 initrd /boot/initrd-2.4.9-e.27.img

Desired grub.conf
-----------------

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd0,0)
#          kernel /boot/vmlinuz-version ro root=/dev/sda1 console=tty0 console=ttyS0,115200 nmi_watchdog=1 profile="">
#          initrd /boot/initrd-version.img
#boot=/dev/sda
default=1
timeout=10
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title Red Hat Linux (2.4.9-e.27smp)
 root (hd0,0)
 kernel /boot/vmlinuz-2.4.9-e.27smp ro root=/dev/sda1 console=tty0 console=ttyS0,115200 nmi_watchdog=1 profile="">
 initrd /boot/initrd-2.4.9-e.27smp.img
title Red Hat Linux (2.4.9-e.27enterprise)
 root (hd0,0)
 kernel /boot/vmlinuz-2.4.9-e.27enterprise ro root=/dev/sda1 console=tty0 console=ttyS0,115200 nmi_watchdog=1 profile="">
 initrd /boot/initrd-2.4.9-e.27enterprise.img
title Red Hat Linux (2.4.9-e.27)
 root (hd0,0)
 kernel /boot/vmlinuz-2.4.9-e.27 ro root=/dev/sda1 console=tty0 console=ttyS0,115200 nmi_watchdog=1 profile="">
 initrd /boot/initrd-2.4.9-e.27.img

Sample CFengine script snipet:
-------------------------
editfiles:

   redhat::
      {  /tmp/grub.conf
         Backup "one"
         CommentLinesMatching "^splashimage.*"
         BeginGroupIfNoLineMatching "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
            LocateLineMatching "^timeout.*"
            InsertLine "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1"
            InsertLine "terminal --timeout=10 serial console"
            LocateLineMatching ".*kernel /boot.*"
            AppendToLineIfNotContains " console=tty0 console=ttyS0,115200 nmi_watchdog=1 profile="">
            DefineInGroup SetupSerialConsole
         EndGroup
      }

Tim Perry
Quantum Leap Consolidation


reply via email to

[Prev in Thread] Current Thread [Next in Thread]
  • Editing Files, tiperry <=