rubychef-infra

Customize logs in inspec chef


Ruby/chef/inspec newbie here.

We are using inspec chef for testing existence of the user in linux.

When running something like

describe user(username) do
      it "should exist" do
        # The existence check itself is included in the custom description.
        expect(subject.exists?).to eq(true)
      end
    end

it prints the following message.

 User user1 is expected to exist

Is there any way to suppress the message or customize it?

Thanks


Solution

  • Inspec supports reporters to customize your output. It's not entirely clear to me what you want changed from the output, but if you want something more terse, the progress or progress-bar reporters seem to be what you might be after.

    inspec exec example_profile --reporter progress
    

    looks like it will give you the classic progression of dots.

    If you want to customize the output of the line, The User class is defined in inspec at https://github.com/inspec/inspec/blob/main/lib/inspec/resources/users.rb#L314

    It just has a simple to_s method.

    You could override that method in your setup. For example,

    module Inspec::Resources
      class User
        def to_s
          "User (redacted)"
        end
      end
    end