cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
580
Views
2
Helpful
2
Replies

ansible slow execution

cyberpea
Level 1
Level 1

  we wrote ansible script to create 200 vlan pool in ACI APIC, but execution is too slow. it take more than one hour to finish the job!  With postman it take 2 minutes to create 200 vlan pool.  how can we improve ansible time execution?  

1 Accepted Solution

Accepted Solutions

 

Yes this commonly seen as Postman is primarily designed for manual API testing and interaction and it's optimized for sending requests and handling responses efficiently where as Ansible is focused on infrastructure automation and configuration management. and whilst it can interact with APIs, it has additional layers of functionality, like task execution, dependency management, and error handling, which can add overhead... etc...

If you're currently creating each VLAN pool with a separate Ansible task, switch to using a loop method as this allows you to define the pool configurations once and iterate through them, reducing redundancy and API calls. The only way to speed this up is to use modules like async or community.async which allows parallel execution of tasks, potentially speeding things up. For example, using the asynchronous mode to create the VLAN pools with a timeout of 60 seconds and without polling.

- name: Create VLAN pools asynchronously
  cisco.aci.aci_vlan_pool:
    host: apic
    username: admin
    private_key: "{{ private_key }}"
    pool: "{{ item.pool }}"
    pool_allocation_mode: dynamic
    description: "Production VLANs - Batch {{ item.batch }}"
    state: present
  loop: "{{ vlan_pools | groupby('pool') | list }}"
  loop_control:
    loop_var: item
  async: 60
  poll: 0

Hope this helps.

 

 
Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

View solution in original post

2 Replies 2

 

Yes this commonly seen as Postman is primarily designed for manual API testing and interaction and it's optimized for sending requests and handling responses efficiently where as Ansible is focused on infrastructure automation and configuration management. and whilst it can interact with APIs, it has additional layers of functionality, like task execution, dependency management, and error handling, which can add overhead... etc...

If you're currently creating each VLAN pool with a separate Ansible task, switch to using a loop method as this allows you to define the pool configurations once and iterate through them, reducing redundancy and API calls. The only way to speed this up is to use modules like async or community.async which allows parallel execution of tasks, potentially speeding things up. For example, using the asynchronous mode to create the VLAN pools with a timeout of 60 seconds and without polling.

- name: Create VLAN pools asynchronously
  cisco.aci.aci_vlan_pool:
    host: apic
    username: admin
    private_key: "{{ private_key }}"
    pool: "{{ item.pool }}"
    pool_allocation_mode: dynamic
    description: "Production VLANs - Batch {{ item.batch }}"
    state: present
  loop: "{{ vlan_pools | groupby('pool') | list }}"
  loop_control:
    loop_var: item
  async: 60
  poll: 0

Hope this helps.

 

 
Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Ruben Cocheno
Spotlight
Spotlight

@cyberpea 

try to use cert auth with ACI

Tag me to follow up.
Please mark it as Helpful and/or Solution Accepted if that is the case. Thanks for making Engineering easy again.
Connect with me for more on Linkedin https://www.linkedin.com/in/rubencocheno/