Search code examples
azureansibleazure-virtual-machineazure-deployment

Create VM and deploy application on to Azure VM via Ansible


I am new to Ansible Azure modules. What I need is the ability to create VM's(n) and deploy an application on all of them. From what I read online azure_rm_virtual machine can be used to create VM(Assuming vnet, subnet and other networking jazz is in place). I am trying to figure out how do I deploy(copy bits and run my app installer) my application onto the newly created VM's? Can my app deployment be part of the VM creation process? If so what are the options? I looked into other modules but couldn't find any relevant one's. Didn't find any on the azure documentation too. Thanks.


Solution

  • Use azure_rm_deployment module to create VMs.

    Because you know what you are deploying, use azure_rm_networkinterface_facts to get the IP address of your VM.

    Use add_host to create an ad-hoc inventory. This all with:

    ---
    - name: Create VM
      hosts: localhost
      gather_facts: true
    

    Once you have your inventory use:

    - name: Run updates
      hosts: myazureinventory
      gather_facts: true
    

    From here, you can install your software. Hope it helps.