Search code examples
bashpowershellazure-automationazure-runbookhybrid-runbook-worker

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?


Solution

  • 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!!