Reputation: 43778
I'm new in Ansible, just wandering how could I loop through an json records with ansible. I have a json file with the following data inside:
{
"map": {
"entry": [
{
"string": [
"6a032ae5-3eed-4d20-a9ef-ccbd88118c47"
]
},
{
"string": [
"27617813-e268-4c94-b539-3550a3a8501a"
]
},
{
"string": [
"b39b10fb-0538-42d7-96fc-553eee9c7ded"
]
}
]
}
}
and I have the following code in ansible to run through the json file:
- name: Initialise variables
set_fact:
NEW_CODE_TEMPLATES_IDS: "{{ lookup('file', 'code_template_map/codeTemplate.json') | json_query('map.entry[*].item') }}"
- name: code template id
debug:
var: NEW_CODE_TEMPLATES_IDS
I expecting the output will be like following:
6a032ae5-3eed-4d20-a9ef-ccbd88118c47
27617813-e268-4c94-b539-3550a3a8501a
b39b10fb-0538-42d7-96fc-553eee9c7ded
But for some reason this is doesn't seem working for me. doesn't anyone know why ?
Upvotes: 1
Views: 294