Skip to content

Instantly share code, notes, and snippets.

@tyler-ball
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyler-ball/82be00c5c88fbdfe0952 to your computer and use it in GitHub Desktop.
Save tyler-ball/82be00c5c88fbdfe0952 to your computer and use it in GitHub Desktop.
Audit mode examples - error on duplicate controls blocks

Two controls blocks cannot be named the same. Doing so will raise a compilation error as seen with the following code:

# cookbook: example
# recipe: default
controls "mysql audit" do

  control "mysql package" do
    it "should be installed" do
      expect(package("mysql")).to be_installed.with_version("5.6")
    end
  end

end

controls "mysql audit" do

  control "mysql package" do
    it "should be installed" do
      expect(package("mysql")).to be_installed.with_version("5.6")
    end
  end

end

Running the recipe[example::default] recipe on a node would produce the following output:

Compiling Cookbooks...

================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/tyler-mysql/recipes/default.rb
================================================================================

Chef::Exceptions::AuditControlGroupDuplicate
--------------------------------------------
Audit control group with name 'mysql audit' has already been defined

Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/tyler-mysql/recipes/default.rb:29:in `from_file'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/tyler-mysql/recipes/default.rb:

 22:      it "should be installed" do
 23:        expect(package("mysql")).to be_installed.with_version("5.6")
 24:      end
 25:    end
 26:
 27:  end
 28:
 29>> controls "mysql audit" do
 30:
 31:    control "mysql package" do
 32:      it "should be installed" do
 33:        expect(package("mysql")).to be_installed.with_version("5.6")
 34:      end
 35:    end
 36:
 37:  end
 38:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment