filter on attribute value

I want to validate my inventory to have only a certain number of hosts
to have a certain value. I tried to do that using assert but I am
unable to find a way to do so.

Example inventory (ini) file:

[nginx]
10.52.130.31

[backends]
10.52.194.41 read_only="true"
10.52.130.2 read_only="false"
10.52.130.31 read_only="true"

Want to validate there is only one host in backends with read_only as
false. Tried a lot of things but could not get it to work.

Any help?

Thank you
Anuj Agrawal

You could default that variable to true in a single location, so it’s easy to spot in the inventory?

True, but I was hoping I could validate that the variable is not set
to true for more than one host.

Something like this should work

  - assert:
      that: groups['backends'] | map('extract', hostvars, 'read_only') | select('equalto', 'false') | list | length == 1