Ansible evaluates all variables for each task and each iteration in the task despite the vars are not actually used

Hello everybody,

I am using Ansible 2.3.1.1 with Jenkins. I have encountered the following issue - my playbook which uses variables from aws dynamic inventory becomes extremely slow. The most interesting case that if I copy this playbook outside my jenkins workspace and run it in any other directory the execution speed is OK. In order to test it I moved out all variable files from workspace directory /group_vars/all, as a result the execution speed for this playbook inside workspace become OK too. Then I put variable files back to /group_vars/all one by one and test execution time. Each additional file in the folder augments the execution time for each task iteration. Also when I put one file which has reference to removed file variable Ansible throwed an error.

I can conclude that Ansible evaluates all variables in the /group_vars/all for each tasks and for each iteration of the task before run despite it is not actually used. But according to the documentation Ansible uses lazy evaluation method, so I can not understand why this issue occurs and how it could be fixed. Could someone shed the light on it?

the playbook is the following:

  • hosts: “127.0.0.1”

tasks:

 - name: print something
  debug:
    var: hostvars["{{item}}"]['ec2_vpc_id']
  with_items: "{{groups['some_tag']}}"

Regards.

Also I have find the similar issue discussed in

https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!searchin/ansible-devel/lazy|sort:relevance/ansible-devel/k7Tei-nBygs/N9xYtno9AwAJ

but it seems that fix provided in https://github.com/ansible/ansible/issues/17024 did not help, as all the variables in /group_vars/all is still evaluated for each task iteration.