ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
346 stars 334 forks source link

Running a playbook against dynamic inventory is very slow #1856

Open 4SH-gaupee opened 11 months ago

4SH-gaupee commented 11 months ago
SUMMARY

Running a ping playbook against a dynamic inventory of 350 VM is very slow

ISSUE TYPE
COMPONENT NAME

https://docs.ansible.com/ansible/latest/inventory_guide/intro_patterns.html

ANSIBLE VERSION
ansible [core 2.15.4]
  config file = /home/gaupee/.ansible.cfg
  configured module search path = ['/home/myself/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/myself/.venv/vmware-auto/lib/python3.11/site-packages/ansible
  ansible collection location = /home/myself/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/myself/.venv/vmware-auto/bin/ansible
  python version = 3.11.5 (main, Aug 29 2023, 15:31:31) [GCC 13.2.0] (/home/myself/.venv/vmware-auto/bin/python3)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
CONFIGURATION
CONFIG_FILE() = /home/myself/.ansible.cfg
HOST_KEY_CHECKING(/home/myself/.ansible.cfg) = False
INVENTORY_ENABLED(/home/myself/.ansible.cfg) = ['vmware_vm_inventory']
PAGER(env: PAGER) = less
OS / ENVIRONMENT

target OS CentOS

STEPS TO REPRODUCE

Run a playbook against a dynamic inventory

- hosts:
    - QA:&db
  tasks:
    - action: ping
EXPECTED RESULTS

The play should run in a timely manner

ACTUAL RESULTS

Play run in 3min just to ping 1 server

ok: [mongo-001.qa.tom.local] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "data": "pong"
        }
    },
    "ping": "pong"
}

PLAY RECAP *********************************************************************************************************************************************************************************************************************************
mongo-001.qa.tom.local     : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

ansible-playbook test.yml -i tom.vmware.yaml  -vvvv  5.98s user 0.50s system 3% cpu 3:14.56 total
eddiedunn commented 10 months ago

Try to limit the fields you select. That allowed me to go from 1 min 30 sec to less than 1 second to pull the inventory.

    properties:
    - 'name'
    - 'guest.ipAddress'
    - 'config.name'
    - 'config.uuid'
4SH-gaupee commented 9 months ago

Sorry for the very late reply.

Using theses properties it took 1min instead of 3.

The majority of time seems spent doing inventory parsing.

I've tried, and the problem seems to be the "with_tags" value, the parsing of tags is taking an awful lot of time, when disabled it only took 6 seconds, but then I can't use tags to match hosts :upside_down_face: