I have a scenario where I need to print only 0th array and 1st array of 'N'of array in ansible.
Could someone help me to achieve this
Sample code:
Array;
ID = [1,2,3,4]
Ansible Code:
- hosts: localhost
gather_facts: no
tasks:
- name: Print the first 2 values in the array
debug:
msg: "{{ item }}"
with_items: "{{ ID }}"
Expected Output:
PLAY [localhost] ***********************************************************************************************************************************************************************************************
TASK [Print the first 2 values in the array] *******************************************************************************************************************************************************************
ok: [localhost] => (item=1) => {
"msg": "1"
}
ok: [localhost] => (item=2) => {
"msg": "2"
}
Actual Output:
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"
}