We are creating a multi-tenant application and hosting it on Window Azure IaaS platform.
We want to provision and configure all our virtual machines remotely using PowerShell.
We don't want to RDP into VMs for any configuration.
Does Azure VMs support start up tasks to execute power shell scripts similar to Web-Role and Worker-Role?
If no, then are there any alternatives available (tools like PsExec) which can help in executing start-up scripts?
Your VM's are just virtualized Windows/Linux machines and this support start-up tasks as per usual.
For Windows VM's, you'll need to:
Download the base Azure Windows Server guest VM.
Customize the machine's startup process to execute a startup script.
Push your customized VM back up into Azure.
Configure Azure to start your customized VM.
Note: You can also access PowerShell on a remote VM using PowerShell remoting in a similar manner to how one uses SSH to access the console of a remote [LI|U]N[U|I]X box/VM.
FWIW, Git is a great tool to use to pull down and execute a VM config script: Your on-VM startup script can use Chocolatey to install the latest version of GIT (if it's not already installed) and then use Git to pull down the latest version of your startup script from GitHub/similar and execute it. This way you don't need to continually rebuild VM images every time your scripts change.
Related
We have source code with combination of .net 4.0 and C++ (CLI C++). To build this code we use visual studio 2015 and visual studio 2010 both at the same time. To build the C++ source code we using VS 2010. Now as we are migrating to azure devops we need create build pipelines. One way to achieve this is to create a self hosted windows agent and install vs 2015 and vs 2010 on it.
Is there a way to make this containerized? Can we create a custom container image with vs 2015 and vs2010 already installed?
You can use docker inside virtual machine for containerization, You can set up a self-hosted agent in Azure Pipelines to run inside a Windows Server Core (for Windows hosts), or Ubuntu container (for Linux hosts) with Docker. This is useful when you want to run agents with outer orchestration, such as Azure Container Instances.
Both Windows and Linux are supported as container hosts. Windows containers should run on a Windows vmImage. To run your agent in Docker, you'll pass a few environment variables to docker run, which configures the agent to connect to Azure Pipelines or Azure DevOps Server. Finally, you customize the container to suit your needs. Tasks and scripts might depend on specific tools being available on the container's PATH, and it's your responsibility to ensure that these tools are available.
Here is the reference doc https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops
As per my knowledge number of container we run inside the VM is completely depends on the VM size( hardware configuration)we choose. we do have different VM size available in azure.
if you want to run more containers, I would recommend to go with AKS,Azure Kubernetes Service (AKS) simplifies deploying a managed Kubernetes cluster in Azure by offloading the operational overhead to Azure. As a hosted Kubernetes service, Azure handles critical tasks, like health monitoring and maintenance. Since Kubernetes masters are managed by Azure, you only manage and maintain the agent nodes. Thus, AKS is free; you only pay for the agent nodes within your clusters, not for the masters.
Need to create azure devops windows self-hosted agents programmatically (Need to install Remotely for the existing VM).
I have PS script and it is working well if i run it (as admin) inside the virtual machine and agent is getting installed successfully. But i want to create this agent for the existing VM without logging in (Remotely i need to install the agent), because i will need to just add the ARM template in Azure devops pipeline and that should create the Agent for the existing VM.
As this needs to be installed remotely and securely, i shouldn't use custom script due to some restrictions.. It would be really great if we can achieve this installation remotely without custom script and using any other automated way.
Any information will be helpful, thanks.
I have found out a way using Run-Command. This is another helpful option to run the PS scripts remotely on a Virtual machine. In addition, this executes the script with elevated permissions which is really helpful in many scenarios.
Source: https://learn.microsoft.com/en-us/azure/virtual-machines/windows/run-command#powershell
This can be performed using via Portal, Powershell and CLI as well.
I have been told that there is another way to access an Azure VM without using RDP. What other ways are out there?
You can use Azure Cloud Shell to work with any WM using the command line (bash for Linux VMs and PowerShell for Windows WMs)
You can find common info about Azure Cloud Shell usage here: Overview of Azure Cloud Shell
Connection flow for Windows WMs here: Interactively log on to a remote VM
Connection to Linux VM here: SSH into your Linux VM
Just to add to existing answer, all the regular ways to manage virtual machines are available (winrm\ssh), you can also use custom script extension to run command on your virtual machines without exposing management endpoints on those vm (more secure, but less trivial).
You can also use Invoke-AzVmRunCommand\az vm run-command invoke to run commands on the vm directly (similar to custom script extension).
Reading:
https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows
https://learn.microsoft.com/en-us/cli/azure/vm/run-command?view=azure-cli-latest
https://learn.microsoft.com/en-us/powershell/module/az.compute/invoke-azvmruncommand?view=azps-1.3.0
I have a number of VMs provisioned in my Azure subscription, protected by an NSG, so I don't have WinRM available remotely.
I'd like to execute a PowerShell script on these VMs as part of my TFS release definition.
Is there any way to execute arbitrary PowerShell scripts on Azure VM resources?
I'm aware of the Custom Script extension for Azure VM resources, but I don't know if this is what I'm after, or if it plays nicely with TFS.
Custom Script Extension would work fine for running scripts on the VM - but it would have to be done as part of "adding" the extension. Meaning you'd have to deploy the extension to the VM to trigger running the script. So you'd do it when the VM is provisioned or submit another deployment to run the script after it's provision.
Either is doable from TFS/VSTS...
I am new to azure RM model.Please help me to copy and install an exe in VM created in resource manager portal using powershell script or using API. Thanks in advance.
If you want to do the install the EXE remotely then the VM needs to be configured to allow for remote management - you can do this via WinRM. See: https://www.penflip.com/powershellorg/secrets-of-powershell-remoting/blob/master/accessing-remote-computers.txt and http://tarkus.me/post/64761019099/windows-azure-vms-remote-management
Setting this up is non-trivial (you need to ensure it's secure). You could also try adding an VM extension to the VM that will do the copy. Since the VM is already provision I think the only option here would be to use DSC though I've never added a DSC extension to a VM post-provisioning, it should work. That would require authoring and staging a DSC script in addition to adding the extension but definitely less complex than enabling remote management.
Simplest by far is as Gaurav suggested and log on to the VM and copy from there.