ansible/ansible — pull request #1058 by jkleint (2012-09-17 22:18:30+00:00)
Title: Support iteration over command output in with_items.

This lets you access a command's stdout in a register as a list of lines.

When the result of a command is stored in a register, this splits its stdout
into a list (using universal newlines) and stores it in the `stdout_lines` field
of the result object. You can do whatever you want with it, but in particular
you can loop over the lines using `with_items`.

Here is an example:

```
---
- name: Ensure only trusted RPM signing keys are present.
hosts: all
sudo: True
vars:
trusted_keys: [RPM-GPG-KEY-CentOS-5, RPM-GPG-KEY-EPEL, RPM-GPG-KEY-rpmforge-dag]

tasks:
- name: Copy RPM signing keys
action: copy src=etc/pki/rpm-gpg/$item dest=/etc/pki/rpm-gpg/$item
with_items: $trusted_keys

- name: Get list of all keys
action: command ls -1 /etc/pki/rpm-gpg
register: all_keys

- name: Remove untrusted keys
action: file dest=/etc/pki/rpm-gpg/$item state=absent
with_items: ${all_keys.stdout_lines}
only_if: "'$item' not in $trusted_keys"
```

Unit test included.