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

29 views
Skip to first unread message

Aleksandr Neshcheret

unread,
Aug 29, 2017, 6:22:17 AM8/29/17
to Ansible Project
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.

Aleksandr Neshcheret

unread,
Aug 29, 2017, 10:03:19 AM8/29/17
to Ansible Project
Also I have find the similar issue discussed in 


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.
Reply all
Reply to author
Forward
0 new messages