Inspec配置文件中的决定

问题描述 投票:0回答:1

我正在运行一个postgres inspec配置文件,并且仅当该节点是主节点时,才想运行某些测试。这是我的个人资料

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

但是这不起作用,因为变量结果不存储值'f'。

我的问题是如何将值存储在变量中,并将其用于inspec中的下一个测试?我们如何在inspec中打印变量值(调试语句)

postgresql chef inspec
1个回答
0
投票

仅从我的记忆中来讲,您应该将sql查询分配给一个变量,将该变量传递给describe块,以便您可以使用匹配器(但感觉到您并不需​​要它),然后放置一个该变量的条件。它应该是这样的:

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
© www.soinside.com 2019 - 2024. All rights reserved.