How to install IIS on Azure Windows VM using Azure Cli - windows

After Running this command on Azure Cli:
az vm extension set --publisher Microsoft.Compute --version 1.8 --name CustomScriptExtension --vm-name avmUat --resource-group argUat --settings '{"commandToExecute":"powershell.exe Install-WindowsFeature -Name Web-Server"}'
I get this error
Deployment failed. Correlation ID:
8d6972da-6d46-42e8-a053-f8e899348893. VM has reported a failure when
processing extension 'CustomScriptExtension'. Error message: "Invalid
handler configuration. Exiting. Error Message: Error converting value
"{commandToExecute:powershell.exe Install-WindowsFeature -Name
Web-Server}" to type
'Microsoft.WindowsAzure.GuestAgent.Plugins.CustomScriptHandler.PublicSettings'.
Path 'runtimeSettings[0].handlerSettings.publicSettings', line 5,
position 102.".
Edit:
The result when I run it in powershell on Azure Cloud Shell:
Bash and this is on bash (Gladly it worked)

It seems that these commands do not work in the Azure CLI locally on the windows command prompt. You should run these on a bash environment.
With the same Azure CLI version. The same commands could work in Azure cloud Shell but not local Azure CLI in command prompt. I also tried running it on local Azure CLI 2.0.58, still failure.
Moreover, Here is the same Sample script, which is running in a bash environment.
Run this on my local command prompt.
Run it on Azure Cloud Shell

Related

debug azure webapp using ssh

I am working on a new webapp in azure cloud.
The challenge is that I am working on a new python module that I dont know that well, Pyspice. Pyspice interface to a program Ngpspice.
On my windows PC it works fine but not on the cloud. So I would like to be able to do debugging without pushing and then wait 25min for each build.
Right now I am using SSH to connect to the webapp. Then I can create a simple python script to see if I can get the connection to work between pyspice and ngspice. The challenge I have is that when I run python in SSH then it uses a different environment than the webapp, i.e. all the modules in the requirements.txt is not available. So how can I change environment to be able to debug?
I have created an Azure App service with Python version 3.8, when I check the version in Azure SSH it is showing me different version.
To install the latest version in Azure SSH, run the below command
apt update
apt install python3.9
python --version
Run the below command to change the python version of the Azure App service in Azure Cloud Shell (Bash).
az webapp config set --resource-group MyRGName --name WebAppName --linux-fx-version "PYTHON|3.9"
To check the updated version, run the below command
az webapp config show --resource-group MyRGName --name Python4Nov --query linuxFxVersion
debug azure webapp using ssh
To remote debug Azure Linux App Service, we need to open a TCP Tunnel from the development machine to Azure App Service.
Configure for SSH and Remote Debugging
In Azure CLI run the below command
az webapp create-remote-connection --resource-group MyRG -n WebAppName
References taken from MSDoc

Windows Container Access is denied. (0x5). using Powershell. But still accessible on Docker Desktop CLI tool

I am running a docker-compose up and spinning up my Windows containers. Then I want to attach to a container.
I tried docker attach <container id>, but it crashes the entire docker container for whatever reason. Then, I tried docker exec <container name> C:\ to login to C:\.
This gives me the error: container 8504af497601933a0c2e7126e00665da77b9fa71db03c37ce30eb5fa94ee2ee6 encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: Access is denied. (0x5)
On my Windows 10 machine, I can still access the CLI for the containers using Docker Desktop (even though its inaccessible through CLI), however, I need to use CLI to access it on my Windows Server 2019 machine. I've tried C:\, C:\Users, etc , and they all give the same error.
I was running this erroneous command:
&$Env:ProgramFiles\Docker\docker run hello-world:nanoserver .
Which resulted in:
docker: Error response from daemon: container encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: Access denied. (0x5).
This is due to . after hello-world:nanoserver which specify the shell to use. The error Access denied was coming from inside the container I think.
So try to check if you are specifying a shell which is incorrect.

Teamcity and AWS CLI

I am running Teamcity on a windows VM and have installed the awscli.
I am trying to pull a zip from aws S3. But I get this error:
" aws : The term 'aws' is not recognized as the name of a cmdlet, function, script file"
When I run the command in both cmd and powershell it works just fine.
I have also checked that the awscli path is in both user and system paths.
Any ideas?
I figured it out.
The build agent was not running as a service and was running as a user account that didn't have the correct permissions. Installed a new agent, ran it as a windows service and as a service account.
I hope this helps someone in the future that faces this frustrating issue.

Execute bash commands on Azure Linux VM using azure automation

I need to install software on Azure VM with Ubuntu image. One way of manually doing it is ssh into the terminal using putty or other command-line tool and executing the installation bash command. Another way of doing it was by automating this by creating a bash script and calling it from Azure automation. But I unable to find a way to call the bash script from the azure automation runbooks. Kindly let me know if this is possible.
I am able to call powershell scripts because Azure Automation supports powershell by default.
I tried using the command New-SshSession and using Invoke-SshCommand to run my command but I get the below error while trying to connect to a session.
Also, what are the prerequisites for using New-SshSession (see below)?
New-SshSession -ComputerName 'ComputerName' -Username 'UserName'
Unable to create SSH client object: Exception calling ".ctor" with "4" argument(s): "Could not load type 'System.Security.Cryptography.HMACRIPEMD160' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral,
Are there any prerequisites before I should start using New-SshSession? Do I need to install any .Net library on my linux machine?
Welcome to Stack Overflow!!
If the requirement was for Windows VM then it would have been easy by leveraging Invoke-AzVmRunCommand cmdlet but as requirement is for Linux VM so looks like the comment (with sample script) provided by Azure Automation team content author in this GitHub helps you to accomplish your requirement of executing bash commands on Azure Linux VM using azure automation.
Hope this helps!!

Azure xplat to run a CustomScriptExtension in a Windows VM

I am creating Windows VMs from the azure xplat cli, using the following command:
azure network vnet create --location "East US" testnet
azure vm create --vm-name xplattest3 --location "East US" --virtual-network-name testnet --rdp 3389 xplattest3 ad072bd3082149369c449ba5832401ae__Windows-Server-Remote-Desktop-Session-Host-on-Windows-Server-2012-R2-20150828-0350 username SAFEpassword!
After the Windows VM is created I would like to execute a powershell script to configure the server. As far I understand, this is done by executing a CustomScriptExtension.
I found several examples for PowerShell but no examples for Xplat cli.
I would like, for example, to run the following HelloWorld PowerShell script:
New-Item -ItemType directory -Path C:\HelloWorld
After reading documentation I should be able to run a CustomExtensionScript by executing something like this (the following command does not work):
azure vm extension set xplattest3 CustomScriptExtension Microsoft.Compute 1.4 -i '{"URI":["https://gist.githubusercontent.com/tk421/8b7dd37145eaa8f82e2f/raw/36c11aafd3f5d6b4af97aab9ef5303d80e8ab29b/azureCustomScriptExtensionTest"] }'
I think that the problem is the parameter -i. I have not been able to find an example on Internet. There are some references and documentation such as MSDN and Github, but no examples.
Therefore, my question: How to execute a PowerShell script after creating a Windows VM in Azure using the xplat cli ?
Please note that the my current approach is a CustomScriptExtension, but anything that allows to bootstrap a configuration script will be considered!
EDIT How do I know it is failing ?
After I run the command azure vm extension ...:
xplat cli confirms that the command has been executed properly.
As per MSDN documentation, the folder C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\ is created, but there is no script downloaded to C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\{version-number}\Downloads\{iteration}
The folder C:\HelloWorld is not created, which means that the contents of the script has not been executed.
I cannot find any sort of logs or a trace to know what happened. Does anyone knows where can I find this information ?
The parameters (The Json) that I used after reading the MSDN documentation were not correct. However, you can get clues of the correct parameters by reading the C# code.
And the final command is:
azure vm extension set xplattest3 CustomScriptExtension Microsoft.Compute 1.4 -i '{"fileUris":["https://macstoragetest.blob.core.windows.net/testcontainername/createFolder.ps1"], "commandToExecute": "powershell -ExecutionPolicy Unrestricted -file createFolder.ps1" }'
This command successfully creates the C:\HelloWorld directory.
NOTE: I decided to upload the script to Azure as I read in a post and in the documentation that is mandatory. However I just made a test to download the original script from Github and it is working fine, so I guess that the documentation is a bit outdated.
EDIT: I created an detailed article that explains how to provision windows servers with xplat-cli in Azure.

Resources