First we need to install the Guest Agent in our templates. Here I am just going through the Windows one. For Linux, please see my previous article : vRealize Automation 7 – Guest Agent.
Also for some strange reason, Linux always seem to be working whilst Windows is .. temperamental.
Guest Agent
First browse to the vRA appliance – specifically the software page
https://vra.www.open902.com/software/
Note: Download the Windows Guest Agent Files appropriate for the architecture of your server. This only applies if you ONLY intend to use the Guest Agent.
If you intend to use Software Components as well then please scroll down to the Software Components and use the Powershell script to prepare the template instead.
I want to keep the footprint as small as possible and therefore only install what is needed.
So here, for the sake of completeness – the Guest Agent only.
Running the .exe will just extract the packages to VRMGuestAgent
Move the folder to C:\
Open up a command prompt and navigate to the folder
Now install the service. Point it to the Manager Service – here I only got one IaaS server anyway.
WinService.exe -i -h iaas.www.open902.com:443 -p ssl
The above will not pull the appropriate IaaS certificate needed for secure communication.
Using the .pem file created during the installation process, copy it as cert.pem into the installation folder
If you don’t have a .pem – check out the article HERE – it describes how to download the certificate from the IaaS and convert it properly.
Now start the service
Once started …
.. check the logs
C:\VRMGuestAgent\axis2\logs\gugent-axis.log
Make sure you don’t see any errors but rather that the certificate was specified (something along those lines)
[Thu Nov 24 10:32:17 2016] [info] Starting addressing out handler [Thu Nov 24 10:32:17 2016] [debug] ..\..\src\modules\mod_addr\addr_out_handler.c(133) No action present. Stop processing addressing [Thu Nov 24 10:32:17 2016] [debug] ..\..\src\core\transport\http\sender\http_transport_sender.c(246) ctx_epr:https://iaas.www.open902.com:443/VMPS2 [Thu Nov 24 10:32:17 2016] [debug] ..\..\src\core\transport\http\sender\http_transport_sender.c(805) using axis2 native http sender. [Thu Nov 24 10:32:17 2016] [debug] ..\..\src\core\transport\http\sender\http_sender.c(416) msg_ctx_id:urn:uuid:b4c47fa3-5689-4fa2-bc3d-08f2a7e94bed [Thu Nov 24 10:32:17 2016] [info] [ssl client] Client certificate chain filenot specified [Thu Nov 24 10:32:17 2016] [debug] ..\..\src\core\transport\http\sender\http_transport_sender.c(822) OP name axutil_qname_get_localpart = http://www.w3.org/2004/08/wsdl/out-in [Thu Nov 24 10:32:17 2016] [debug] ..\..\axiom\src\soap\soap_builder.c(930) Identified soap version is soap11 [Thu Nov 24 10:32:17 2016] [debug] ..\..\src\core\engine\phase.c(210) Invoke the handler request_uri_based_dispatcher within the phase Transport [Thu Nov 24 10:32:17 2016] [debug] ..\..\src\core\engine\phase.c(210) Invoke the handler AddressingInHandler within the phase Transport
Also make sure the following logfile doesn’t have any errors
C:\VRMGuestAgent\GuestAgent.log
Again, you should not see any errors but a clean communication. The fact there isn’t a workitem means that essentially no install has been initiated by vRA
2016-11-24 10:35:49 Application: [Debug] Uninitializing subsystem: Logging Subsystem 2016-11-24 10:36:19 Application.MachineQuery: [Information] uuid = 9ed30742-2c69-a396-b004-cee2eeb5ef5a 2016-11-24 10:36:19 Application: [Information] Using the network enabled proxy ... 2016-11-24 10:36:19 Application: [Information] The vCAC endpoint is https://iaas.www.open902.com:443/VMPS2. 2016-11-24 10:36:19 Application: [Information] The AXIS2C directory is axis2/. 2016-11-24 10:36:19 Application: [Information] Requesting work for agent ID 4207d39e-692c-96a3-b004-cee2eeb5ef5a. 2016-11-24 10:36:19 Application: [Information] Fetching a work item ... 2016-11-24 10:36:19 Application.Proxy: [Information] 2016-11-24 10:36:19 Application.Proxy: [Information] No workitem currently available
So what is it good for ?
The Guestagent is used to customise the operating system after deployment.
This is not to be confused by the customization done by vCenter as part of the deployment.
The agent gives you the option to execute scripts – Powershell – Batch – Shell – anything really. The agent merely passes the commands from vRA through to the agent and executes them locally.
Let’s test it.
Here I created a simple script which puts the current date and time into a text file
date /T > c:\date.txt time /T >> c:\date.txt
Here an example when executed manually
Now shut the server down and prepare it for vRA. In my case I am using Linked Clones. So I will create a new Snapshot which I will be using in my Blueprint
Now re-run the Data Collection of your vCenter Resources to ensure vRA knows about the new Snapshot
If you are unsure how to create a Blueprint and Entitle it – see my previous article
vRealize Automation 7.2 – Blueprints and Entitlements
In order to utilise the guest agent we need to create a couple of Custom Properties.
- VirtualMachine.Customize.WaitComplete
- Set to True to prevent the provisioning workflow from sending work items to the guest agent until all customizations are complete
- VirtualMachine.Software0.Name
- Specifies the descriptive name of a software application
- VirtualMachine.Admin.UseGuestAgent
- If the guest agent is installed as a service on a template for cloning, set to True on the machine blueprint to enable the guest agent service on machines cloned from that template
- VirtualMachine.Software0.ScriptPath
- Specifies the full path to an application’s install script
Reference:
http://pubs.vmware.com/vrealize-automation-72/topic/com.vmware.ICbase/PDF/vrealize-automation-72-custom-properties.pdf
Rather than adding all the properties to every single Blueprint you want to utilise the script, create a Property Group
Example:
Now create a Blueprint
Here making sure I select a template / snapshot with the Gugent installed
Apart from the network of course, ensure you add the newly created Property Group
I will also add another Custom Property – Hostname – this allows me to specify a custom hostname – rather than using the pre-configured prefix.
Note: The VM MUST have network access (DNS is important !!) to the IaaS Manager Service. If the VM doesn’t have access to the VM, you will likely end up with a stale deployment. Whether or not it times out seems to be random – at least in my lab.
It needs more testing but it seems similar to previous vRA 7.x releases. If this happens to you – see my previous article in how to delete those state deployments. You can find the article HERE.
Pay special attention to the following comment as this is an easier procedure than described in my article:
Anyway, when requested, I can now enter a custom hostname
Now wait for the deployment to finish
Once finished you should be able to see that the script was executed and shows the time pretty close to the finished deployment
Software Components
Software Components are different and have a few more requirements.
If you intend to use Application Components then you need in addition to the Gugent also the Software Agent and Java.
From your template browse again to
https://vra.www.open902.com/software/
Download the Powershell script. No need to download the Guest Agent, the script will do this for you (and downloads the certificates required).
prepare_vra_template.ps1
Open a Powershell prompt and navigate to the location of the script and execute it using the below command.
Please Note: The Software page is missing the full path. If the command is executed without the full path, it is likely to fail.
PowerShell -NoProfile -ExecutionPolicy Bypass -Command c:\prepare_vra_template.ps1
Enter the FQDN / IP of your vRA appliance, Manager Service Server (IaaS) and the account the Management Agent runs under. Whether or not you use local or domain accounts obviously depend whether your deployed VM will be in the domain once done 🙂
Ensure the install completes successfully – shut down the template as instructed
Note: If you are using Full clones in vRA, prepare the server as template. If you are using Linked Clones, create a new Snapshot and run another data collection of the Compute Resources
Now back to vRA.
Browse to Software Components
First, here is the example – using Powershell throwing the bios information a text file
# List Bios Info into bios.log param( [string]$strComputer = "." ) $colItems = get-wmiobject -class "Win32_BIOS" -namespace "root\CIMV2" -computername $strComputer | Out-File c:\bios.log foreach ($objItem in $colItems) { write-host "Name :" $objItem.Name write-host "Version :" $objItem.Version write-host "Manufacturer :" $objItem.Manufacturer write-host "SMBIOSBIOS Version :" $objItem.SMBIOSBIOSVersion }
Which will output the follwing into a text file called bios.log
SMBIOSBIOSVersion : 6.00 Manufacturer : Phoenix Technologies LTD Name : PhoenixBIOS 4.0 Release 6.0 SerialNumber : VMware-42 07 2a 4e 9e dd 0f 9c-c0 2c b6 32 77 c3 5a 31 Version : INTEL - 6040000
Let’s do it.
Click New
Give it a Name
I don’t need to specify any properties for this simple script so I will skip it.
You could use a property for example to have the path (here c:\bios.log) made available during the request with the ability to change it.
But here, I just want a simple example so I won’t use any at this stage.
Here select powershell and Click here to edit.
Now paste the sample code and click OK > Finish
Make sure you Publish the Software Component
Now click Software Components. Select the newly created component BiosInfo and drag it onto the Virtual Machine
Now deploy the VM and wait for the deployment to finish
Apart from the obvious success, the existence of the Bios.log file we created …
… you can also confirm the success in the log file
C:\VRMGuestAgent\GuestAgent.log
2016-11-25 15:03:42 Application: [Information] Executing '10_finalize_noop.bat' ... 2016-11-25 15:03:42 Application: [Information] Wait for completion of '10_finalize_noop.bat' 2016-11-25 15:03:42 Application: [Information] Successfully sent the work item response for id=b1a9d74e-fa7a-4b05-b503-30d1eda6120e 2016-11-25 15:03:42 Application: [Information] c:\VRMGuestAgent\config.xml 2016-11-25 15:03:42 Application: [Information] found termination node 2016-11-25 15:03:42 Application: [Debug] Uninitializing subsystem: Logging Subsystem
If you don’t want to create your own Application Blueprints, have a look at VMware’s Solution Exchange, you can there download ready prepared blueprints, such as Microsoft SQL 2014.
Happy scripting 🙂