[英]Chef + InSpec using only_if for users
I need to go through a list of users and determine whether they are in a locked state, I can do this just fine but my issue is that I don't know how inspec will let me ignore users on my list that don't exist on the operating system. 我需要查看用户列表并确定他们是否处于锁定状态,我可以做到这一点,但是我的问题是我不知道inspec将如何让我忽略列表中不存在的用户在操作系统上。 I've tried a few different methods using only_if (including below) with no luck.
我已经尝试过使用only_if(包括以下内容)的几种方法,但都没有运气。
Here is my code below: 这是我的代码如下:
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
You can only use only_if
and similar APIs from inside a control
block. 您只能在
control
块内部使用only_if
和类似的API。 You would probably want to use the user
InSpec resource for this in the first place but also check out the users
API. 您可能首先想使用
user
InSpec资源,但也要签出users
API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.