Build automation using ESXi, Ansible, Pysphere

Here is how to setup Docker to use proxy settings. 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.

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. :slight_smile:
Thanks in advance. Have a wonderful time. :slight_smile:

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

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

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

New repo
https://github.com/OneMainF/vmware-ansible-rhel-server-builder

I’ll create a playbook that works on RHEL 6.7 sometime this week

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

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.

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.

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

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.

Sure, which logs need rotated?

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. :frowning:

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

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.

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?

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