- Chef Tutorial
- Chef - Home
- Chef - Overview
- Chef - Architecture
- Chef - Version Control System Setup
- Chef - Workstation Setup
- Chef - Client Setup
- Chef - Test Kitchen Setup
- Chef - Knife Setup
- Chef - Solo Setup
- Chef - Cookbooks
- Chef - Cookbook Dependencies
- Chef - Roles
- Chef - Environment
- Chef - Chef-Client as Daemon
- Chef - Chef-Shell
- Chef - Testing Cookbooks
- Chef - Foodcritic
- Chef - ChefSpec
- Testing Cookbook with Test Kitchen
- Chef - Nodes
- Chef - Chef-Client Run
- Advanced Chef
- Dynamically Configuring Recipes
- Chef - Templates
- Chef - Plain Ruby with Chef DSL
- Chef - Ruby Gems with Recipes
- Chef - Libraries
- Chef - Definition
- Chef - Environment Variable
- Chef - Data Bags
- Chef - Scripts for Data Bags
- Chef - Cross-Platform Cookbooks
- Chef - Resources
- Lightweight Resource Provider
- Chef - Blueprints
- Chef - Files & Packages
- Chef - Community Cookbooks
- Chef Useful Resources
- Chef - Quick Guide
- Chef - Useful Resources
- Chef - Discussion
Chef - Foodcritic
Writing good cookbooks without any issue is quite a difficult task. But there are ways which can help in identifying the pitfalls. Flagging in Chef Cookbook is possible. Foodcritic is one of the best way of archiving it, which tries to identify possible issues with the logic and style of cookbooks.
Foodcritic Setup
Step 1 − Add Foodcritic gem.
vipin@laptop:~/chef-repo $ subl Gemfile source 'https://rubygems.org' gem 'foodcritic', '~>2.2.0'
Step 2 − Install the gem.
vipin@laptop:~/chef-repo $ bundle install Fetching gem metadata from https://rubygems.org/ ...TRUNCATED OUTPUT... Installing foodcritic (2.2.0)
Foodcritic Gem
Step 1 − Run Foodcritic on the cookbook.
vipin@laptop:~/chef-repo $ foodcritic ./cookbooks/<Cookbook Name> FC002: Avoid string interpolation where not required: ./cookbooks/ mysql/attributes/server.rb:220 ...TRUNCATED OUTPUT... FC024: Consider adding platform equivalents: ./cookbooks/<Cookbook Name>/ recipes/server.rb:132
Step 2 − Generate a detailed report.
vipin@laptop:~/chef-repo $ foodcritic -C ./cookbooks/mysql cookbooks/<cookbook Name>/attributes/server.rb FC002: Avoid string interpolation where not required [...] 85| default['<Cookbook Name>']['conf_dir'] = "#{mysql['basedir']}" [...] cookbooks/<Cookbook Name>/recipes/client.rb FC007: Ensure recipe dependencies are reflected in cookbook metadata 40| end 41|when "mac_os_x" 42| include_recipe 'homebrew' 43|end 44|
Working Method
Foodcritic defines a set of rules and checks recipe agents, each one of them. It comes with multiple rules concerning various areas: styles, connectedness, attributes, string, probability, search, services, files, metadata, and so on.
Advertisements
To Continue Learning Please Login
Login with Google