Optimizing anssible code

Some ansible code can take a long time to run, this is in most cases due to a design choice in the playbook.
Mostly when using loops where they are not needed, or loops to parse large datasets, this takes lots of time.
For a few of these optimizations there are thing that can be done to improve performance:

Avoid large loops on registered vars

parse output with jinja

Create lists and dicts with jinja2

jinja_variables

Avoid jinja spacing errors in linting

jinja spacing

Creating complex loops using jinja2

complex loops