- hosts: all tasks: - name: Convert test_command to list set_fact: test_commands: ['{{ test_command }}'] when: test_command | type_debug != 'list' - name: Use test_command list set_fact: test_commands: '{{ test_command }}' when: test_command | type_debug == 'list' - name: Run test_command command: '{{ item }}' args: chdir: '{{ zuul.project.src_dir }}' with_items: '{{ test_commands }}'