【发布时间】:2022-01-24 08:31:52
【问题描述】:
我有一个场景,我只需要在 ansible 中打印第 0 个数组和第一个数组的 'N'of 数组。
谁能帮我实现这个目标
示例代码:
数组;
ID = [1,2,3,4]
Ansible 代码:
- hosts: localhost
gather_facts: no
tasks:
- name: Print the first 2 values in the array
debug:
msg: "{{ item }}"
with_items: "{{ ID }}"
预期输出:
PLAY [localhost] ***********************************************************************************************************************************************************************************************
TASK [Print the first 2 values in the array] *******************************************************************************************************************************************************************
ok: [localhost] => (item=1) => {
"msg": "1"
}
ok: [localhost] => (item=2) => {
"msg": "2"
}
实际输出:
PLAY [localhost] ***********************************************************************************************************************************************************************************************
TASK [Print the first 2 values in the array] *******************************************************************************************************************************************************************
ok: [localhost] => (item=1) => {
"msg": "1"
}
ok: [localhost] => (item=2) => {
"msg": "2"
}
ok: [localhost] => (item=3) => {
"msg": "3"
}
ok: [localhost] => (item=4) => {
"msg": "4"
}
【问题讨论】: