Conditional include.

Hi,

main.yml:

  • include: somefile.yml
    when: variable is defined

somefile.yml:

  • name: do some stuff
    file: path=“/x/y/x/application{{ item }}” state=directory
    with_sequence: start=“{{variable.start}}” end=“{{variable.end}}”

Runs into an error when variable is -not- defined, as it seems to include somefile.yml anyway and then complains about it being unable to parse the sequence. (unknown error parsing with_sequence arguments:)
Considering that the include is conditional, why is it even processing the file? I also tried adding the condition to this specific task, that is add the ‘when’ clause to somefile.yml, however this results in the same error.

Any ideas?

Thanks,
Nico

​It's not the include that is conditional. include+when means applying the
when on each task in the included file.
Also, the combination of a when and a with loop, means, apply the when to
each iterated item.

You'll need to extend your conditional: when variable is defined and
variable.start is defined and variable end is defined.​

You can use “group_by” if you want something that creates a dynamic group and it will show more concise output.