I want to set the Grub password and setup serial consoles on my KVM hosts with Puppet. Augeas is the tool to properly manage grub.conf without having to be aware of each kernel update as it hits the Puppet client. I found lots of half-solutions on the internet, but never the whole ball of wax. So, here’s a Puppet class that does exactly this.

class realmlinux::grub {

    $rootmd5 = $rlmtools["root"]

    # Set the Grub password
    if $rootmd5 != undef {

        # Create password setup in grub if not present
        augeas { "grub-create-password":
            context => "/files/boot/grub/menu.lst",
            changes => [
                "ins password after default",
                "set password/md5 ''",
                "set password $rootmd5",
            ],
            onlyif => "match password size == 0",
        }

        # Set the password in grub.conf
        augeas { "grub-set-password":
            context => "/files/boot/grub/menu.lst",
            changes => [
                "set password $rootmd5",
            ],
            require => Augeas["grub-create-password"],
        }

    }
    # KVMs should have serial consoles setup so "virsh console" works
    if $productname == "KVM" {

        # Setup Grub's serial console magic
        augeas { "grub-serial-consoles":
            context => "/files/boot/grub/menu.lst",
            changes => [
                "ins serial after default",
                "ins terminal after serial",
                "set serial/unit 0",
                "set serial/speed 115200",
                "set terminal/timeout 10",
                "clear terminal/console",
                "clear terminal/serial",
            ],
            onlyif  => "match terminal size == 0",
        }

        # Correct all kernel lines to have the needed console parameters
        augeas { "grub-set-kernel-consoles":
            context => "/files/boot/grub/menu.lst",
            changes => [
                "setm /files/boot/grub/menu.lst/title/kernel/ console tty0",
                "setm /files/boot/grub/menu.lst/title/kernel/ console[2] ttyS0,115200n8",
            ],
        }

    }

}

On KVM boxes this adds

serial --unit=0 --speed=115200
terminal --timeout=10 console serial

lines to grub.conf. Also, it corrects each kernel stanza to have the correct console parameters.

Previous | Back | Next


comments powered by Disqus