【问题标题】:Chef + InSpec using only_if for usersChef + InSpec 为用户使用 only_if
【发布时间】:2017-01-27 16:27:44
【问题描述】:

我需要查看用户列表并确定他们是否处于锁定状态,我可以做到这一点,但我的问题是我不知道 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

【问题讨论】:

    标签: ruby rspec chef-infra chef-recipe inspec


    【解决方案1】:

    您只能在 control 块内使用 only_if 和类似的 API。您可能首先希望使用 user InSpec 资源,但也请查看 users API。

    【讨论】:

      猜你喜欢
      • 2017-03-01
      • 1970-01-01
      • 2014-09-05
      • 2021-04-11
      • 2018-01-12
      • 1970-01-01
      • 2016-12-09
      • 2016-12-15
      • 1970-01-01
      相关资源
      最近更新 更多