Ansible 中使用 jinja2 batch

bactch是将列表拆分成多个指定大小的子列表。

---
- hosts: localhost
  gather_facts: no
  tasks:
    - name: use debug to view the vault values 
      vars:
       sleep_durations:
         - 1
         - 2
         - 3
         - 4
         - 5
       durations: "{{ item }}"
      debug:
         msg: "{{ durations }}"
      loop:
         - "{{ sleep_durations | batch(2) | list }}"

TASK [use debug to view the vault values] *************************************************************
ok: [localhost] => (item=[[1, 2], [3, 4], [5]]) => {
    "msg": [
        [
            1,
            2
        ],
        [
            3,
            4
        ],
        [
            5
        ]
    ]
}

猜你喜欢

转载自blog.csdn.net/weixin_44487339/article/details/86561970