3

I haven't found a decent way to get a Windows instance in Azure started up using the azure_rm_virtualmachine module with remote PowerShell enabled from first boot.

What is the typical approach to get started with Azure Windows instances provisioned with Ansible ready to run PowerShell remote commands?

There's another Ansible module called simply azure, but appears to be deprecated by azure_rm_virtualmachine.

  • Do you mean you want to get VM status by using PowerShell. If yes, you could use Azure PowerShell. (Get-AzureRmVM -ResourceGroupName $ResourceGroup -Name $RmVM -Status).Statuses.Code[1] – Shui shengbao May 18 '17 at 1:37
  • I mean using ansible to provision a host that has remote power shell enabled from first boot to be usable by ansible. I'll clarify the question – barrymac May 18 '17 at 16:07
4

After creating the VM, use azure_rm_deployment module to create a deployment for a Custom Script Extension.

In the template specify:

{
  "publisher": "Microsoft.Compute",
  "type": "CustomScriptExtension",
  "typeHandlerVersion": "1.4",
  "settings": {
    "fileUris": [
      "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1"
    ],
    "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File ConfigureRemotingForAnsible.ps1"
  }
}

Then run a play against the VM.

  • Much appreciated @techraf , thanks also for question edits! – barrymac Jun 4 '17 at 15:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.