fatal error when skipping includes

Error:
`
fatal: [myhost] => with_items expects a list or a set

`

I have a role with the following tasks(snippets included):
tasks/main.yml
`

the include itself is not skippable, the when gets added to the included tasks.

I’m not sure I follow you. The include is being skipped since the when: condition isn’t met. All other tasks above the one that errs out shows skipped. It’s just that specific task that makes everything fail for that host.

I have attempted to add a ‘default’ filter to the when:, but it seems like it is always defined, even though it’s being skipped ?!?!?

try:
  with_items: "{{ ((the_files|default()).stdout_lines|default()) | list }}"

Ah, great catch. That actually works.

Now, to convince ansible not to evaluate anything in included files which are skipped…

And I’ve run into this bug yet again!

I have the following which fails on skipped hosts:

`

  • name: Check all other host certs
    connection: local
    sudo: false
    stat:
    path: “{{ role_path }}/templates/ca/{{ item }}.crt”
    with_items: “{{ (nagios_host_fqdns_flat|default()).split(‘,’)|default() }}”

register: stat_host_certs

`

This is becoming quite time consuming to insert for every with_* on skipped files!!!

@Brian,

According to your comment in this issue:
https://github.com/ansible/ansible/issues/11961

the when: of the include: gets run AFTER the with_xxx of the child file? This doesn’t make any sense to me. If you are conditionally including a file, NOTHING in that file should be processed. I am not being combative, but am I missing something here? That seems like a real bug; the specific bug that I’m running into over and over again.

​You are not conditionally including. you are applying the condition to all
tasks in the include.

​

Ahhhh! Thanks Serge. So it is applying in the same manner as roles apply args (e.g. tags: ).

So, now to figure out how to default a split().

Ultimately fixed this by simply putting this into the role’s defaults/main.yml

`
nagios_host_fqdns_flat: ()

`