arista-netdevops-community / eos_designs_to_containerlab

Deploy and run AVD eos_designs in containerlab
Apache License 2.0
11 stars 4 forks source link

Suggested speed improvement for large inventories #1

Closed andrewbonney closed 1 month ago

andrewbonney commented 2 months ago

Hi. We're trying to use this role as part of a much larger Ansible inventory where switches are just one of many host types. As a result of this and a large collection of templated host variables, the following step which requires all hostvars to be rendered out is incredibly slow:

https://github.com/arista-netdevops-community/eos_designs_to_containerlab/blob/main/tasks/create_avd_node_files.yml#L27

- name: Create simulation topology and other needed files
  delegate_to: localhost
  run_once: true
  simulation:
    inventory: "{{ ansible_play_hosts_all | sort() }}"
    hostvars: "{{ hostvars }}"
    groups: "{{ groups }}"

I believe the same functionality can be acheived as follows, but this only causes host vars to be rendered for hosts which are actually relevant to the role:

In create_avd_node_files.yml, remove the arguments:

- name: Create simulation topology and other needed files
  delegate_to: localhost
  run_once: true
  simulation:

In the simulation.py action plugin:

    def run(self, tmp=None, task_vars=None):
        super(ActionModule, self).run(tmp, task_vars)
        ret = dict()
        inventory = sorted(task_vars.get("ansible_play_hosts_all", {}))
        hostvars = task_vars.get("hostvars", {})
        groups = task_vars.get("groups", {})

This certainly appears to work for us, and assuming it doesn't cause an obvious regression it would be great if it could be adjusted.

bjmeuer commented 1 month ago

@andrewbonney I added the code for speed improvements with large inventories, please test if this fits your needs.

andrewbonney commented 1 month ago

Looks like this is working, thanks