The include feature helps you to reduce duplicity while writing tasks. This also allows us to have smaller playbooks by including reusable code in separate tasks using the Don't Repeat Yourself (DRY) principle.
To trigger the inclusion of another file, you need to put the following under the tasks object:
- include: FILENAME.yaml
You can also pass some variables to the included file. To do so, we can specify them in the following way:
- include: FILENAME.yaml variable1="value1" variable2="value2"
Keeping your variable clean and minimalistic using the include statement, and by observing the DRY principle will allow you to write Ansible code that is going to be far more maintainable and easy to follow.