In ansible playbook, I have to read one yaml file which contains the data like:
john: stu001
bob: stu002
william: stu003
This data is dynamic, there can be number of students with their ids. I want to read this yaml in my ansible play and needs the output like :
---
- name: Students Data
hosts: localhost
tasks:
- include_vars:
file: tmp/stuData.yml
name: stuName
- name: "Students Details"
uri:
url: "{{ some_api_server }}"
return_content: yes
body_format: json
method: POST
body:
matchers:
- name: john
id: stu001
age: NA
- name: bob
id: stu002
age: NA
- name: william
id: stu003
age: NA
startsAt: "{{ st_time }}"
endsAt: "{{ en_time }}"
createdBy: abc@example.com
I have tried the following code for it:
---
- name: Students Data
hosts: localhost
tasks:
- include_vars:
file: tmp/stuData.yml
stuName: stuName
- name: "Students Details"
uri:
url: "{{ some_api_server }}"
return_content: yes
body_format: json
method: POST
body:
matchers:
{% for k,v in stuName.items() %}
- name: {{ k }}
id: {{ v }}
age: "NA"
{% endfor %}
startsAt: "{{ st_time }}"
endsAt: "{{ en_time }}"
createdBy: abc@example.com
This is giving me syntax error in line after matchers. Can anyone please help me in writing the correct code.