with_items in playbook context

Hi,

ive got the following playbook:

https://gist.github.com/anonymous/ecb41b6fa411871fb69c

with the following var_files:

https://gist.github.com/anonymous/6d33670bf74388dd3d39

But its not possible to iterate over with_items in playbook context. But how can i do checks in the next task (probe if tomcat-manager call was successful) with registered variable (tomcat_response)
if the iterate only possible in the first task… Maybe theres a better way to do things like this but … I’m really puzzled atm…

Thanks for help!

Lasse

​use with_items on the first task, register the response, then iterate over
the results of that response

command: ... ${item.content}...
with_items: ${tomcat_response.results}​

(I might have the specific subkeys wrong, but you get the idea)

Serge

Here’s and example where I do something similar. Took me a while to get the subkeys right.

  • name: setup application instance configuration file
    template: >
    src=dealmax_app.pl.j2
    dest=/var/www/dealmax/{{ item.application }}/dealmax_{{ item.application }}_{{ item.name }}.pl
    with_items: instances
    register: config

  • name: restart apps on configuration change
    tags: config
    service: >
    name=dealmax-{{ item.item.application }}-{{ item.item.name }}
    state=restarted
    when: item.changed and item.item.enabled

config.results is a list of all the results of the

previous task loop including the ‘item’ data passed to the task

with_items: config.results

FYI: this requires even less boilerplate in 1.2 syntax, just

Hi,

thanks to all for the hints… this helps me out, but one problem suddenly occured:

https://gist.github.com/anonymous/e7ca3b6e44a25b7cd466

The $childs var doenst resolve anymore the request on localhost look like → GET /manager/undeploy?path=/${childs}

But the var file got childs:


childs: [!!python/unicode 'myapplication-5.1.0', !!python/unicode 'myapplication-3.1.0']

Once again confused n thankful 4 help...

Lasse

Ok, ive found it:

i tried to load

${ansible_facts.ansible_fqdn}

but it should be

${ansible_fqdn}

but from me opinion it should be raise an error like 

ERROR: file not found: /tmp/.yml

or something like that, same error if the vars_files are hardcoded and the file doesnt exists, instead of 
running further and resolve no vars..

Greetings 

Lasse

I don’t see where “childs” is being set above.

If vars_files contains fact variables they are resolved later rather than up front.

It is good form to supply a default in this case, by doing this:

vars_files:

  • [ “${somefact}_foo.yml”, “default.yml” ]

I would tend to agree that if you have the bare:

vars_files:

  • “${somefact}.yml”

Should probably produce a host-specific error and fail the task(s).

Note that ${foo} is 1.1 syntax, and in 1.2, we still support that but far {{ foo }}