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. On Mon, Aug 5, 2019 at 4:21 PM Bob Tanner <[email protected]> wrote: > Simple tasks, where I want the "Remote git configuration" task to only be > run when apache2_configuration == 'git' > > - debug: > msg: "DEBUG: {{ apache2_configuration }}" > tags: apache2-servers > > - name: Remote git configuration > import_tasks: remote-git.yml > when: apache2_configuration == 'git' > tags: apache2-servers > > Running ansible, apache2_configuration is "role" but for some reason the > import_tasks: remote-git-yml is being imported? > > TASK [apache2-servers : debug] > ************************************************* > ok: [www.aws.comap.com] => { > "msg": "DEBUG: role" > } > > TASK [apache2-servers : XXXXXXXXX inside remote-git.yml] > *********************** > > Trying with include: > > - debug: > msg: "DEBUG: {{ apache2_configuration }}" > tags: apache2-servers > > - name: Remote git configuration > include: remote-git.yml > when: apache2_configuration == "git" > tags: apache2-servers > > TASK [apache2-servers : debug] > ************************************************* > ok: [www.aws.comap.com] => { > "msg": "DEBUG: role" > } > > TASK [apache2-servers : XXXXXXXXX inside remote-git.yml] > *********************** > > 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? > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/38b657c1-2383-443d-b9e6-e6a62993cec0%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/38b657c1-2383-443d-b9e6-e6a62993cec0%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Matt Martz @sivel sivel.net -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAD8N0v-4yWXi7iHsGcHeBZHUoLjrUnUdBgLVqieBLmdCw76pQw%40mail.gmail.com.
