This document explain how to install and configure vagrant to use Vmware Vcenter. Firstly we must install and configure our virtual environment. I have 2 ESXI servers worked with clustered storage from FC storage.

Before read this document you must install and configure your Fedora24 desktop with vagrant and ansible.

Install Vagrant Ansible and Virtualbox in Feora 24/25

 

Lets  start   the  article Vagrant  and Vsphere integration

The configuration of vCenter as following:

ESXI severs:
10.50.94.8
10.50.94.9
Vcenter server:
10.50.94.10

dev is the resource pool. The name Cluster will be used in our Vagrantfile. Right click on the Cluster(or Ctrl+O) and choose New Resource Pool. Select as default and write name is dev.

Right click on the dev resource pool and select New Virtual Machine (or Ctrl+N). Configure new virtual machine with you need and as operation system select CentOS7. Give name of virtual machine cos7box. Remove floppy device and select vlan for your network card in the DHCP subnet. Install your operation system as default with minimal installation. Set hostname cos7box and configure network card to start when system up. Disable IPv6. Set root password to vagrant.

After installation login to your Linux via ssh.

Update chache and packages:
[[email protected] ~]# yum makecache fast
[[email protected] ~]# yum update -y

Disable Selinux, firewalld and do reboot your template system:
[[email protected] ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
[[email protected] ~]# systemctl disable firewalld
[[email protected] ~]# reboot

Install perl and needed packages because vmware-tools will be require:
[[email protected] ~]# yum -y install perl net-tools bind-utils

Install vmware-tools. In the console of virtual machine select VM -> Guest -> Install/Upgrade Vmware Tools

In the Linux console mount cdrom and install vmware-tools:
[[email protected] ~]# mount /dev/cdrom /media/
mount: /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# cp /media/VMwareTools-10.0.0-3000743.tar.gz /root/
[[email protected] ~]# cd /root/; tar zxf VMwareTools-10.0.0-3000743.tar.gz ; cd vmware-tools-distrib/

Answer the first question yes and select default to others(just press Enter button)
[[email protected] vmware-tools-distrib]# ./vmware-install.pl
[[email protected] vmware-tools-distrib]# ./vmware-install.pl
open-vm-tools are available from the OS vendor and VMware recommends using
open-vm-tools. See http://kb.vmware.com/kb/2073803 for more information.
Do you still want to proceed with this legacy installer? [no] yes
Enjoy,
–the VMware team

Select VM -> Edit Settings and change cdrom to Host Device:

Add new user vagrant and give password vagrant:
[[email protected] ~]# useradd -m vagrant
[[email protected] ~]# passwd vagrant
Changing password for user vagrant.
New password: vagrant
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: vagrant
passwd: all authentication tokens updated successfully.

Give full access to vagrant user to use sudo:
[[email protected] ~]# visudo
## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now
Defaults:vagrant !requiretty
vagrant ALL=(ALL) NOPASSWD:ALL

Gerate SSH folder to this user and download vagrant public key to this folder:

Set SSH permissions to work without warnings:

Shutdown the virtual machine and create template in the vcenter console of this machine:
[[email protected] ~]# poweroff

Right click on the virtual machine select Template and Convert to Template:

Fedora desktop and install and configure vagrant with ansible

Create folder for our Vagrantfile and go to this folder:

Create temps folder for file syncronization and tasks folder for ansible playbooks:

Create cos7-playbook.yml file with the following content (This file will include install_nginx.yml file from tasks folder to install/configure and start nginx):

Create tasks/install_nginx.yml file with the following content:
[[email protected] vsphere]$ cat tasks/install_nginx.yml
– name: NGINX | Installing NGINX repo rpm
yum:
name: http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

– name: NGINX | Installing NGINX
yum:
name: nginx
state: latest

– name: NGINX | Starting NGINX
service:
name: nginx
state: started

Install needed plugins:

 

Create and add new box for vsphere:

Look at box files:

Create vagrantfile with the following contents:

Use the following command to start new virtual machine and install nginx to this virtual machine(If you want to debug use the vagrant up –debug command):

Try to login to the virtual machine:

SHARE
Jamal Shahverdiyev, I was born in Azerbaijan. I have 10 years experience in IT especially in open source technologies. I have worked as a lead specialist in many important government projects. I am author of dozens of books about open source technologies in my native language and three of them have been published. I share my knowledge in universities regularly and teach Unix/Linux.

LEAVE A REPLY

Please enter your comment!
Please enter your name here