Complex loop question.

47 views
Skip to first unread message

Nico K.

unread,
Jun 24, 2015, 5:26:26 AM6/24/15
to ansible...@googlegroups.com
Hi,

I'm looping over a set of repositories and storing them using 'register', for each of these repositories I'm listing the configuration directory and storing the results using register, so far so good.
Now I'm trying to compare the results against a list of configuration files that should exist within that repository, but I can't seem to get that done.

What I'm trying to do:

- name: check repos
  shell: ls -1 {{ path }}/{{ item.name }}/{{ config_dir }}
  register: found
  with_items: repositories

found, at this point contains 'x' repositories with 'y' files, y.stdout_lines contains the files that were found for 'x'.

The "cleanup" code I'm trying to write does something like:

- name: remove unmanaged
  file:
    path: ...
    state: absent
  with_together:
    - repositories
    - found.results
    - item.1.stdout_lines <--- these would be the actual file names
  when: item.2 not in configuration_files

Sadly, this doesn't seem to work.. how is one supposed to deal with this?

Thanks,
Nico

yunano

unread,
Jun 25, 2015, 11:08:48 PM6/25/15
to ansible...@googlegroups.com
Hi,

You should use with_subelements like:

- name: remove unmanaged
  file:
    path: ...
    state: absent
    with_subelements:
    - found.results
    - stdout_lines
    when: item.1 not in configuration_files

Thanks.

2015年6月24日水曜日 18時26分26秒 UTC+9 Nico K.:
Reply all
Reply to author
Forward
0 new messages