Conditional loop messes up the following task that does a with_item

47 views
Skip to first unread message

Samnang Sen

unread,
Sep 2, 2015, 3:04:09 PM9/2/15
to Ansible Project
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

Brian Coca

unread,
Sep 2, 2015, 4:08:11 PM9/2/15
to Ansible Project
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.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/7f307ebe-2c47-469c-9724-46c30c7e5a42%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Samnang Sen

unread,
Sep 2, 2015, 6:17:22 PM9/2/15
to Ansible Project
The error is within my original msg. I was using the when to build my deploy list.
Reply all
Reply to author
Forward
0 new messages