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

**URL:** <https://forum.ansible.com/t/ansible-evaluates-all-variables-for-each-task-and-each-iteration-in-the-task-despite-the-vars-are-not-actually-used/25353>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [August 29, 2017, 10:22am UTC](https://forum.ansible.com/t/ansible-evaluates-all-variables-for-each-task-and-each-iteration-in-the-task-despite-the-vars-are-not-actually-used/25353 "2017-08-29T10:22:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleksandr\_Neshcheret](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Aleksandr\_Neshcheret](https://forum.ansible.com/u/Aleksandr_Neshcheret)\
**Post date:** [August 29, 2017, 10:22am UTC](https://forum.ansible.com/t/ansible-evaluates-all-variables-for-each-task-and-each-iteration-in-the-task-despite-the-vars-are-not-actually-used/25353/1 "2017-08-29T10:22:17Z")

</div>

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:

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

```

```auto

```

```auto
Regards.

```

---

<div class="post-metadata">

**Author:** ![Aleksandr\_Neshcheret](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Aleksandr\_Neshcheret](https://forum.ansible.com/u/Aleksandr_Neshcheret)\
**Post date:** [August 29, 2017, 2:03pm UTC](https://forum.ansible.com/t/ansible-evaluates-all-variables-for-each-task-and-each-iteration-in-the-task-despite-the-vars-are-not-actually-used/25353/2 "2017-08-29T14:03:19Z")

</div>

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](https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!searchin/ansible-devel/lazy%7Csort:relevance/ansible-devel/k7Tei-nBygs/N9xYtno9AwAJ)

but it seems that fix provided in [https://github.com/ansible/ansible/issues/17024](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.
