Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doubt regarding Functioning of the script. #2

himanshkumar opened this issue Apr 1, 2019 · 1 comment


Copy link

commented Apr 1, 2019

I used your Ansible script to deploy Azure VM. The script works perfectly fine & I am very thankful for your contribution . As a beginner it helped me a lot to understand ansible and azure. I had a doubt regarding the functionality of the script.
When I execute this script it Launches one VM at a time , which take a lot of time if I have to execute 7-8 instances together. It takes around 30-35 min in total to launch all the VM's. It will be very helpful if you could explain why does this happen and any way to execute these instances in parallel or a bit faster as I have to configure a complete cluster after provisioning of these VM's


This comment has been minimized.

Copy link

commented Apr 4, 2019

The functionnality you are looking for is "async". See for official documentation

with Ansible, you can specify to a task that it as to run in async mode. You have to add the following stuff in you task, meaning that the tasks will eventually timeout (120s in the example)

  register: myasynctask
  async: 120
  poll: 0

Then, after that, you add the async_status module, that listens for myasynctask.results list.

In our case here (deploying VMs in Azure), it would look like this

- name: "Create {{vm_root_name}}X VM with existing NIC (in parallel using async)"
      resource_group: "{{resourcegroup_name}}"
      name: "{{vm_root_name}}{{item}}"
      vm_size: "{{vm_size}}"
      managed_disk_type: "{{managed_disk_type}}"
      admin_username: "{{admin_username}}"
      availability_set: "{{availabilityset_name}}"
      ssh_password_enabled: false
        - path: "/home/{{admin_username}}/.ssh/authorized_keys"
          key_data: "{{lookup('file', '{{admin_pub_path}}') }}"
      network_interface_names: "{{nic_root_name}}{{item}}"
        offer: UbuntuServer
        publisher: Canonical
        sku: '16.04.0-LTS'
        version: latest
  with_sequence: count="{{instances_number}}"
  register: azure_vms_instances
  async: 600
  poll: 0

- name: "Wait for instance creation to complete"
    jid: "{{ item.ansible_job_id }}"
  register: azure_vms_jobs
  until: azure_vms_jobs.finished
  retries: 120
  with_items: "{{ azure_vms_instances.results }}"

Hope this helps

@zwindler zwindler closed this Apr 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.