Ansible循环和数组的条件

我希望能够通过指定changed_when条件来控制模块的行为。 当执行一个简单的任务,如文档中的一个,这工作正常:

- command: some command register: command_result changed_when: "command_result.rc != 2" 

问题出现在我开始使用循环时。 我无法弄清楚如何从循环的当前迭代访问stderr,stdout,rc结果。 例如:

 - command: aptly mirror update some-mirror register: aptly_output changed_when: "?item?.stdout | search('Download queue: 0 items')" 

所有结果都转到aptly_output.results ,但是如何访问当前迭代的结果?

在我们的angular色之一,我们这样做:

 - name: themes | activate command: "wp-cli --allow-root --no-color --path='{{ item.0.path }}' theme activate {{ item.1.name }}" register: check_activate_theme changed_when: "'Success: Switched to' in check_activate_theme.stdout" with_subelements: - wordpress_installs - themes when: item.1.name and item.1.activate | default(false) tags: - wordpress-themes-activate-theme 

我认为这应该也适用于你的用例。