State exists for group of items

I keep running into this a lot but I am not sure how to handle it. Lets assume I have the following yaml:

project_paths:

  • path: /srv/www/web/app1
    name: app1
  • path: /srv/www/web/app2
    name: app2

Then I want to check if a file exists before running the following action:

  • name: application | check for installer
    stat: path={{ item.path }}/install.php
    register: check_install
    with_items: project_paths

  • name: application | run install
    command: php install.php chdir={{ item.path }}
    with_items: project_paths
    when: check_install.stat.exists == false

The issue is registering check_install since we are doing it in a loop. It looks to be resetting the variable for every item. I tried something like this and I get ‘check_install’ is undefined.

  • name: application | check for installer
    stat: path={{ item.path }}/install.php
    register: check_install[item.name]
    with_items: project_paths

  • name: application | run install
    command: php install.php chdir={{ item.path }}
    with_items: project_paths
    when: check_install[item.name].stat.exists == false

  • name: done
    fail: msg=“{{ item.name } installer does not exist”

with_items: project_paths
when: check_install[item.name].stat.exists == false

Basically I am wondering the best way to run stat or other register commands with_items so that I can later check that on other with_item tasks for the same variables.

Verify the results of a registered variable like so:

  • debug: var=register

Thank you! This is the code I ended up with for anyone that stumbles upon this:

  • debug: >
    msg=“{{ item.0.path }} - {{ item.1.stat.exists }}”
    with_together:

  • project_paths

  • check_install.results

  • name: application | run install
    command: php install.php chdir={{ item.0.path }}

with_together:

  • project_paths
  • check_install.results

when: item.1.stat.exists