To test if the correct consul version is installed on my servers, I am trying to write an inspec test. The idea is to call this test with mutiple ip addresses, parse it against json (which I get from the consul api) and then check the consul version for only the servers that I have the IPs listed for.
Now I am struggling with iterating over the json and then only checking the correct servers.
It should look something like this:
describe json(content: http('http://172.17.0.1:8500/v1/agent/members').body) do
for i in 0..2 do
ip_addresses.each { |node| its ([i, 'Tags', 'build']) { should match consul_version }.where(['Addr'] == node) }
end
It doesn't work of course, but I think it explains what I am trying to achieve.
Is there an approach that would allow me to do this?
Edit: The json boils down to this:
[
{
"Addr": "192.100.100.100”,
"Name": “machine0”,
"Tags": {
"build": "1.11.3",
}
},
{
"Addr": "192.100.100.101”,
"Name": “machine1",
"Tags": {
"build": "1.11.3”,
}
},
{
"Addr": "192.100.100.102”,
"Name": “machine2”,
"Tags": {
"build": "1.11.3",
}
}
]