I'm running a postgres inspec profile and would like to run certain tests only if the node is a master node. Here is my profile
sql = postgres_session('postgres', password, 'localhost')
result = describe sql.query('SELECT pg_is_in_recovery()') do
its('output') { should eq 'f' }
end
if result == 'f'
describe sql.query('SELECT state from pg_stat_replication') do
its('output') { should match 'streaming' }
end
end
But this doesn't work as the variable result doesn't store value 'f'.
My question is how do i store a value in a variable and use that for the next test in inspec ? How do we print variable values in inspec (debug statements)
speaking only from my memory, you should assign the sql query into a variable, pass that variable to the describe block so you could use the matcher (but it feels that you do not need it in your case), and then place a condition on that variable. it should be something like:
sql = postgres_session('postgres', password, 'localhost')
result = sql.query('SELECT pg_is_in_recovery()')
if result.output == 'f'
describe sql.query('SELECT state from pg_stat_replication') do
its('output') { should match 'streaming' }
end
end