Conditional loop messes up the following task that does a with_item

I store the modules I need to deploy within Consul. It consist of both Perl and PHP modules so on our web servers I only want to install the modules associated with PHP. The following playbook works as long as there are TWO matching modules. In my test case I have two keys with one of them being a key related to PHP deploys. The error I get is:

fatal: [127.0.0.1] => with_items expects a list or a set

FATAL: all hosts have already failed – aborting

If I remove the “when” clause and only have one key within Consul, it also works. How do I get around the error if I’m using a “when” clause and all that remainds within “deploy_list_result” is just one item?

PLAYBOOK

  • consul_kv: host=indeploy001 action=get key=deploylist/{{ jira_ticket }} keys=True
    register: modules_to_deploy

  • name: set fact
    set_fact: deploy_list=“{{ item | replace(“deploylist/” + jira_ticket + “/”,‘’) }}-{{ lookup(‘consul_kv’,item) }}”
    when: “‘{{ item | replace(‘deploylist/’ + jira_ticket + ‘/’,’‘) }}’ in php_modules”
    with_items: ‘{{ modules_to_deploy.value }}’
    register: deploy_list_result

  • shell: sudo rpm -Uvh {{ rpm_repo }}/aria-{{ item }}.rpm --force --test
    with_items: “{{ deploy_list_result.results | map(attribute=‘ansible_facts.deploy_list’) | sort }}”
    register: php_command_result

it would help to see the error, I'm going to guess you need a when: on
the last task that skips the 'skipped' items., also you should not
need to sudo in shell.

The error is within my original msg. I was using the when to build my deploy list.