Conditional Execution
InSpec controls can be conditionally executed based on additional requirements expressed through InSpec helpers and language constructs.
Profile Attributes:
only_if
only_if do command('git').exist? endif
if os.linux? ... enddescribe.one
describe.one do describe file('primary.cfg) do its('content') { ... } end describe file('seconday.cfg) do its('content') { ... } end endsupports
supports: os-family: OSFAMILY
My Activity
For this activity I have two docker instances running, a CentOS and a Ubuntu image. The Ubuntu instance has git installed, and in the CentOS instance I have created a file hello.txt in the root directory with a content of "Conditional test" inside of it.
Execution on CentOS
Output:
Execution on Ubuntu:
Output:
When I change supports os-family to windows in the
inspec.ymlfile and execute on the linux instances i.e. Ubuntu & CentOS in my case. My inspec.yml file looked like this:Execute:
Output:
Last updated