Generate a dynamic list to be used by with_items

Hi,

I thought the following should work, but I got a syntax error. Can the yml condition check syntax be used inside with_items? If not, how can I generate a dynamic list in the role to be used by with_items (register ??)? Thank you very much and appreciate any clues to fix following statement or workarounds.

  • name: install scripts
    copy: dest={{ home }}/scripts/{{ item }} src=scripts/{{ item }} mode=755
    with_items:
    {% set script_list = %}
    {% for s in services %}
    {% for g in s.groups %}
    {% if g in groups %}
    {% if script_list.append(s.script) %}
    {% endif %}
    {% endif %}
    {% endfor %}
    {% endfor %}
    {% for script in script_list | unique %}
    {{ script }}
    {% endif %}

Forgot the error message:

Note: The error may actually appear before this position: line 17, column 6

with_items:
{% set script_list = %}
^

Also fixed the list line:

{% for script in script_list | unique %}
{{ script }}
{% endfor %}

Don’t worry about it, don’t need it any more.

Thank you.