Techioz Blog

Ruby Inspec - description.1 ですが、オプションの 1 つは 2 つの description コマンドを必要とします

概要

それほど複雑ではない Ruby Inspec ファイルがありますが、それを適切に構造化する方法がわかりません。基本的には、rsync がインストールされていないか無効になっているかを確認する必要があります。無効になっているかどうかを確認するには、systemctl is-active rsync と systemctl is-enabled rsync を実行します。次に、出力をそれぞれ非アクティブと無効に一致させます。

control "my control" do
  title "title"
  desc "desc"

  describe.one do
    describe package('rsync') do
      it { should_not be_installed }
    end

    # These two should be treated as one option
    describe command('systemctl is-active rsync') do
      its('stdout') { should match "^inactive$" }
    end
    describe command('systemctl is-enabled rsync') do
      its('stdout') { should match "^disabled$" }
    end
  end
end

解決策

次のようなことを試してください。

control "my control" do
  title "title"
  desc "desc"

  if package('rsync').installed?
    # These two should be treated as one option
    describe command('systemctl is-active rsync') do
      its('stdout') { should match "^inactive$" }
    end
    describe command('systemctl is-enabled rsync') do
      its('stdout') { should match "^disabled$" }
    end
  end
end

または、次のようなことができるはずです。

control "my control" do
  title "title"
  desc "desc"

  describe.one do
    describe package('rsync') do
      it { should_not be_installed }
    end

    describe 'rsync is inactive and disabled' do
      # These two should be treated as one option
      describe command('systemctl is-active rsync') do
        its('stdout') { should match "^inactive$" }
      end
      describe command('systemctl is-enabled rsync') do
        its('stdout') { should match "^disabled$" }
      end
    end
  end
end