31 May 2018
register可以帮助我们获取task执行的结果,然后在使用,但是如果我们是一个循环的task,如何循环的取出所有的result呢?
在循环中使用register官方文档
- name: get tomcat version shell: "{{ item }}/bin/version.sh" with_items: - "{{ CATALINA_HOME_01 }}" - "{{ CATALINA_HOME_02 }}" - "{{ CATALINA_HOME_03 }}" - "{{ CATALINA_HOME_04 }}" - "{{ CATALINA_HOME_05 }}" register: tomcat_version - name: tomcat version debug: msg: "{{ item.stdout }}" with_items: "{{ tomcat_version.results }}"
如果后面的with_items循环中需要使用when判断呢?
- name: tomcat version command: "echo {{ item.item }}" when: item.stderr != "" with_items: "{{ tomcat_version.results }}"