VMware Aria Automation Orchestrator

 View Only

 Host profile remediation via Orchestrator workflow

Mafriea's profile image
Mafriea posted May 27, 2024 07:22 AM

Hello everyone,

I'm looking to use the Vmware Aria Automation Orchestrator (only the Orchestrator, without Aria Automation) to attach a specific host profile to a host, perform the host customization and remediate the host. The Host profile only includes settings to make the installation stateful, to set the password and to configure the vSwitch (hence the host customization, the host needs the IP address, the subnet mask and the hostname).

However, during the remediation process I constistently encounter the error message "Cannot apply the host configuration" with "Error: filename must be a str or bytes object, or a file".

When I attach and customize the profile via the workflow, but perform the remediation manually, it works without any issues, so I guess the host customization via workflow works (and is valid according to the workflow "Get answer file status") and the problem must be the remediation.

I would appreciate any insights on the requirements for a successfull remediation through a workflow. How can i successfully implement this process?

Here's a brief overview over my implementation:

Host customization (vmHost = HostSystem input, vmHostName = String input, esxSubnet = String input, esxIp = String input); the code was mostly generated using code capture in vCenter 7.0.3) :

var sdkConnection = vmHost.sdkConnection
var hostProfileManager = sdkConnection.hostProfileManager

var hostToConfigSpecMap = new Array();
hostToConfigSpecMap[0] = new VcHostProfileManagerHostToConfigSpecMap();
hostToConfigSpecMap[0].configSpec = new VcAnswerFileOptionsCreateSpec();
hostToConfigSpecMap[0].configSpec.validating = true;
var userInput = new Array();
userInput[0] = new VcProfileDeferredPolicyOptionParameter();
userInput[0].inputPath = new VcProfilePropertyPath();
userInput[0].inputPath.policyId = 'HostNamePolicy';
userInput[0].inputPath.profilePath = 'network.GenericNetStackInstanceProfile["key-vim-profile-host-GenericNetStackInstanceProfile-defaultTcpipStack"].GenericDnsConfigProfile';
var parameter = new Array();
parameter[0] = new VcKeyAnyValue();
parameter[0].value = vmHostName;
parameter[0].key = 'hostName';
userInput[0].parameter = parameter;
userInput[1] = new VcProfileDeferredPolicyOptionParameter();
userInput[1].inputPath = new VcProfilePropertyPath();
userInput[1].inputPath.policyId = 'IpAddressPolicy';
userInput[1].inputPath.profilePath = 'network.hostPortGroup["key-vim-profile-host-HostPortgroupProfile-ManagementNetwork"].ipConfig';
var parameter = new Array();
parameter[0] = new VcKeyAnyValue();
parameter[0].value = esxSubnet;
parameter[0].key = 'subnetmask';
parameter[1] = new VcKeyAnyValue();
parameter[1].value = esxIp;
parameter[1].key = 'address';
userInput[1].parameter = parameter;
hostToConfigSpecMap[0].configSpec.userInput = userInput;
hostToConfigSpecMap[0].host = vmHost
task = hostProfileManager.updateHostCustomizations_Task(hostToConfigSpecMap);
The host customization shows up correctly in the UI and is considered 'valid' by the workflow, as mentioned above.
Remediation (assuming the profile was already attached; vmHost is the hostSystem input):
var sdkConnection = vmHost.sdkConnection
var hostProfileManager = sdkConnection.hostProfileManager

var profile = hostProfileManager.findAssociatedProfile(vmHost)[0]
var profileExecuteResult = profile.executeHostProfile(vmHost);
task = hostProfileManager.applyHostConfig_Task(vmHost,profileExecuteResult.configSpec, profileExecuteResult.requireInput);
Thank you in advance for your assistance!
Best regards
WhiteForEver's profile image
WhiteForEver

Hi.

Following the API documentation, the executeHostProfile requires two arguments:

  1. VcHostSystem (provided)
  2. Array/VcProfileDeferredPolicyOptionParameter (missing)

Can you please try to update this: 

var profileExecuteResult = profile.executeHostProfile(vmHost, userInput);

If that will not help, I can try to setup some quick test environment and run it there.

Mafriea's profile image
Mafriea

Hi,

thanks for the advice!

I've added the argument like you've described, but I get the same error as always. I've also tried adding the variable userInput to hostProfileManager.applyHostConfig_Task directly (hostProfileManager.applyHostConfig_Task(vmHost,profileExecuteResult.configSpec, userInput);) but that didn't work either.

WhiteForEver's profile image
WhiteForEver

No problem.

I will spin up some test env to take a look on. I am OOO for a few days. Will do that once will come back if that's not urgent.

WhiteForEver's profile image
WhiteForEver

Hi.

So, your code is working for me (output log is below). As is. I never get this error you have mentioned. "Error: filename must be a str or bytes object, or a file".

I am testing it on vCenter 8U2, ESXi 7.0.3 and vRO 8.17.0

2024-06-03 13:05:12.153 +02:00info__item_stack:/item1
2024-06-03 13:05:12.202 +02:00infoupdateHostCustomizations/session[52c310c3-f67a-28c9-a7ef-e51cf8b228c7]52b8f9c4-af6c-5569-4a79-7ab2d4f44694 running 0 %
2024-06-03 13:05:14.210 +02:00infoupdateHostCustomizations/session[52c310c3-f67a-28c9-a7ef-e51cf8b228c7]52b8f9c4-af6c-5569-4a79-7ab2d4f44694 running 0 %
2024-06-03 13:05:16.220 +02:00infoupdateHostCustomizations/session[52c310c3-f67a-28c9-a7ef-e51cf8b228c7]52b8f9c4-af6c-5569-4a79-7ab2d4f44694 ends with success
2024-06-03 13:05:16.228 +02:00infoprofile: DynamicWrapper (Instance) : [VcHostProfile]-[class com.vmware.o11n.plugin.vsphere_gen.HostProfile_Wrapper] -- VALUE : Stub: moRef = (ManagedObjectReference: type = HostProfile, value = hostprofile-3, serverGuid = null), binding = https://vcenter:443/sdk
2024-06-03 13:05:19.468 +02:00infoupdateHostCustomizations/session[52c310c3-f67a-28c9-a7ef-e51cf8b228c7]52b8f9c4-af6c-5569-4a79-7ab2d4f44694 ends with success
2024-06-03 13:05:19.519 +02:00infoapplyHostConfiguration/task-29005 running 0 %
2024-06-03 13:05:21.528 +02:00infoapplyHostConfiguration/task-29005 running 0 %
2024-06-03 13:05:23.536 +02:00infoapplyHostConfiguration/task-29005 running 0 %
2024-06-03 13:05:25.547 +02:00infoapplyHostConfiguration/task-29005 running 0 %
2024-06-03 13:05:27.556 +02:00infoapplyHostConfiguration/task-29005 running 0 %
2024-06-03 13:05:29.570 +02:00infoapplyHostConfiguration/task-29005 ends with success
2024-06-03 13:05:29.580 +02:00info__item_stack:/item0

The only thing I did update, is a hostname setting in the exported profile itself to the selected on below. Otherwise, it is not possible to set the hostname.

If you have more details or the error stack you can share, I can try to take a look deeper.