【问题标题】:Trying to filter a with_item results in ansible尝试过滤 with_item 会导致 ansible
【发布时间】:2017-10-26 03:52:36
【问题描述】:

伙计们。我试图找到一个可行的答案,但失败了; 我们正在将 docker 映像加载到虚拟机中。我们想调试每个.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 }}"

【问题讨论】:

    标签: filter ansible jinja2 docker-image


    【解决方案1】:

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

    - debug:
        msg: "{{ docker_pull_output.results | json_query('[].actions[]') }}"
    

    【讨论】:

      猜你喜欢
      • 2019-07-07
      • 1970-01-01
      • 1970-01-01
      • 2018-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多