Version: Ansible 2.3.1.0
Hello,
I’m using Ansible with a small/medium sized inventory and accessing hostvars is painfully slow. I think problems began when switching 2.1 → 2.3, but I have no easy way of verifying this.
Playbooks became incredibly slow while rendering templates. One particular template became unusable since the task takes now 40 minutes. I investigated the issue by analyzing this template and came to the conclusion that each access to hostvars[something] takes ~1sec.
I’m positive the template could be improved, but the core problem would still be there.
Just to give an idea about what I mean by slow, here’s the time it took to process the same operation on lab and prod inventory:
$ ansible -i lab.inv all --list-hosts |wc -l
16
$ time ansible -i lab.inv all -m debug -a var=hostvars |wc -l
163740
real 0m2,455s
user 0m5,462s
sys 0m0,948s
$ ansible -i prod.inv all --list-hosts |wc -l
257
$ time ansible -i prod.inv all -m debug -a var=hostvars |wc -l
ctrl-c
I’ve stopped it after 1h.
I’ve found quite a few issues related to this but I’ve not been able to understand if the issue was addressed or resolved at all. Apparently not.
https://github.com/ansible/ansible/issues/12239 (opened in 2015)
https://github.com/ansible/ansible/issues/23349 (2017)
https://github.com/ansible/ansible/issues/30773 (2017)
Having to manage 200+ servers in production should not be that uncommon: how do I get out of this issue? I’ve currently found this workaround https://github.com/ansible/ansible/issues/17528#issuecomment-255065629 , but it’s obviously an ugly hack.
Would 2.4 help?
Thanks.