Issue with AzureRM.Profile Module

Hi

We have recently upgraded to Octopus 2018.5.0 and now using the web app deployment targets for Azure. This works well up until running a post deployment script to restart the Web app (Restart-AzureRmWebApp ). The error thrown seems to suggest a problem with the AzureRM.Profile module as shown below:

Hi Luke,

Thanks for getting in touch.

Unfortunately we’ve been unable to reproduce this. We’ve checked out the same 2018.5.0 tag and run the following on an Azure Web App, which runs successfully:

Write-Host "Restarting Azure Web App..."
Restart-AzureRmWebApp -Name markse-as1 -ResourceGroupName markse-as1
Write-Host "Done"

Could you confirm if you’re using the bundled PowerShell modules that come with Octopus, or are you overriding them with your own version?

There were some fixes released recently in 2018.5.6 to do with Azure PowerShell bundling, it may be worth upgrading to the latest and seeing if that helps.

If that doesn’t help, could you try adding that Import-Module AzureRM.Profile to the top of your post deployment script and see if that successfully imports … and if not, does the error message change at all?

Cheers
Mark

Hi Mark

Thanks for getting back to me, unfortunately still no luck after your suggestions. I have tried the following:

  • Upgraded to Octopus 2018.5.7
  • Added Import-Module AzureRM.Profile to the post deploy script (no change in error)

Regarding the bundling of PowerShell, we have not overridden those provided by Octopus but when running Get-Module –ListAvailable I do not actually see the Azure module - is this expected and loaded by Octopus elsewhere?

Hi Luke,

Thanks for the additional information.

Could you please confirm how you’ve got the post deployment script setup? Is this on your Azure Web App step, done via “Configure Features > Custom deployment scripts > Post-deployment script” (or is this a postdeployment script in your package?), or have you setup an additional step after your Azure Web App step?

If you could take a screenshot showing where and how your post-deployment script is defined, that may help us reproduce.

Octopus bundles the Azure PowerShell modules, so you shouldn’t need to install them, and they should definitely be listed out when you run that command. You should see something like this for starters:

Name              : Azure 
Path              : C:\Octopus\master\OctopusServer\Tools\Octopus.Dependencies.AzureCmdlets\5.7.0\Powershell\Azure\5.1.2\Azure.psd1 
etc.

Once we understand how your post-deployment script is setup, we may have a better angle on what’s going wrong.

Cheers
Mark

Hi Mark

Yes this is a custom deployment script with the PowerShell added as a post deployment script. There is no additional step and the entire deployment is contained in one Octopus step (to deploy the Azure site).

Below is the screenshot for listing all PS modules, should we perhaps try loading in the module manually?

Hi Luke,

Thanks for the additional information.

The Azure PS modules that come with Octopus are bundled as part of the step execution, so you won’t see them by running Get-Module -ListAvailable directly on the server (as they’re only loaded into the PowerShell context while the Octopus Azure step runs), but what you can do is run an Azure PowerShell script step inside Octopus (or do this in your pre/post-deployment script on your Azure Web App step as we’ve been trying).

Running this via an Octopus Azure PowerShell step should provide some clues…

Write-Host "##Finding AzureRM.Profile..."
Find-Module -Name "AzureRM.Profile"
Write-Host "--------"
Write-Host "##Listing all available modules..."
Get-Module -ListAvailable -Name Azure*

If that doesn’t return any information for the AzureRM.Profile module, then the bundled modules are not working for you and we’ll need to investigate further. Could we please get you to turn on variable logging for your project where this is failing, re-deploy and then export the raw task log, then attach the log to this ticket for us to investigate?

As a potential workaround, you could try installing your own version of the Azure Cmdlets on your Octopus Server and then set this project variable to use your own modules.

Cheers
Mark

For anyone else who has this “the module could not be loaded” error using AzureRm.Websites, I have managed to resolve it I believe.
We’re using Octopus 2020.5.1 running on Windows Server 2012 R2. I think the OS is the issue. It had Powershell 5.0 installed. I installed PowerShellGet:
Install-Module -Name PowerShellGet -Force
Then I tried:
Import-Module AzureRm.Websites
but that gave an error about “the variable ‘$psedition’ cannot be retrieved”. Turns out that the recent versions of AzureRm require Powershell 5.1. So after installing WMF 5.1 and rebooting the Octopus server it seems to be working.