The topics for this guide are taken directly from training.chef.io. I copied the bulleted lists, and I filled in the study information from either my own understanding or from docs.chef.io.
https://training.chef.io/static/Basic_Chef_Fluency_Badge_Scope.pdf
The Basic Chef Fluency badge is awarded when someone proves that they understand the core elements that underpin Chef. Candidates must show:
- An understanding of basic Chef terminology.
- An understanding of Chef product offerings.
- An understanding of Chef's design philosophy.
- An understanding of Chef's approach to workflow and compliance.
- An understanding of basic Chef coding skills.
Here is a detailed breakdown of each area.
Candidates should understand:
When a node is converged, chef-client first tests to see if the node is in the same state as defined by the recipe. If it is not, then it repairs the node in accordance to the recipe.
Default actions
-
The
:nothing
action- This simply means that this resource will do nothing to the node unless told otherwise.
-
The
supports
directive- The
supports
directive specifies the platform that the cookbook supports. This is specified within the cookbook'smetadata.rb
.
- The
-
The
not_if
andonly_if
directives- You may specify that a resource takes action only if or not if another requirement is met or not met.
Candidates should understand:
- A recipe is an ordered script within a cookbook that can be called within a chef-client run.
- The resources of a recipe are called in the order in which they are written because some require that others exist or not before they can be called.
- To include another recipe within a recipe, one must first make the cookbook dependent upon that recipe within the metadata of that cookbook. Then you may use the
include_recipe
resource within the recipe to actually execute that dependent recipe.
- The node will be idempotent, so as the recipe runs a subsequent time, it will again test and repair.
- A resource can notify another resource of its actions in order for the secondary resource to take action based upon the primary resource's actions. Conversely, a resource can subscribe to another resource to listen for its actions and take action itself based on the actions of the resource to which is it subscribed.
Candidates should understand:
- A cookbooks' primary contents include recipes, attributes, resources, metadata,
.kitchen.yml
, data bags, roles, environments.
- Underscores should be used instead of hyphens.
- You can declare the dependencies of your cookbook on other cookbooks by including those cookbooks in the
metadata.rb
by usingdepends '<cookbookname>', 'versionoptional'
. If you're using dependencies that are not stored in source control or the Supermarket, you may use Berks to upload those dependencies to the Chef server from your workstation.
- If there is only one recipe in the cookbook, then this will be called the default recipe. The default recipe is called when the cookbook is listed without a recipe name in a run list.
Candidates should understand:
- The Chef server can store a number of different artifacts for use by the chef-client. These include but are not limited to: roles, environments, data bags with data bag items stored inside, attributes, cookbooks, policies, clients, organizations, node attributes / OHAI data.
- The Chef server receives OHAI data, which contains all of the node data from the chef-client after it is run.
- When using Chef solo, all of the artifacts are stored on the workstation in which you are working, whereas when you are using the Chef server, those artifacts are stored on the Chef server.
- If Chef server being a single point of failure being a huge risk for you, then you can run Chef server in high availability mode, which means it has redundancy.
- If the chef-client is on the node being configured, then it scales more easily because a server doesn't have to do all the work. Scaling with High Availability (HA) is also an option.
Candidates should understand:
knife search
commands can be used to search the Chef server.
knife search node "<index>:<search_query>"
may be invoked or you may search in the Chef server UI (nodes > attributes).
- Node data is indexed on the Chef server. That data may be accessed through a search query in any of the following ways:
- within the recipe
- by using the
knife search
command - the search method in the Recipe DSL
- the search box in the Chef management console
- by using the
/search
or/search/INDEX
endpoints in the Chef server API
- A databag is a directory of data that is stored on the Chef server.
- You would use the
knife search
command to get a list of nodes on which you need to perform actions.
knife search node "<index>:<search_query>"
Candidates should understand:
- The Chef client is an agent installed on the nodes being configured.
- While the client is installed on the nodes being configured, the server stores the necessary configuration information for the client to access.
- The
--why-run
command is similar to Terraform'sterraform plan
command. It tells you what would happen and change if you were to converge. It does run the executable, but it doesn't actually modify the system.
chef_zero
would be the provisioner, and you'd use local mode if you weren't using a proper Chef server. All of the data would be accessed from
- The node on which Chef client is installed has a client.rb file which contains a link and credentials to access the Chef server. The Chef server never accesses the Chef client; it merely holds the data that the client will need to access. The Chef client communicates to the Chef server over https (port 443) or http (port 80).
- The client configures the node that it is on based on the run-list it is given during the bootstrap or knife commands.
Candidates should understand:
- A node is a machine that is being configured by the Chef client.
- A node object is data that is given to the Chef server to store by the Chef client after
chef-client
is run which contains OHAI data as well as attributes.
- A node object is data that is given to the Chef server to store by the Chef client after
chef-client
is run which contains OHAI data as well as attributes.
- Nodes may be managed through the Chef server UI or through knife commands.
- Nodes may be searched through using the
knife search node
command. For exampleknife search node "platform:ubuntu"
.
- Nodes are named either during a bootstrap or by changing the
client.rb
file on the node.
Candidates should understand:
- A run_list is added to a node either during a bootstrap or by changing the
client.rb
file on the node. It contains all of the cookbooks, recipes, and roles for the node.
- A nested run_list simply means that when a role has a run-list and you add that role to a run-list, it becomes nested.
- For example:
security
role has a run-list that includescloudpassage::default, hardening::centos
and then your node has a run-list that includesrole[security]
in it
- For example:
- A run_list is stored both on the Chef server and in the node's
client.rb
.
- A run_list consists of all of the recipes and cookbooks to be run on the node as well as the roles assigned to it, which contain their own recipes and cookbooks.
- You may find a node's run_list in 3 ways:
- Look in the UI under Nodes > Details > Run List.
- Run
knife node show <nodename>
- In the node, look at the
client.rb
file.
- You can set and change run_lists in much the same way that you can view them.
- Look in the UI under Nodes > Details > Run List > Edit.
- After you've insured that your desired cookbooks are uploaded to the Chef server, run
knife node run_list add <nodename> 'recipe[<cookbookname>::<recipe>]'
ORknife node run_list add chefkata7 'role[security]'
- In the node, look at the
client.rb
file (not best practice).
Candidates should understand:
- A role sets the patterns and processes for a node. Each node may have any amount of roles or none. A role can be thought of in two different ways:
- the role of the machine
- the role of the team/person setting the run lists (not best practice)
- A role ensures code consistency by giving that node all of the same patterns and processes as well as attributes.
- Roles are stored in the chefrepo sibling to cookbooks on your workstation or on the node if you're running it in local mode. Otherwise, they're stored on the Chef server.
- Roles are defined in a
.json
or.rb
file within aroles
directory sibling to thecookbooks
directory in achefrepo
which is uploaded to the Chef server. Or you may create a role within the UI of the Chef server: Policy > Roles > Create.
- The main components Roles consist of a run list and attributes (both default and override).
- A role, recipe, and run_list can each call various recipes in different ways.
- A role will be assigned to a node and may or may not have its own run_list that will be included for that node.
- A recipe can use the
include_recipe
resource in order to run a recipe that is included in that cookbook's dependencies within themetatdata.rb
file. - A run_list is assigned to a node using the
bootstrap
orknife
command. It may contain both recipes and roles.
- The name of the role is defined by the name of the
.json
or.rb
file that you create in theroles
directory as well as the metadata within that file. This may also be done within the UI of the Chef server. The requirements for the name are that it must be:- unique to its organization
- made of letters (upper and/or lower-case), numbers, underscores, and/or hyphens (no spaces allowed).
- Roles are assigned to nodes through the bootstrap, knife, or UI, and they are then applied when
chef-client
is run.
Candidates should understand:
- Environments are assigned to nodes to determine which phase of the release cycle that node represents. This include but are not limited to development, user acceptance testing, and production.
- An environment is assigned to a node in order to give it the appropriate version of the cookbooks in the run_lists. The earlier in the release cycle that the environment assigned to the role is, the later versions of the recipes it will be assigned to.
- Environments are assigned to nodes, and then that node data is returned to the Chef server. You can then use that data within a recipe to constrain attributes to particular environments.
- Environments are assigned to nodes through:
- the UI under Nodes > Attributes > Edit.
- bootstrap and knife commands
- by editing the
client.rb
file
- You may also change a node's environment with a
knife exec
command.
Candidates should understand:
- If your infrastructure is code, then you know your the state of your infrastructure just by looking at the code. You can then easily alter your configuration and use version control to promote changes easily through development.
- Scalability
- version control
- dynamic infrastructure
- simplicity and flexibility for managing and provisioning infrastructure
- Rolling back would be to undo the configuration changes made to your infrastructure. This is not best practice with Chef, as you're only allowed to roll back due to the nature of idempotency. You would need to first change your recipe to intentionally undo the changes to the infrastructure that you wanted to "roll back". Then you'd redefine the desired state in your recipe and instill those changes by converging again.
Candidates should understand:
- An imperative approach to configuration management would be something like running a shell or Powershell script that consecutively executes commands on a node. Chef, however, uses a declarative approach which would declare the desired state of configuration within the Chef server and perform that configuration management through the Chef client installed on the node.
- A push approach would be if the node that was being configured was idle while the server pushed a policy of configuration desired state to the node. This would mean that there is nothing additional being installed on the node being configured, only what is in the policy. A pull approach is what Chef employs, which means that the Chef server is idle while the client that is installed on the node being configured pulls the necessary data from the Chef server that it needs to complete its configuration given to it through a bootstrapping process.
- Windows Desired State Configuration is Windows' configuration management tool based on Powershell which employs declarative programming.
- If you remove a resource from a recipe that has already run on the node, then nothing will happen. Whatever that resource did the first time it ran will still be in effect unless you intentionally undo its effects.
Candidates should understand:
- The Supermarket is a storehouse full of FREE cookbooks available to use and maintained by Chef. They are easily depended upon in your own cookbooks.
- The Supermarket can store cookbook and other tools such as InSpec profiles.
- A company may have their own private supermarket for use internally. These must be maintained by them and can only be accessed by them.
- You would want to use a private Supermarket when you wanted to produce and promote your own cookbooks.
- The Supermarket is FREE for anyone to use.
- Everything within the Supermarket is FREE to use for anyone.
Candidates should understand:
- When the Chef DK is installed on your workstation, you're able to develop with Chef and therefor able to completely configure your infrastructure.
- Audit > Remediate > Certify - TDD allows you to develop based on red/green/refactor. You first test for the desired state, and when it fails you write the desired state in your recipe. You then test again, and it passes.
- Chef-client and OHAI
- Chef CLI
- InSpec / ChefSpec / Cookstyle / Foodcritic
- Chef provisioning
- Knife / Berks / Spork
- Test Kitchen
Candidates should understand:
- Test Kitchen is at the heart of TDD within Chef. Being able to test your configuration before changing the state of your machine is invaluable because you can configure the state of a throw-away machine without having to change your actual infrastructure.
- Test Kitchen is at the heart of TDD within Chef. Being able to test your configuration before changing the state of your machine is invaluable because you can configure the state of a throw-away machine without having to change your actual infrastructure.
- Linux and Windows
- You can add
kitchen test
into your pipeline, and it will run through the entire Kitchen cycle (create, converge, verify, destroy). If it does not pass, then you can halt your build or promote if it passes.
kitchen create
kitchen converge
kitchen login
kitchen verify
kitchen destroy
kitchen test
- Driver- What is creating your VM?
- Provisioner- What is running Chef?
- Verifier- What is running the tests? (probably InSpec)
- Transport- What are you using to remote to a machine?
- Suites- What are the machines are you making?
- Platform- What OS are you using?
Candidates should understand:
- "Effective cross-team collaboration" Chef Automate tracks and tests dependencies between projects and teams. Deploy safely, even in a multi-team, multi-project environment where there are complex inter-dependencies.
- Full oversight
- Change management
- Governance
- Built-in compliance
- Workflow is similar to Jenkins or Team City, as it defines and automates the CI/CD pipeline. It affects productivity by promoting the next build in the previous one had passed. You're able to release code faster when the automation process is in charge of promotion. The safeguard of promoting only the builds that pass validation contributes to productivity, as well.
- In the same way that workflow adds safeguards which contribute to productivity
- It provides insight on how changes affect the state of Chef on the nodes.
- You create your own server, then you reference your private supermarket in your Berksfile so that Chef server grabs the cookbooks from there.
- The open source components of Automate include:
- InSpec
- Chef
- Habitat
- Visibility is a tool within Chef Automate that allows you to see the state of infrastructure across your entire organization.
- Habitat is a tool within Chef Automate for the managing and packaging of applications.
- InSpec is a framework with which to automate security and compliance tests.
- Compliance is the tool created on top of the InSpec framework which integrates within Chef Automate.
Candidates should understand:
- Audit (InSpec/Compliance) > Remediate (Chef/Workflow/Habitat) > Certify (Visibility)
- Workflow defines and automates the CI/CD pipeline.
- Compliance defines and automates compliance validation.
- Audit (InSpec/Compliance) > Remediate (Chef/Workflow/Habitat) > Certify (Visibility)
- Audit (InSpec/Compliance) > Remediate (Chef/Workflow/Habitat) > Certify (Visibility); TDD
- "Effective cross-team collaboration" Chef Automate tracks and tests dependencies between projects and teams. Deploy safely, even in a multi-team, multi-project environment where there are complex inter-dependencies.
- Full oversight
- Change management
- Governance
- Built-in compliance
- Cookbooks for hardening and patch management
- InSpec and Compliance within Workflow for promotion of safe cookbooks
- Visibility for validation of compliance
- Habitat for application packaging
- Test Kitchen for TDD
- Workflow for promotion of code through the pipeline
- Compliance for health checks
- Chef for infrastructure as code
- Visibility for state of affairs
- Visibility for state of affairs to assess risk of change and to verify the reliability of a version from a previous environment
- Workflow for approval process
- Chef enforces consistency across infrastructure by having roles and environments, and Workflow helps to ensure that changes are consistently applied.
Candidates should understand:
- Chef is a thin domain-specific-language, meaning that it was built on top of Ruby. This means that you're able to easily customize with Ruby.
- If you'd like to customize your cookbook, then you can use raw Ruby anywhere in the cookbook.
- Ruby code can be stored in a cookbook's
libraries
directory and can be implemented / called anywhere in the cookbook's recipes or custom resources.
Candidates should understand:
- You must state explicitly what you want Chef to do in your configuration.
- Common actions include :nothing, :create, :sync, :delete, :run, :start, :restart, :stop, :status, etc.
- Rolling back would be to undo the configuration changes made to your infrastructure. This is not best practice with Chef, as you're only allowed to roll back due to the nature of idempotency. You would need to first change your recipe to intentionally undo the changes to the infrastructure that you wanted to "roll back". Then you'd redefine the desired state in your recipe and instill those changes by converging again.
- Resources are executed in the order in which they are written. So if you were to reverse them, Chef client would test and repair them in that new order.
- Yes and no.
- Identify which patches are required
- Apply and evaluate the patches in a testing environment
- Distribute the patches to the rest of the fleet
- Confirm the patches have been applied successfully with InSpec
Candidates should understand:
- A push approach would be if the node that was being configured was passive while the server pushed a policy of configuration desired state to the node. This could mean that there is nothing additional being installed on the node being configured, only what is in the policy. A pull approach is what Chef employs, which means that the Chef server is passive while the client that is installed on the node being configured pulls the necessary data from the Chef server that it needs to complete its configuration given to it through a bootstrapping process.
- The major benefit of a pull model is scalability. The server that houses the data needed for configuration is not strained trying to configure all of the nodes. Instead the client installed on the node does the configuration itself.
- When you need to run a job independently of a
chef-client
run, a push job may be appropriate. This will allow you to send a job to a node independently of the client. A push model may also be required when orchestrating changes in an order amongst different types of servers.
- The Chef client communicates to the Chef server over https (port 443) or http (port 80).
- Converge intervals are configured by the Chef client cookbook that you would include in your run list. Push jobs would be employed to invoke immediate updates.
Candidates should understand:
- A wrapper cookbook is the main cookbook that you write that you include dependent cookbooks inside that don't contain all of the functionality that you need. The wrapper would extend the dependent cookbook to include the additional functionality that you need.
- Storing your repos and cookbooks in source control, such as GitHub, allows you to collaborate with others on development as well as branch, fork, and promote.
- TDD allows you to develop based on red/green/refactor. You first test for the desired state, and when it fails you write the desired state in your recipe. You then test again, and it passes. This is done with Test Kitchen.
Candidates should understand:
- Continuous delivery is a software engineering approach in which teams produce software in short cycles, ensuring that the software can be reliably released at any time. It aims at building, testing, and releasing software faster and more frequently. (Wikipedia)
- Chef allows for TDD with Test Kitchen, which produces reliability. And storing in source control makes it easier to develop collaboratively, leading to faster releases as the most reliable and stable branches are promoted through the environments.
- Tests should be run every time a change is made or the node is converged.
- Uniformity through automation minimizes error.
- Removing the risk of human error, you can see your infrastructure and compliance as code, seeing its state in code before it is actually changed.
Candidates should understand:
- A test is more reliable if nothing is installed on the node being installed because you don't have to change the state of the node being tested; you merely have to inspect it.
- You simply need to be able to have remote access to the node in order for the InSpec framework to use your profile to scan the node being inspected.
- Regulatory security and compliance standards
- Configuration validation
- State discovery
- InSpec
Candidates should understand:
- Test Kitchen is at the heart of TDD within Chef. Being able to test your configuration before changing the state of your machine is invaluable because you can configure the state of a throw-away machine without having to change your actual infrastructure.
- cookbook development (as well as other node data such as roles and environments)
- bootstrapping nodes with the Chef client
- communicating with the Chef server
Candidates should understand:
- One would use a
knife
command to upload artifacts to the Chef server.
- Berkshelf is a tool which one can use to upload artifacts such as cookbooks to the Chef server.
If the Chef Automate workflow feature can push artifacts to things other than a Chef server or Supermarket
- Yes, Chef Automate can push artifacts to places like GitHub or production servers.
- Each cookbook that a cookbook is dependent upon must be included in that cookbook's metadata. After executing a
berks install
,
Candidates should understand:
- Chef is a thin domain-specific-language, meaning that it was built on top of Ruby. This means that you're able to easily customize with Ruby.
- Ruby code can be stored in a cookbook's
libraries
directory and can be implemented / called anywhere in the cookbook's recipes or custom resources.
- Chef is a thin domain-specific-language, meaning that it was built on top of Ruby. This means that you're able to easily customize with Ruby.
Candidates should understand:
How to read a recipe that includes the 'package', 'file', and 'service' resources and describe its intent.
- (studied in kata)