尝试过滤with_item会导致ansible

时间:2017-05-25 13:11:53

标签: filter ansible jinja2 docker-image

嗨伙计们。我试图找到一个合适的答案,但失败了; 我们将docker image sin加载到vm。我们要调试每个.actions的列表,而不对响应列表进行硬编码。 有谁知道怎么做?

到目前为止我们的代码:

---
- name: 'Debbug images to pull'
  debug:
    var: required_images

- name: 'Pull docker images so that we have them pre-loaded'
  docker_image:
    name: "{{ item.image_name }}:{{ item.image_version }}"
    state: 'present'
  with_items: "{{ required_images }}"
  register: docker_pull_output

- name: 'Confirm images pulled attempt a - this looks righ tbut has the array length hard coded'
  debug:
    var: item
    verbosity: 2
  with_items:
   - "{{ docker_pull_output.results[0].actions }}"
   - "{{ docker_pull_output.results[1].actions }}"
   - "{{ docker_pull_output.results[2].actions }}"
   - "{{ docker_pull_output.results[3].actions }}"
   - "{{ docker_pull_output.results[4].actions }}"

- name: 'Confirm images pulled attempt b - this spams us with the full item, not just the .action property'
  debug:
    var: item.actions
    verbosity: 2
  with_items: "{{ docker_pull_output.results }}"

1 个答案:

答案 0 :(得分:0)

要获取拉动任务中所有操作的列表,您可以使用JMESPath

AttribLocation