# 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:** 17\
**Page:** 3

<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, 12:55pm UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/41 "2016-05-24T12:55:04Z")

</div>

Here is how to setup Docker to use proxy settings. [https://docs.docker.com/engine/admin/systemd/](https://docs.docker.com/engine/admin/systemd/)

The Docker container uses CentOS as its base image. If you don't want to use Docker I can make an Ansible playbook for you instead. I won't be able to get the playbook ready until next week, I'm leaving for vacation today.

---

<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 26, 2016, 3:56pm UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/42 "2016-05-26T15:56:12Z")

</div>

Hi Jason  
It would be great if you could create an ansible playbook for this. Because I might not able to use docker in the real lab. I'll wait untill you come back from vacation. 🙂  
Thanks in advance. Have a wonderful 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:** [June 3, 2016, 2:31am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/43 "2016-06-03T02:31:01Z")

</div>

I've created a playbook that will work with RHEL7, try it out and let me know how it goes.

---

<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:** [June 3, 2016, 3:20am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/44 "2016-06-03T03:20:06Z")

</div>

Thanks Jason. But I am using RHEL 6.7. Will it work there?

---

<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:** [June 6, 2016, 3:21am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/45 "2016-06-06T03:21:44Z")

</div>

Hi Jason  
The github repository is not available any more. could you please share the new repo if you have created one?

---

<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:** [June 8, 2016, 11:59am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/46 "2016-06-08T11:59:04Z")

</div>

New repo  
[https://github.com/OneMainF/vmware-ansible-rhel-server-builder](https://github.com/OneMainF/vmware-ansible-rhel-server-builder)

I’ll create a playbook that works on RHEL 6.7 sometime 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:** [June 20, 2016, 4:07am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/47 "2016-06-20T04:07:05Z")

</div>

Hi Jason  
I have tried the ansible playbook that you created.  
Here are the issues I am facing at this time.

1. while creating running the playbook I got

TASK [Open port 80 in the firewall] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [127.0.0.1]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “Destination /etc/sysconfig/iptables does not exist !”, “rc”: 257}

to get rid of this error I added /etc/sysconfig/iptables manually, whereas in my server iptables service was disabled. Is it mandatory to have iptables settings in place?

1. Second error:

TASK [SELinux allow to connect to MySQL] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [127.0.0.1]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “This module requires libselinux-python support”}

I installed the rpm in order to get rid of this error. This can be added to the instruction.

1. Third Error:

TASK [SELinux allow to connect to MySQL] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [127.0.0.1]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “SELinux is disabled on this host.”}

By default in my server SELINUX was disabled. Is it Mandatory to be the SELINUX to be enabled?  
to get rid of this I enabled SELINUX.

After this The playbook ran successfully.  
But I was unable to create a VM.

Error 1: “Invalid HD Side” I have HD side as 20/30/50  
where as when I gave the value as 100 or 200 the error disappeared.

Error 2: when I rerty a VM creation, it says already exists in the DB, whereas the node was not created at all, Is the nodename getting saved in DB somewhere? If yes then how to clean that up?

Overall, I am not able to find out why the VM creation is not working.  
Is there any way to check any logs to find out the errors? which log to check?

Thanks and regards  
Dibyendu

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 20, 2016, 1:16pm UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/48 "2016-06-20T13:16:19Z")

</div>

Even if selinux is ‘inactive’ Ansible requires the libselinux-python library to make sure contexts are preserved, otherwise you can get an unusable system if selinux is turned on later.

---

<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:** [June 21, 2016, 2:22am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/49 "2016-06-21T02:22:00Z")

</div>

I left the SELinux rules in place because I assumed that they are enabled. If you have disabled them go ahead and comment out those lines from the playbook.

To remove any severs from the table run the following commands.

mysql -u root -d sysmgmt  
delete from servers where serverid = ‘your\_server’;

For more troubleshooting go to the /var/www/html/builds/ directory and cat out the yml file for your server so I take a look.

Be sure the remove any sensitive information from the yml file.

---

<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:** [June 21, 2016, 3:20am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/50 "2016-06-21T03:20:12Z")

</div>

Hi Jason  
Thank you.  
Is there any way that a log rotation could be introduced for this project.

---

<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:** [June 21, 2016, 6:36am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/51 "2016-06-21T06:36:02Z")

</div>

It is also not clear to me how do I map VMWare network and their Managed Object Reference (MoRef)  
what are the information this should contain?

{  
“192.168.1.0”: “dvportgroup-123”,  
“192.168.2.0”: “dvportgroup-456”  
}  
how do I map

VirtualMachine- **vm-\***

HostSystem- **host-\***

Datastore- **datastore-\***

for example, I have a ESXI host, vCenter and 2 datastores.

---

<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:** [June 22, 2016, 1:31am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/52 "2016-06-22T01:31:41Z")

</div>

Sure, which logs need rotated?

---

<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:** [June 22, 2016, 2:03am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/53 "2016-06-22T02:03:07Z")

</div>

Mostly Ansible related logs.

It is also not clear to me how do I map VMWare network and their Managed Object Reference (MoRef)  
what are the information this should contain?

{  
“192.168.1.0”: “dvportgroup-123”,  
“192.168.2.0”: “dvportgroup-456”  
}  
how do I map

VirtualMachine- **vm-\***

HostSystem- **host-\***

Datastore- **datastore-\***

for example, I have a ESXI host, vCenter and 2 datastores.

**Basically I was not able to spin up a single VM 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:** [June 22, 2016, 3:04am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/54 "2016-06-22T03:04:12Z")

</div>

Please email me the yml file in the /var/www/html/builds directory

---

<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:** [June 22, 2016, 3:24am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/55 "2016-06-22T03:24:56Z")

</div>

You only need the mapping for the distributed switches, this will not affect VM builds. There is a script that gets called at the end of the build process that changes the VMs network from the DHCP network to your desired network. If this step fails the VM will still get crested, it will just be on the wrong network. You will have to go into VCenter and manually change the VMs network.

I’ll write a script that gets the Morefs of your switches 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:** [June 22, 2016, 6:17am UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/56 "2016-06-22T06:17:25Z")

</div>

That is great!  
I had another query. In case the web UI is not used is there any way the information could be fed to the ansible as an input file?

---

<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:** [June 23, 2016, 4:15pm UTC](https://forum.ansible.com/t/build-automation-using-esxi-ansible-pysphere/17193/57 "2016-06-23T16:15:02Z")

</div>

Hi Jason  
Were you able to analyze the yml files I emailed you? Is there any specific issues?

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