I have a json file structure, and I would like to iterate over an array inside of that file structure. In a way that it fails if a given string isn't found.
"datasource": [
{
color: "red",
value: "#f00"
},
{
color: "green",
value: "#0f0"
},
{
color: "black",
value: "#000"
}
]
This is my try.
vars:
color: "red"
- name: Fetch json_data
uri:
url: example.com/json_data
register: color_data
- name: Loop over data and continue if string was found.
fail:
msg: "The color '{{ color }}' was not found.
when: color not in item
loop: "{{ color_data['datasource'] }}"
What I want to achieve is, if there is a match it should not fail. E.g. it would be nice to break the loop on match and continue but that doesn't seem to be possible.
Like it should find that there is a match and as long as there are >=1 matches, it should be happy and continue.