I have the below playbook test1.yml that gets istat data for 26 subfolders under this directory /var/myfile/pdf.
tasks:
-
name: List directoriesraw: "ls -d “/var/myfile/pdf/*/”
register: subdir -
name: List pid files
raw: “istat {{ item }}”
with_items: “{{ subdir.stdout_lines }}”
I run the playbook and it takes 29 seconds to complete
time ANSIBLE_SSH_PIPELINING=True ansible-playbook -i=10.9.9.12, -f 30 test1.yml -vvv
After the playbook completes below is the time taken details output:
Output:
real 0m29.144s user 0m6.206s sys 0m5.618s
I now put the same code with istat task in include_tasks` file like below.
Playbook test2.yml
tasks:
-
name: List directories
raw: "ls -d “/var/myfile/pdf/*/”
register: subdir -
name: List pid files
include_tasks: “innertest.yml”
with_items: “{{ subdir.stdout_lines }}”
cat innertest.yml
- raw: “istat {{ item }}” time ANSIBLE_SSH_PIPELINING=True ansible-playbook -i=10.9.9.12, -f 30 test2.yml -vvv
Output:
real 0m59.044s user 0m18.203s sys 0m10.118s
As you can see the time with the same amount of task has more than doubled due to include_tasks
In the debug, I also see there are 26 ssh connections triggered for the 26 sub-directories with_items for the same target host 10.9.9.12
I’m not sure of how this works internally but it would have been nice to have a single ssh connection for istat for 26 sub-directories on the same host for performance reasons.
Is there a way to increase the performance for include_tasks and bringing down the number of ssh connections to the same host ?