I have multiple arrays with same length. I need to loop through the length and call the elements. I tried the below one and failed. Can you please let me know where I did wrong in this. Or is there any better approach to loop through array elements.
tasks:
- name: Set facts
set_fact:
SERIAL_NUMBER: ['2342', '4455', '5643']
PASSWORD: ['xxx', 'yyy', 'zzz']
EXP_DATE: ['06-10-18', '07-01-19', '06-01-18']
LICENSE_TYPE: "evaluation"
- name: Execute the script to apply evaluation license
lineinfile:
dest: "/root/test.txt"
line: "{{ SERIAL_NUMBER[{{ item }}] }} {{ PASSWORD[{{ item }}] }} {{ EXP_DATE[{{ item }}] }}"
create: yes
with_sequence: start=0 end={{ SERIAL_NUMBER|length }}
when: "{{ LICENSE_TYPE }}" == "evaluation"
I even tried the below approach in place of line:. But no luck.
line: "{{ SERIAL_NUMBER[item]int % SERIAL_NUMBER|length }} {{ PASSWORD[item]int % PASSWORD|length }} {{ EXP_DATE[item]int % EXP_DATE|length }}"
I see 2 issues here.
- The array element calling with flower braces inside flower braces {{ {{ }} }}.
- The second is using "when" in this case.
Thank you.