Installing 64 Bit software with Guest Agent in vCAC 5.2
So you have set up your vCloud Automation Centre, followed the guide, put in multiple hours creating the enterprise groups, provisioning groups, reservations, blueprints, etc. Heck you have even customized / created some of the vCAC’s workflows and now, you just want to install some software after the machine is provisioned, you decide to use the Guest agent on windows. You followed some guides (i.e. The Operating guide) or this blog
You have edited the InstallSoftware.js file (detailed in the above mentioned link) So for so good … You have for the testing purposes created a set of custom properties like given in sample and you are able to create the “Hello World “ Batch file (some thing that’s described here )
Now, you walk up to your boss and say, hey its ready! The system can now be used, your boss smiles at you happily and says, Excellent! please create a script that installs IIS 7 on the Windows 2008R2 server, we need to start with those. You happily write a Powershell script to do so and put that in the software0.install property, etc and when you run … BAM!! it fails!
You try, then retry and then try again. It fails all the times, you modify the script several times, you test that the script works when you execute by hand, but some thing goes wrong when the system try’s to invoke it, you are certain this gets invoked (you log that ), but it doesnt work, you are bewildered and Googling for help, and may be then you come across this blog ;)
Ok, I know the above was a little too melodramatic, however, the fact of the matter is this. If you try to invoke any 64 bit program using the vCAC Guest agent, it will FAIL :)
Please note that this is true in vCAC 5.2, hopefully they will fix it in vCAC 6. But, if you are using it and its failing, look no further, you are very close to the solution … Read On …
The Reason
vCAC Guest Agent is a scripting agent, which means what ever you throw at it, it will execute without rhyme and reason (The only reason being that, you as an administrator told it to do so). Also, its worth noting that the agent itself is written in C++ and compiled as 32 bit. Any command that you invoke using a 32 bit software will also be 32 bit. So when you launch powershell using the guest agent to install IIS, it launches the 32 bit version of powershell and that wont be able to load the 64 bit server manager module. Hence the entire problem. Now, there is no way to change this default behaviour, because of the WOW64 (Windows On Windows), I am sure you guys have seen this folder. Please remember that when a 32 bit application makes a call, the WOW system intercepts it and invokes the executables in the %SystemDrive%Windows\SysWow64 rather than the %SystemDrive%Windows\System32 folder (which is used when you using 64 bit applications). It is marvelous that windows does this, but that prohibits us from being able to launch 64 bit applications.
Ok, now you know the problem and the reason, now for the solution. The solution is in fact is very simple. I wrote a code which i call posh64.exe, which can be invoked from 32 bit / 64 bit but will run the 64bit powershell. I am going to give you the download link of the exe in this blog, but as this blog is for the curious, here is how I wrote it
Writing Posh 64
Open Visual Studio, Select New Project –> Windows Console Application (C#)–> Choose framework (I chose framework 2, which will be available by default on most windows machines) and I wrote this in the code
1: using System;
2: using System.Diagnostics;
3:
4: class Program
5: {
6: static int Main(string[] args)
7: {
8: var p = new Process();
9: p.StartInfo = new ProcessStartInfo("PowerShell.exe", String.Join(" ", args))
10: {
11: UseShellExecute = false
12: };
13:
14: p.Start();
15: p.WaitForExit();
16:
17:
18: return p.ExitCode;
19: }
20: }
20 lines of code (Actually less). So what does this do, just starts powershell.exe with the parameters that you pass to this application. Please note there is no error check or correction, as this is just meant to be a wrapper. If you want to put those, then its fine, feel free, how ever, this is not where the magic happens. If you just compile the above with default settings you will be again left with the same problem.
Open the build property and choose the platform target as x64 (default will be Any CPU)
Now you can execute the code, and this will ONLY invoke 64 bit applications. You can bake the posh64.exe in your template and then use it like this
Invoke a Powershell script (64 bit)
posh64.exe <powershell script name> < powershell script arguments>
Invoke a Command Prompt (64 bit)
posh64.exe cmd.exe /c <what ever you want to invoke at the command line>
Invoke a Powershell Script (32 bit) – I am not sure why would any one want to do this
posh64.exe cmd.exe /c c:\windows\syswow64\powershell.exe <powershell script name > <powershell script arguments>
You get the picture!
Enjoy
For people who don’t want to write this, here is the link to the posh.exe
I hope you like it. Also, please let me know in the comments if you have questions! Merry Christmas !
This comment has been removed by a blog administrator.
ReplyDelete