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

Closed
himanshkumar opened this issue Apr 1, 2019 · 1 comment

Comments

@himanshkumar
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

@zwindler

This comment has been minimized.

Copy link
Owner

commented Apr 4, 2019

The functionnality you are looking for is "async". See https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html 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)

mymodule:
  ...
  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)"
  azure_rm_virtualmachine:
      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
      ssh_public_keys:
        - path: "/home/{{admin_username}}/.ssh/authorized_keys"
          key_data: "{{lookup('file', '{{admin_pub_path}}') }}"
      network_interface_names: "{{nic_root_name}}{{item}}"
      image:
        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"
  async_status:
    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
Projects
None yet
2 participants
You can’t perform that action at this time.