top of page
Search
eleaseweapq

CentOS Template for vSphere ESX: Automating VM Configuration with PowerCLI



#===============================================================================# Virtual machine parameters#===============================================================================# The name of the virtual machine #vm_name = "centos-standalone"# The datastore name used to store the files of the virtual machine #vm_datastore = "Datastore-02"# The vSphere network name used by the virtual machine #vm_network = "pg-inkubate-production-static"# The netmask used to configure the network card of the virtual machine (example: 24) #vm_netmask = "24"# The network gateway used by the virtual machine #vm_gateway = "10.10.40.1"# The DNS server used by the virtual machine #vm_dns = "10.10.40.1"# The domain name used by the virtual machine #vm_domain = "inkubate.io"# The vSphere template the virtual machine is based on #vm_template = "centos-7-terraform-template"# Use linked clone (true/false)vm_linked_clone = "false"# The number of vCPU allocated to the virtual machine #vm_cpu = "1"# The amount of RAM allocated to the virtual machine #vm_ram = "1024"# The IP address of the virtual machine #vm_ip = "10.10.40.254"




How to Create a CentOS Template for vSphere ESX




You need yum-utils installed to get package-cleanup. This has to go before the yum cleanup in the next step as it needs your channel data. I usually let the post-deployment configuration management take care of this, but this is nice when we create a new template for a intermediate/point release, or just to cover a security hole.


What do you suggest or think what might be the difference in the templates centos 6 and 7. I even compared the network scripts eth01 and network file and replicated the same on to centos 7 template and still same issue. But when i manually clone from the vsphere client the vmware is able to assign a random ip address. Note: when cloning from java for centos 6 template the network adapter is getting ticked and for centos 7 it is not getting ticked. Kindly need you help or suggestions.


We created a new Centos 7 template and when i cloned a server, i am not able to assign the desired ip-address or no ip-address is assigned. When i go to edit settings of the cloned centos 7 server the network adapter is not ticked. While in cloned centos 6 server the network adapter is automatically ticked .


Using the steps above you now have CentOS templates that is ready to be used in Cloud Assembly with cloud-init. In a future post I will show how to create a Windows Server template for Cloud Assembly.


"variables": "version": "0.0.X", "HTTP_IP": "fileserver.rockylinux.lan", "HTTP_PATH": "/packer/rockylinux/8/ks.cfg" , "sensitive-variables": ["vcenter_password"], "provisioners": [ "type": "shell", "expect_disconnect": true, "execute_command": "bash '.Path'", "script": "template_dir/scripts/requirements.sh" ], "builders": [ "type": "vsphere-iso", "CPUs": 2, "CPU_hot_plug": true, "RAM": 2048, "RAM_hot_plug": true, "disk_controller_type": "pvscsi", "guest_os_type": "centos8_64Guest", "iso_paths": [ "[datasyno-contentlibrary-mylib] contentlib-a86ad29a-a43b-4717-97e6-593b8358801b/3a381c78-b9df-45a6-82e1-3c07c8187dbe/Rocky-8.4-x86_64-minimal_72cc0cc6-9d0f-4c68-9bcd-06385a506a5d.iso" ], "network_adapters": [ "network_card": "vmxnet3", "network": "net_infra" ], "storage": [ "disk_size": 40000, "disk_thin_provisioned": true ], "boot_command": [ " text ip=192.168.1.11::192.168.1.254:255.255.255.0:template:ens192:none nameserver=192.168.1.254 inst.ks=http:// user `HTTP_IP` / user `HTTP_PATH` " ], "ssh_password": "mysecurepassword", "ssh_username": "root", "shutdown_command": "/sbin/halt -h -p", "insecure_connection": "true", "username": " user `vcenter_username` ", "password": " user `vcenter_password` ", "vcenter_server": "vsphere.rockylinux.lan", "datacenter": "DC_NAME", "datastore": "DS_NAME", "vm_name": "template-rockylinux8- user `version` ", "folder": "Templates/RockyLinux", "cluster": "CLUSTER_NAME", "host": "esx1.rockylinux.lan", "notes": "Template RockyLinux version user `version` ", "convert_to_template": true, "create_snapshot": false ]Next, we will describe each section of this file.


Use_AD_Configuration_Files_Of_Current_VDA: Determines whether to use the existing AD-related configuration files (/etc/krb5.conf, /etc/sssd.conf, and /etc/samba/smb.conf) of the currently running VDA. If set to Y, the configuration files on MCS-created machines are the same as the equivalents on the currently running VDA. However, you still must configure the dns and AD_INTEGRATION variables. The default value is N, which means the configuration templates on the master image determine the configuration files on MCS-created machines.


(If you are using a currently running VDA as the template VM or if it is a non-domain-joined scenario, skip this step.) On the template VM, update the configuration templates to customize the relevant /etc/krb5.conf, /etc/samba/smb.conf, and /etc/sssd/sssd.conf files on all created VMs.


9: Final step is to remove the users ssh history and then shut down the machine to create the template. The final command shuts down the guest and you should be ready with the template. Any additional commands you want to run on the template should be run before sys-unconfig.


Terraform configuration files are text files with a .tf file extension. To get started, create a new folder for this configuration, along with a file called vsphere.tf. The first part to creating a Terraform configuration file is to define the provider you will interact with. In this example, it will create a virtual machine using the vSphere provider. The vSphere provider has some required fields like the user, password and server name. Create the provider block referring to "vsphere" and set the required fields with valid values for your environment.


Following the provider, define any "data" sources needed, which are used to retrieve existing objects. In this example of creating a vSphere virtual machine, reference the existing data center, cluster, datastore, VM network and template objects. This is defined in the code below. You can see that the "name" values are used to locate each of the objects. These will be referenced later to retrieve the ID values, as you can also see in the "vsphere_resource_pool" data source.


Once you have all of the required data sources, define the "resource" that is to be created. In this case, it will be the "vsphere_virtual_machine" type, where the configuration of the virtual machine is defined. Start by defining the VM name, along with how many CPUs and the amount of memory to be assigned (in MB). There are a few required fields such as the datastore_ID and resource_pool_ID, which are referred to using the "data" sources created earlier. Then set the guest_ID and scsi_type to reference the guest_id and scsi_type of the template VM by referencing the "data" source.


Once your file is complete, run the "terraform init" command in the folder which contains your vsphere.tf file. This will automatically download any providers that are referenced in your Terraform configuration file. Next, run the "terraform plan" command which will show you exactly what resources are to be created. In this example, it will be one vsphere_virtual_machine. If the plan looks correct, run the command "terraform apply --auto-approve" to provision your virtual machine. Congratulations! You should now have your new VM deployed in your vSphere environment.


In vSphere, VM templates are considered golden images. You can quickly create and run a VM from either the web client or PowerCLI with fewer steps rather than starting from scratch via installation media.


Once a VM is ready to become a template, use the New-Template cmdlet in PowerCLI. In the example below, assume you already created a new VM called Win2016VM, installed the Windows OS and configured the VM as a golden image. With the New-Template cmdlet, take that VM and create a new template called Windows2016Template using the location VMLocation on the datastore VMDatastore.


Packer, the open source image builder from HashiCorp, provides a more modern method of creating a vSphere template. It can create platform-independent machine images for AWS, Azure and VMware, as well as other on-premises and cloud providers. Another advantage of Packer is that the machine details of a VM's creation -- both the machine itself and processed template -- can be kept in code. For this reason, users need not change an existing VMware VM template in vCenter -- they can simply change the existing Packer template in code when a change is necessary and deploy the new VM from Packer, minimizing time and effort. An example configuration for the Packer post-processor looks like this:


Once you create a VM template in vSphere, you can use it to deploy new VMs. Before you do, though, create an OS customization specification in PowerCLI. This task ensures that when a VM is created from a template, you can still change certain settings to make it unique. These settings include the organization name, security identifier, local administrator password for the template, Active Directory domain, time zone, domain credentials used to join AD, Windows product key and the AutoLogonCount registry key.


After this, you can deploy a VM from the template and the OS customization specification. Even better, you can create VMs over and over with the same template, knowing each one has the same configuration.


You can create an ESXi image for MAAS deployment via the following procedure. MAAS cannot directly deploy the VMware ESXi ISO; a specialized image must be created from the ISO. Canonical has created a Packer template to automatically do this for you.


I originally began playing with Harbor as a component of the Pivotal Container Service (PKS) package since it was all bundled and has automated deploy capabilities. After exploring what Harbor had to offer, I wanted to use it with my existing Kubernetes clusters that were built with kubeadm outside of PKS. I began by deploying the OVA into my vSphere environment and ran into issues and learned the OVA was being a deprecated form of installation (#5276). I decided to try using the online version of the installer that will pull images from DockerHub. I've been using CentOS a lot more than Ubuntu lately because it maps more to customer environments. So create a new CentOS 7 virtual machine from a template or build one out. 2ff7e9595c


0 views0 comments

Recent Posts

See All

Comments


bottom of page