Build automation using ESXi, Ansible, Pysphere

Custom ISO, that’s generic. Think something like iPXE. Boots, kickstart talks to a web service, web service provides tailored Kickstart file.

You will need to setup a few more things, I’m working on Dockerizing this entire setup, just haven’t had time.

I’ll add more examples to Github this weekend.

First you need to add something like this to the kernel line of your custom ISO

For RHEL6 for example

ks=http://kickstart.eample.com/kickstart/ks.php?osid=rhel_64Guest kssendmac ks.sendmac inst.ks.sendmac

That tells the ISO to get it’s Kickstart config from a dynamic kickstart file (ks.php - web service) and to send the VM’s MAC address.

Here is a snippet from the web service

<?php foreach (getallheaders() as $sName => $sValue) { if ($sName == "X-RHN-Provisioning-MAC-0") { $aValue = explode(" ", $sValue); $sThisMAC = strtolower($aValue[1]); if ($sThisMAC != "") { $sSQL = "select * from servers where LOWER(macaddress) = '" . $sThisMAC; ##Generate dynamic kickstart ?>

Now that I can lookup the MAC address I can create a dynamic Kickstart for the VM.

I now also have the server in a database which allows me to create a dynamic Ansible inventory.

Ansible has helped our automation out tremendously, we can fully provision RHEL servers in about 10 minutes.

Our motto is “If your VM isn’t ready in 15 minutes your next one is free!”

Thanks,

Jason

Hi
How the kick start will pick individual ips of the vms. Where those ips to be defined?
The kick start will not have the up conf? How do you make it generalized?

We have a web UI that lets our admins input IP, VM name, number of CPUs, RAM and other attributes.

You can see a stripped down version of it here → https://github.com/OneMainF/vmware-rhel-server-builder/blob/master/build/src/www/createVM.html

The web UI calls this web service when all inputs are entered → https://github.com/OneMainF/vmware-rhel-server-builder/blob/master/build/src/www/ws/createvm.php

The web service adds the server to a database and creates an Ansible play and runs it. The playbook creates the VM and collects the VM’s MAC address and updates the DB.

Once the VM starts up the dynamic Kickstart file is called and the VM is built.
https://github.com/OneMainF/vmware-rhel-server-builder/blob/master/build/src/www/kickstart/ks.php

I’m getting closer to Dockeizing the application, hopefully I can get it done this week.

Hi Jason
This is excellent!
In this setup is it possible to pick the RHEL OS from the Installation server? where the iso could be kept or local repository could be created?

Regards
Dibyendu Paul

Yes, you could specify the installation server in your custom ISO.

I think the correct option to use is "inst.repo="

We just use the installation source from the DVD.

``

Hi Jason
Thanks.
Are you going to add a short description in github as in how to use the repository? I mean a set of instructions may be.

Hi Jason
Thanks.
Are you going to add a short description in github as in how to use the repository? I mean a set of instructions may be.

Also The current Web UI allows to create one VM at a time. Is It possible to create Multiple VMs at a time?

Yes, I am going to update code and write up some instructions this weekend. I have a big project at work I need to finish up before I can get to that though.

If you want to make multiple VMs I would write a script that calls the createVM.php web service.

All you would have to do is call curl, for example. curl “http://test.example.com/ws/createVM.php?vmname=${VMName}&ipaddress=${IPAddress}&cpus=2….”

Thanks,

Jason

Thanks much Jason.
I will keep an eye on the github page.

Hi Jason
Is there any instructions available yet?

Instructions are finally up, sorry it took so long, ran into some bugs while I was Dockerizing the app. Please try it out and let me know what problems you come across.

Thanks Great Jason.
But I have a silly question.
where exactly (Which file) do I insert the following line: kssendmac ks.sendmac inst.ks.sendmac ks=http://CONTAINERHOSTNAME/kickstart/ks.php?osid=rhel6_64Guest
The link you mentioned ( http://serverfault.com/questions/517908/how-to-create-a-custom-iso-image-in-centos) basically used the kickstart file and here I suppose the boot line needs to be added. where do I put the boot line in that case? Is it the isolinux.cfg file I need to modify?

Yes, the isolinux.cfg file, this link may explain better.
http://vuksan.com/linux/kickstart_boot_cd.html

Thanks Jason.
Just to make sure that I am doing it right.
Could you please confirm if this is correct. I have changed the texts marked in BOLD.

default ks
#prompt 1
timeout 600

display boot.msg

menu background splash.jpg
menu title Welcome to Red Hat Enterprise Linux 6.5!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000

label linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz
append initrd=initrd.img
label vesa
menu label Install system with ^basic video driver
kernel vmlinuz
append initrd=initrd.img xdriver=vesa nomodeset
label rescue
menu label ^Rescue installed system
kernel vmlinuz
append initrd=initrd.img rescue
label local
menu label Boot from ^local drive
localboot 0xffff
label memtest86
menu label ^Memory test
kernel memtest
append -
label ks
menu label ^Kickstart installation
kernel kickstart
append kssendmac ks.sendmac inst.ks.sendmac ks=http://CONTAINERHOSTNAME/kickstart/ks.php?osid=rhel7_64Guest

That looks correct, make sure CONTAINERHOSTNAME is changed to the hostname that is running your Docker container.

Hi Jason
Any idea about this error?

[root@controlserver vmware-rhel-server-builder]# /usr/bin/docker build -t hs .
Sending build context to Docker daemon 1.032 MB
Sending build context to Docker daemon
Step 0 : FROM centos
Pulling repository centos
Get https://index.docker.io/v1/repositories/library/centos/images: dial tcp 52.73.94.64:443: connection timed out
[root@controlserver vmware-rhel-server-builder]#

Looks like Docker can’t get out to the Internet to fetch the CentOS image. Make sure the box you are on has Internet access or if is behind a proxy has the proxy variables set.

Hi Jason
The machine has internet access I am able to use yum install. The proxy is set. But I am wondering why is it looking for centos. Also is it possible that it doesn't look for internet at all?