# Build automation using ESXi, Ansible, Pysphere

**URL:** <https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193>\
**Category:** Ansible Project\
**Tags:** rhel, vmware\
**Created:** [January 6, 2015, 9:07am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193 "2015-01-06T09:07:53Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Mark\_Phillips](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mark\_Phillips](https://forum.ansible.com/u/Mark_Phillips)\
**Post date:** [April 21, 2016, 4:56pm UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/21 "2016-04-21T16:56:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jason\_Hiatt](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jason\_Hiatt](https://forum.ansible.com/u/Jason_Hiatt)\
**Post date:** [April 22, 2016, 2:23am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/22 "2016-04-22T02:23:29Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Dibyendu\_Paul](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dibyendu\_Paul](https://forum.ansible.com/u/Dibyendu_Paul)\
**Post date:** [April 22, 2016, 4:24am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/23 "2016-04-22T04:24:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Jason\_Hiatt](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jason\_Hiatt](https://forum.ansible.com/u/Jason_Hiatt)\
**Post date:** [April 25, 2016, 3:07am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/24 "2016-04-25T03:07:24Z")

</div>

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](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](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](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.

---

<div class="post-metadata">

**Author:** ![Dibyendu\_Paul](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dibyendu\_Paul](https://forum.ansible.com/u/Dibyendu_Paul)\
**Post date:** [April 25, 2016, 4:32am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/25 "2016-04-25T04:32:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jason\_Hiatt](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jason\_Hiatt](https://forum.ansible.com/u/Jason_Hiatt)\
**Post date:** [April 26, 2016, 10:49pm UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/26 "2016-04-26T22:49:18Z")

</div>

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.

``

---

<div class="post-metadata">

**Author:** ![Dibyendu\_Paul](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dibyendu\_Paul](https://forum.ansible.com/u/Dibyendu_Paul)\
**Post date:** [April 27, 2016, 12:10am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/27 "2016-04-27T00:10:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dibyendu\_Paul](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dibyendu\_Paul](https://forum.ansible.com/u/Dibyendu_Paul)\
**Post date:** [April 27, 2016, 12:10am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/28 "2016-04-27T00:10:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dibyendu\_Paul](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dibyendu\_Paul](https://forum.ansible.com/u/Dibyendu_Paul)\
**Post date:** [April 28, 2016, 6:44am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/29 "2016-04-28T06:44:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jason\_Hiatt](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jason\_Hiatt](https://forum.ansible.com/u/Jason_Hiatt)\
**Post date:** [April 29, 2016, 12:42pm UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/30 "2016-04-29T12:42:15Z")

</div>

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…](http://test.example.com/ws/createVM.php?vmname=$%7BVMName%7D&ipaddress=$%7BIPAddress%7D&cpus=2......).”

Thanks,

Jason

---

<div class="post-metadata">

**Author:** ![Dibyendu\_Paul](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dibyendu\_Paul](https://forum.ansible.com/u/Dibyendu_Paul)\
**Post date:** [April 29, 2016, 2:22pm UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/31 "2016-04-29T14:22:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dibyendu\_Paul](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dibyendu\_Paul](https://forum.ansible.com/u/Dibyendu_Paul)\
**Post date:** [May 6, 2016, 2:44am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/32 "2016-05-06T02:44:49Z")

</div>

Hi Jason  
Is there any instructions available yet?

---

<div class="post-metadata">

**Author:** ![Jason\_Hiatt](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jason\_Hiatt](https://forum.ansible.com/u/Jason_Hiatt)\
**Post date:** [May 10, 2016, 1:47am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/33 "2016-05-10T01:47:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dibyendu\_Paul](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dibyendu\_Paul](https://forum.ansible.com/u/Dibyendu_Paul)\
**Post date:** [May 10, 2016, 10:30am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/34 "2016-05-10T10:30:55Z")

</div>

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](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](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?

---

<div class="post-metadata">

**Author:** ![Jason\_Hiatt](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jason\_Hiatt](https://forum.ansible.com/u/Jason_Hiatt)\
**Post date:** [May 10, 2016, 10:01pm UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/35 "2016-05-10T22:01:51Z")

</div>

Yes, the isolinux.cfg file, this link may explain better.  
[http://vuksan.com/linux/kickstart\_boot\_cd.html](http://vuksan.com/linux/kickstart_boot_cd.html)

---

<div class="post-metadata">

**Author:** ![Dibyendu\_Paul](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dibyendu\_Paul](https://forum.ansible.com/u/Dibyendu_Paul)\
**Post date:** [May 11, 2016, 4:04am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/36 "2016-05-11T04:04:35Z")

</div>

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](http://CONTAINERHOSTNAME/kickstart/ks.php?osid=rhel7_64Guest)**

---

<div class="post-metadata">

**Author:** ![Jason\_Hiatt](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jason\_Hiatt](https://forum.ansible.com/u/Jason_Hiatt)\
**Post date:** [May 11, 2016, 10:54am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/37 "2016-05-11T10:54:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dibyendu\_Paul](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dibyendu\_Paul](https://forum.ansible.com/u/Dibyendu_Paul)\
**Post date:** [May 23, 2016, 9:26am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/38 "2016-05-23T09:26:16Z")

</div>

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:](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]#

---

<div class="post-metadata">

**Author:** ![Jason\_Hiatt](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jason\_Hiatt](https://forum.ansible.com/u/Jason_Hiatt)\
**Post date:** [May 24, 2016, 2:59am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/39 "2016-05-24T02:59:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dibyendu\_Paul](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dibyendu\_Paul](https://forum.ansible.com/u/Dibyendu_Paul)\
**Post date:** [May 24, 2016, 8:45am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/40 "2016-05-24T08:45:41Z")

</div>

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?

[Previous page](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193.md?page=1)

[Next page](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193.md?page=3)
