Hello Erik Burmester,
Greetings! Welcome to Microsoft Q&A Platform.
Automating the provisioning of a Windows Server-based Virtual Machine in Azure using Ansible and applying a custom product key is indeed possible.
You can create an Ansible playbook to provision the VM in Azure. The playbook would include tasks to create a resource group, virtual network, subnet, public IP, network security group, and the VM itself -
https://learn.microsoft.com/en-us/azure/developer/ansible/vm-configure-windows?tabs=ansible
If you have Windows Server
license, you can use the same key in an Azure VM
by selecting the Hybrid Benefit
option while creating the Azure VM
, this will save up to 49% with a license if you already have a Windows license.
After the VM is provisioned, you can use a PowerShell script to change the product key. The Set-WindowsProductKey cmdlet from the DISM PowerShell module can be used to set the product key for the Windows image. Alternatively, you can use the slmgr.vbs script to change the product key.
To automate this process with Ansible, you can use the azure_rm_virtualmachineextension module to run the PowerShell script as a custom script extension on the VM.Please ensure you have the necessary permissions and that your Ansible control node is set up correctly to communicate with Azure VMs using WinRM.
As for the costs, using your own product key with the Azure Hybrid Benefit should indeed affect the costs positively by reducing them, as long as the VM size and usage are eligible for the benefit. Always use the Azure pricing calculator to estimate and manage costs effectively- https://azure.microsoft.com/en-us/pricing/calculator/.
Try to create and build Windows/Unix servers using an Azure DevTest Labs. Azure DevTest Labs is a service that helps developers and testers quickly create environments in Azure while minimizing waste and controlling costs. You can use Azure DevTest Labs to create and manage virtual machines (VMs) running Windows or Linux, and you can also use it to create custom images that can be used to create new VMs.
Ref: https://learn.microsoft.com/en-us/azure/devtest-labs/devtest-lab-overview
https://learn.microsoft.com/en-us/azure/devtest-labs/devtest-lab-add-vm
To manage other target hosts using Ansible and PowerShell scripting, you can set up an Ansible controller on one of your VMs in Azure DevTest Labs, and use PowerShell to manage other target hosts. Once you have set up your Ansible controller, you can use PowerShell to manage other target hosts.
Hope this answer helps! Please let us know if you have any further queries. I’m happy to assist you further.
Please "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.