Azure Octopus VM Extension

Hi,

i am trying to install the Octopus Tentacle VM Extension to an Azure VM in our DevTestLab.
When i use the powershell commands like in your documentation (https://octopus.com/docs/installation/installing-tentacles/azure-virtual-machines/via-powershell) it fails with the following error:

Cannot bind parameter ‘Settings’. Cannot convert the
"{“OctopusServerUrl”: “”, “Environments”: [
""], “Roles”: [ “” ], “CommunicationMode”: “Listen”,
“Port”: 10933 }" value of type “System.String” to type
"System.Collections.Hashtable".
At C:\Users\jenkins\AppData\Local\Temp\jenkins3178889207261319953.ps1:19
char:15

  • -Settings $publicSettings `
    
  •           ~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [Set-AzureRmVMExtension], P
      arameterBindingException
    • FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.C
      ommands.Compute.SetAzureVMExtensionCommand

When changing the declaration of the variable $publicSettings, to cast it to a hashtable like:

$publicSettings = @“
OctopusServerUrl=
Environments = {”"}
Roles = {""}
CommunicationMode = Listen
Port = 10933
"@

$hash = ConvertFrom-StringData -StringData $publicSettings

this error occurs:

ErrorCode: VMExtensionProvisioningError
ErrorMessage: VM has reported a failure when processing extension ‘OctopusDeployWindowsTentacle’. Error message: “System.InvalidCastException: Unable to cast object of type
’Newtonsoft.Json.Linq.JValue’ to type ‘Newtonsoft.Json.Linq.JArray’.
at AzureVMExtension.Configuration.ApplicationConfig.GetPublicArraySetting(JToken publicSettings, String property) in
Z:\buildAgent\workDir\8d5946312b69ad91\src\AzureVMExtension\Configuration\ApplicationConfig.cs:line 158
at AzureVMExtension.Configuration.ApplicationConfig.ParseFile(String filename) in Z:\buildAgent\workDir\8d5946312b69ad91\src\AzureVMExtension\Configuration\ApplicationConfig.cs:line 74
at Polly.RetrySyntax.<>c__DisplayClass10_0.b__1() in C:\projects\polly\src\Polly.Shared\RetrySyntax.cs:line 211
at Polly.Retry.RetryEngine.Implementation[TResult](Func1 action, IEnumerable1 shouldRetryExceptionPredicates, IEnumerable1 shouldRetryResultPredicates, Func1 policyStateFactory) in
C:\projects\polly\src\Polly.Shared\Retry\RetryEngine.cs:line 40
at Polly.RetrySyntax.<>c__DisplayClass10_1.b__0(Action action, Context context) in C:\projects\polly\src\Polly.Shared\RetrySyntax.cs:line 210
at AzureVMExtension.Configuration.ApplicationConfig.Parse(String configFolder, Int32 sequenceNumber) in
Z:\buildAgent\workDir\8d5946312b69ad91\src\AzureVMExtension\Configuration\ApplicationConfig.cs:line 47
at AzureVMExtension.Program.Execute(String[] args) in Z:\buildAgent\workDir\8d5946312b69ad91\src\AzureVMExtension\Program.cs:line 75”.
StartTime: 04.10.2017 14:52:54
EndTime: 04.10.2017 14:53:29
OperationID: f72fc0f6-a803-4da5-b9b2-a7a1b17a02cb
Status: Failed
In Zeile:28 Zeichen:1

  • Set-AzureRmVMExtension -ResourceGroupName $resourceGroup `
  •   + CategoryInfo          : CloseError: (:) [Set-AzureRmVMExtension], ComputeCloudException
      + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.SetAzureVMExtensionCommand
    
    
    

Would be very happy if you could give me a working example of how this parameter $publicSettings should look like.

So the thing seems to be with the conversion from the string to hashTable.

$publicSettings = “{"OctopusServerUrl”: "https://octopus.example.com", "Environments": [ "Env1", "Env2" ], "Roles": [ "app-server", "web-server" ], "CommunicationMode": "Listen", "Port“: 10933 }”

I tried it with this approach:
$publicSettings = @“
OctopusServerUrl=
Environments = [ "<env1>" ]
Roles = [ "<role1>" ]
CommunicationMode = Listen
Port = 10933
”@

$hash = ConvertFrom-StringData -StringData $publicSettings

but then again an error is shown, because Environments / Roles need to be Arrays.
Error:

Error message: "System.InvalidCastException: Unable to cast object of type
’Newtonsoft.Json.Linq.JValue’ to type ‘Newtonsoft.Json.Linq.JArray’.

If somebody could give me a working example how this parameter should look like…

Finally i found a solution which works:

$publicSettings = @{“OctopusServerUrl”=""; “Environments” = “”, “” ; “Roles” = “”, “”; “CommunicationMode”=“Listen”; “Port”=“10933”}

Hi there!

Thanks for letting us know you’ve solved it - as you’ve seen the best way is to declare a Hashtable literal rather than trying to cast in from a string.

regards

Jason

Yes seems to be.
Just to let you know – it worked only for me when i passed two environments and 2 roles.
Otherwise i could not get it to work that these two where interpreted as „Array“ like expected.

Sorry if it’s just a silly little error, i am relativly new to writing powershell scripts.

Best,
Stefan!

Von: Jason Brown [mailto:tender2+dc21207349@tenderapp.com]
Gesendet: Donnerstag, 5. Oktober 2017 09:18
An: Stefan Fellner s.fellner@kon-cept.at
Betreff: Re: Azure Octopus VM Extension [Problems #59984]