Monday, September 1, 2014

Playing with puppet vol VI - provisioning centos machines vol II

Last time I've been trying to provision centos machines with kickstart and puppet. But It was not perfect because I had to manually append kickstart file to kernel. Today I'll remove this manual step.

How to setup a pxeboot is described in this post. So at first I'll set boot priority for the guest:

.
.
.
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm
    <boot dev='hd'/>
    <boot dev='network'/>
  </os>
.
.
.

This will boot from hardisk at first. But it will fail, because there is no system installed on the disk. It will fall back to network boot. After installation guest will automatically boot from hardisk.

I'll prepare default syslinux menu. It will contain menu entries for Centos 5-7:

[root@kra pxelinux.cfg]$ cat /var/lib/tftp/pxelinux.cfg/default 
default menu.c32
prompt 0
timeout 100
ONTIMEOUT local

MENU TITLE PXE Menu

LABEL CentOS 7 x86_64 puppet
        MENU LABEL CentOS 7 puppet
        KERNEL images/centos/7/x86_64/vmlinuz
        APPEND ks=http://192.168.122.1/ks-puppet7.cfg initrd=images/centos/7/x86_64/initrd.img console=ttyS0,11200 

LABEL CentOS 6 x86_64 puppet
        MENU LABEL CentOS 6 puppet
        KERNEL images/centos/6/x86_64/vmlinuz
        APPEND ks=http://192.168.122.1/ks-puppet6.cfg initrd=images/centos/6/x86_64/initrd.img console=ttyS0,11200 

LABEL CentOS 5 x86_64 puppet
        MENU LABEL CentOS 5 puppet
        KERNEL images/centos/5/x86_64/vmlinuz
        APPEND ks=http://192.168.122.1/ks-puppet5.cfg initrd=images/centos/5/x86_64/initrd.img console=ttyS0,11200 

I'll download missing kernel images and initial ramdisks and put them to the appropriate location:

[root@kra tftp]$ pwd
/var/lib/tftp
[root@kra tftp]$ mkdir -p images/centos/{6,5}/x86_64
[root@kra tftp]$ curl -# http://ftp.linux.cz/pub/linux/centos/6.5/os/x86_64/isolinux/vmlinuz -o images/centos/6/x86_64/vmlinuz
######################################################################## 100.0%
[root@kra tftp]$ curl -# http://ftp.linux.cz/pub/linux/centos/6.5/os/x86_64/isolinux/initrd.img -o images/centos/6/x86_64/initrd.img
######################################################################## 100.0%
[root@kra tftp]$ curl -# http://ftp.linux.cz/pub/linux/centos/5.10/os/x86_64/isolinux/initrd.img -o images/centos/5/x86_64/initrd.img
######################################################################## 100.0%
[root@kra tftp]$ curl -# http://ftp.linux.cz/pub/linux/centos/5.10/os/x86_64/isolinux/vmlinuz -o images/centos/5/x86_64/vmlinuz
######################################################################## 100.0%
[root@kra tftp]$ tree images
images
`-- centos
    |-- 5
    |   `-- x86_64
    |       |-- initrd.img
    |       `-- vmlinuz
    |-- 6
    |   `-- x86_64
    |       |-- initrd.img
    |       `-- vmlinuz
    `-- 7
        `-- x86_64
            |-- initrd.img
            |-- initrd.img.backup
            |-- initrd.modified2.img
            |-- initrd.modified.img
            `-- vmlinuz

7 directories, 9 files

Now is everything prepared. Now I don't have to manually add kickstart location to kernel. Instead I have to manually chose one entry from pxelinux menu. I've changed one manual thing for another. That's not big improvement. But I can do better. According to pxelinux documentation, it will search for configfile using its MAC address. I'll check puppet7 MAC address:

virsh # domiflist puppet7
Interface  Type       Source     Model       MAC
-------------------------------------------------------
-          network    default    virtio      52:54:00:89:20:7f

virsh # 

I'll create another pxelinux configfile named as lowercase MAC address prefixed with ARP code (which is 01).

[root@kra tftp]$ pwd
/var/lib/tftp
[root@kra tftp]$ cat pxelinux.cfg/01-52-54-00-89-20-7f 
DEFAULT CentOS 7 puppet
LABEL CentOS 7 puppet
    KERNEL images/centos/7/x86_64/vmlinuz
    APPEND ks=http://192.168.122.1/ks-puppet7.cfg initrd=images/centos/7/x86_64/initrd.img console=ttyS0,11200

I'll also disable default pxelinux configuration by renaming it:

[root@kra tftp]$ mv pxelinux.cfg/default pxelinux.cfg/default.backup
[root@kra tftp]$ tree pxelinux.cfg/
pxelinux.cfg/
|-- 01-52-54-00-89-20-7f
`-- default.backup

0 directories, 3 files

When I start the guest I can see it has used the correct config file (line with red dot):

Guest will shutdown after successful installation. That's because of shutdown/poweroff command in the kickstart file. I can replace it with reboot command. After reboot It will boot from disk and puppet will configure the system.

For other centos versions I have to find out generated MAC addresses:

v[root@kra hasul]$ virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # domiflist puppet6
Interface  Type       Source     Model       MAC
-------------------------------------------------------
-          network    default    virtio      52:54:00:e4:e7:ef

virsh # domiflist puppet5
Interface  Type       Source     Model       MAC
-------------------------------------------------------
-          network    default    virtio      52:54:00:31:d7:84

I'll create separate pxelinux config file for each machine:

[root@kra tftp]$ pwd
/var/lib/tftp
[root@kra tftp]$ ls -1 pxelinux.cfg
01-52-54-00-31-d7-84
01-52-54-00-89-20-7f
01-52-54-00-e4-e7-ef
default.backup
[root@kra tftp]$ cat pxelinux.cfg/01-52-54-00-e4-e7-ef 
DEFAULT CentOS 6 puppet
LABEL CentOS 6 puppet
    KERNEL images/centos/6/x86_64/vmlinuz
    APPEND ks=http://192.168.122.1/ks-puppet6.cfg initrd=images/centos/6/x86_64/initrd.img console=ttyS0,11200
[root@kra tftp]$ cat pxelinux.cfg/01-52-54-00-31-d7-84 
DEFAULT CentOS 5 puppet
LABEL CentOS 5 puppet
    KERNEL images/centos/5/x86_64/vmlinuz
    APPEND ks=http://192.168.122.1/ks-puppet5.cfg initrd=images/centos/5/x86_64/initrd.img console=ttyS0,11200

That's it.

Sources

No comments:

Post a Comment