Friday, January 6, 2017

Running AzurePS on Linux with Docker

I decided to play around with my linux box a bit today, and needed a project to help me on my way. Previously, I had fooled around with the azure-cli on Linux, but didn't really like the experience at all. Since Microsoft has made a big push into the world of linux, I decided to take a look at how I could install the Azure powershell on my linux box.

In order to further complicate my life, I did not want to "sully" my main operating system.  Docker is a good way for keeping some isolation between the tests that I do, and so, I decided to install Azure PS on a docker container.

First things first, I am running fedora 25 on my desktop.  Installing docker was pretty easy, especially if you use their get script.  I downloaded it first and had a boo, I hate the move these days to encouraging admins to run downloaded files directly from the internet in a root term.

Step 1)  Installing Docker on Fedora

You can find more information on how to install docker on Fedora here.

Be sure to go through the entire install process and add your regular user to the docker group (that you end up creating).  This is a good idea so you don't have to run every terminal as root.

Step 2)  Pulling a base image

Once docker is installed, you will need to pull a base image to work with.  The powershell-core team has released an installer for centos, but nothing for fedora.  Don't get me wrong, I tried installing it on Fedora but ran into dependency hell.  Most of the solutions on the internet were pointing at downloading the icu lib from some 3rd party repos and installing it so you had the correct version.  No thanks.

I decided to backtrack and install the centos build.

 docker pull 

Step 3) Installing Powershell in the docker image

The next step is to run the centos image in interactive mode so you can start to manipulate it.

 docker run -i -t 

You will want to download the powershell rpm.  You can find that here.  I had already previously downloaded it so I used the "docker cp" command to copy it into my running container.

Follow the instructions for installing the powershell rpm, which can be found here.

Step 4)  Test Powershell

Once you have powershell installed, run powershell from the command line to see it pop open.  Quick note, SELinux was complaining to me as soon as I ran this command.  It seems that powershell requires use of the "getsession" object, which it objected to.  I ran the recommend commands (which essentially look at the denials and issue grants for them).

After this, I see powershell, and could run commands!

Pretty neat!

Step 5)  Install Azure Modules

If you were under a rock for the last few months (like me) you would have probably missed that there are now two versions of powershell, desktop and core.  Core is not to be confused with Windows Server Core, which actually runs powershell desktop (sigh!).  The core (argh!) difference is that one is built to run on .NET core and the other requires the full .NET.  You can see more here.

It is important to note at this point that the main Azure modules require powershell desktop, and are not compatible with core.  You need to install a different set of Azure modules that were designed for core.  Spoiler alert, not all the modules are there at time of writing.  You can find the instructions for installing the core version of the Azure modules here.

Step 6) Profit

Well not really.  After you get everything installed and in your path, you should be able to run the AzureRM commands from the powershell prompt from your linux box. (That previous sentence was not even conceivable 5 years ago).

And there you go!  You are ready to rock.  If you want to skip all the pain and download my version, you can by pulling from my docker repo.