2016-09-19 70 views
0

我需要通过用户列表,并确定他们是否处于锁定状态,我可以做到这一点很好,但我的问题是,我不知道inspec将如何让我忽略列表中不存在于操作系统上的用户。我尝试了一些使用only_if(包括下面)的方法,但没有运气。厨师+ InSpec使用only_if为用户

这里是我下面的代码:

system_accounts = [ 
'user1' 
'user2' 
'user3' 

system_accounts.each do |name| 
    only_if command("getent passwd #{name}") do 
    describe command("passwd -S #{name}").stdout.split[1] do 
    it { should match /LK|NP|NL/ } 
    end 
    end 
    end 
end 

回答

0

您只能使用only_if和类似的API从control块内。您可能首先需要使用user InSpec资源,但也可以查看users API。