Simple tasks, where I want the "Remote git configuration" task to only be
run when apache2_configuration == 'git'
I do not understand why import_tasks: or include: is importing/including
remote-git.yml when apache2_configuration is not equal to git.
Any help?
So for me the following happens:
When the when condition is false import_tasks still imports the tasks
file, but skips all tasks in it. include_tasks on the other hand is
skipped as a task itself.
include without the _tasks (which you shouldn't use anymore) behaves a
lot like import_tasks in this case. If you want it to behave like
include_tasks, you'll have to set the static: no option to the include task.
If you look at the documentation, it's in the examples:
To start, I’ll say, don’t use include any more. It has been replaced by import_tasks and include_tasks. The behavior of include was hard to reason about, and as such we are in the process of deprecating it.
Now as for the differences:
import_tasks is a pre-processor, that is parsed and imported during playbook parsing time. Effectively the result, is that the import is replaced at playbook parsing time with the list of tasks within. Any keyword/argument applied to the import_tasks is effectively merged down or inherited by the individual tasks within.
include_tasks is JIT (Just in Time) processed during task execution. As such, when encountered during normal task execution, any when statement (or other keyword/argument) will affect whether or not it is included at that point. If included, the tasks within do not inherit the keywords/arguments on the include_tasks, to get that behavior you would use apply. If the keywords or arguments, such as when or tags, prevent the include_tasks from running, none of the included tasks wihin will be seen in the playbook execution.