Chef Certified study materials
Chef Certified study resources

Chef Certified practice questions

One question at a time. Build your Chef Certified understanding.

First 50 of 199 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.

Continue in the practice tool above to load more questions, 50 at a time.

Question 1Chef Automation and Infrastructure Management

In a Chef Infra recipe, which resource is used to declare that a package should be installed through the node's platform package manager?

  1. package Correct answer.
  2. service
  3. template
  4. cookbook_file

Explanation

The package resource is the platform-agnostic way to install software; Chef selects the correct provider (apt, yum, dnf, etc.) based on node attributes. It supports version pinning and options passed to the underlying package manager. Other resources manage services or files, not package installation.

Question 2Chef Automation and Infrastructure Management

A recipe contains `file '/etc/motd' do content 'Authorized use only' end`. What happens when the file already exists with exactly that content on the next Chef Infra Client run?

  1. The file is rewritten unconditionally and the resource always reports as updated
  2. The Chef Infra Client run fails because the file resource requires an explicit action
  3. The file is deleted and recreated to guarantee the correct content
  4. The resource is skipped because the file content already matches, so no update is reported Correct answer.

Explanation

Chef resources are idempotent: the provider checks current state (here, file content) and only takes action when it differs from the desired state. When content already matches, the resource is up to date and is not counted as updated. This idempotence is why repeated converges produce no changes.

Question 3Chef Automation and Infrastructure Management

Which directory in a cookbook holds ERB templates that are rendered by the template resource?

  1. files/
  2. recipes/
  3. templates/ Correct answer.
  4. attributes/

Explanation

Templates live under the cookbook's templates/ directory, conventionally in a subdirectory named after the node's platform so the right variant is selected. The template resource looks there by default when resolving the source property.

Question 4Chef Automation and Infrastructure Management

What is the purpose of the metadata.rb file in a cookbook?

  1. It declares the cookbook's name, version, supported platforms and dependencies Correct answer.
  2. It stores the node's Ohai data collected at the start of the run
  3. It contains the encrypted data bag secret used during the run
  4. It lists the run_list that the Chef Infra Client will execute

Explanation

metadata.rb describes the cookbook itself: name, version, maintainer, supported platforms and cookbook dependencies. Chef uses this information for dependency resolution and policy compilation. It is not a place for node data, run lists or secrets.

Question 5Chef Automation and Infrastructure Management

Which Chef Infra Client command uploads cookbooks from the local chef-repo to the Chef Infra Server?

  1. knife bootstrap
  2. knife node upload
  3. knife supermarket install
  4. knife cookbook upload Correct answer.

Explanation

knife cookbook upload transfers one or more cookbooks, with their metadata and dependencies, to the Chef Infra Server so nodes can use them. It validates metadata and dependency versions during upload. The other commands handle nodes, Supermarket cookbooks or initial node setup.

Question 6Chef Automation and Infrastructure Management

Which file in a cookbook is evaluated first and can set default, normal or override attribute precedence levels?

  1. templates/default.erb
  2. metadata.rb
  3. recipes/default.rb
  4. attributes/default.rb Correct answer.

Explanation

Attribute files under attributes/ are evaluated before recipes, and attributes/default.rb is the conventional entry point. They set default, normal or override attributes with the desired precedence. Recipes run afterwards and see the resulting attribute values.

Question 7Chef Automation and Infrastructure Management

What does the `notifies :restart, 'service[nginx]', :delayed` notification on a template resource do?

  1. Queues a restart of the nginx service to run at the end of the converge phase Correct answer.
  2. Fails the run if nginx is not already running
  3. Restarts nginx immediately when the template is rendered
  4. Restarts nginx before the template resource is evaluated

Explanation

A :delayed notification is collected when the notifying resource changes and is executed at the end of the Chef Infra Client run, after all resources have converged. This avoids restarting a service multiple times when several resources change. The :immediately timing would run the action right away.

Question 8Chef Automation and Infrastructure Management

Which command applies a recipe to a node using the Chef Infra Client in local mode without contacting a Chef Infra Server?

  1. chef-client --local-mode --runlist 'recipe[mycookbook::default]' Correct answer.
  2. knife client create mycookbook
  3. knife cookbook upload mycookbook
  4. chef-solo --server https://chef.example.com

Explanation

Running chef-client with --local-mode (or the chef-zero approach) lets the client converge a run list from local cookbooks without a Chef Infra Server. The --runlist option specifies what to converge. This is useful for development and testing.

Question 9Chef Automation and Infrastructure Management

A recipe sets `node.default['app']['port'] = 8080` in attributes/default.rb, while a role sets `node.override['app']['port'] = 9090`. Which value does the recipe see during the run?

  1. 8080, because default attributes are always the effective value
  2. 9090, because override attributes take precedence over defaults Correct answer.
  3. The run fails with a conflicting attribute error
  4. 8080, because attribute files are evaluated before roles

Explanation

Chef attribute precedence ranks override above default, so the role's override value wins when the recipe reads node['app']['port']. Precedence is determined by level, not by evaluation order. Conflicting values at different precedence levels are resolved silently in favor of the higher level.

Question 10Chef Automation and Infrastructure Management

Which construct in a recipe allows resources to be grouped and conditionally executed only when notified by another resource?

  1. A guard clause using only_if on each individual resource
  2. An include_recipe call at the top of the recipe
  3. A node attribute read inside the resource block
  4. A custom resource declared with action :nothing and triggered by a notification Correct answer.

Explanation

Declaring a resource or custom resource with action :nothing and notifying it from another resource lets it run only when triggered. This pattern is common for one-time setup steps that should execute only when a dependency changes. Guards and include_recipe control execution differently.

Question 11Chef Automation and Infrastructure Management

What is the difference between `include_recipe` and a cookbook dependency declared in metadata.rb?

  1. The dependency executes the cookbook's default recipe automatically, while include_recipe only documents intent
  2. They are interchangeable, and Chef treats them identically during compilation
  3. include_recipe downloads the cookbook from Supermarket, while the dependency only documents it
  4. include_recipe adds a recipe to the run at that point, while the dependency ensures the cookbook is available for resolution Correct answer.

Explanation

A metadata dependency makes another cookbook available so its recipes and resources can be used and resolved by the server or policy compiler. include_recipe actually inserts and evaluates that recipe within the current recipe. A dependency alone does not run any recipe.

Question 12Chef Automation and Infrastructure Management

Which approach correctly reads a secret stored in an encrypted data bag item from within a recipe?

  1. Use search with the index 'data_bag' and read the first result
  2. Use node.run_state to look up the bag item by name automatically
  3. Use the template resource's variables property without loading the item
  4. Use data_bag_item with the bag and item names, relying on the secret configured for the client Correct answer.

Explanation

Encrypted data bag items are decrypted with the secret available to the client, and data_bag_item loads and decrypts the named item for use in the recipe. The secret must be provided to the client through configuration or a secret file. run_state, search and template variables do not decrypt data bags on their own.

Question 13Chef Automation and Infrastructure Management

What does the `sensitive true` property on a resource do?

  1. It encrypts the resource's data when it is stored on the Chef Infra Server
  2. It causes the resource to fail if any secret is detected in its properties
  3. It prevents the resource's rendered content or command output from being logged in the Chef Infra Client output Correct answer.
  4. It restricts the resource to run only on nodes in a specific environment

Explanation

Setting sensitive to true suppresses logging of the resource's content and command output, which protects secrets such as passwords written to files. It affects logging only, not storage or encryption. It is commonly combined with file and execute resources.

Question 14Chef Automation and Infrastructure Management

Which statement about Chef Infra custom resources is correct?

  1. They are defined in a cookbook's resources/ directory and are used like built-in resources in recipes Correct answer.
  2. They must be written in Python and registered with the Chef Infra Server before use
  3. They can only be created inside the site-cookbooks directory of a Chef Infra Server
  4. They replace the need for recipes entirely and cannot call other resources internally

Explanation

Custom resources are Ruby files placed in a cookbook's resources/ directory; Chef exposes them as resources usable in recipes, with their own properties and actions. Internally they can declare other resources to build reusable abstractions. They are not tied to a specific language or server directory.

Question 15Chef Automation and Infrastructure Management

A recipe uses `execute 'migrate' do command 'rake db:migrate' end`. Why might this resource run on every Chef Infra Client run even when nothing has changed?

  1. Chef caches execute commands and reruns them only when the recipe file changes
  2. The execute resource has no guard, so its command runs each time the resource is converged Correct answer.
  3. The command property is ignored unless a not_if guard is present
  4. The execute resource always reports as updated but skips execution after the first run

Explanation

Without a guard such as not_if or only_if, an execute resource runs its command every time it is converged, which breaks idempotence. Adding a guard that checks the desired state prevents unnecessary runs. The execute resource does not cache results between runs.

Question 16Chef Automation and Infrastructure Management

Which guard would correctly prevent an execute resource from running when a file already exists?

  1. only_if { ::File.exist?('/var/lib/app/initialized') }
  2. not_if 'skip_when_missing'
  3. guard 'file_exists', '/var/lib/app/initialized'
  4. not_if { ::File.exist?('/var/lib/app/initialized') } Correct answer.

Explanation

not_if runs the guard and skips the resource when the guard returns true, so not_if with File.exist? skips the command once the marker file exists. only_if would do the opposite, running only when the file exists. Guards accept a string command or a Ruby block.

Question 17Chef Automation and Infrastructure Management

What is the role of the Chef Infra Server's cookbook versioning when multiple environments are in use?

  1. Cookbook versions are ignored inside environments and only run lists matter
  2. Each environment stores its own copy of the cookbook source code
  3. The server automatically upgrades all nodes to the newest cookbook version each run
  4. Environments can pin cookbook version constraints so different nodes converge different versions Correct answer.

Explanation

Environment cookbook_versions constraints let a node's environment select which cookbook versions are eligible during dependency resolution. This allows, for example, production to stay on an older version while staging tests a newer one. The server does not force upgrades automatically.

Question 18Chef Automation and Infrastructure Management

In a Chef Infra policyfile setup, which file defines the run list, cookbook sources and policy name?

  1. metadata.rb
  2. Policyfile.rb Correct answer.
  3. client.rb
  4. knife.rb

Explanation

Policyfile.rb declares the policy name, the run list and the cookbook sources used to build a locked policy. The resulting lockfile pins exact cookbook revisions. It replaces the older roles and environment cookbook-version approach for policy-managed nodes.

Question 19Chef Automation and Infrastructure Management

Which resource is the correct choice to manage a configuration file whose content varies per node and must be rendered from a template using node attributes?

  1. remote_file
  2. cookbook_file
  3. template Correct answer.
  4. directory

Explanation

The template resource renders an ERB template with variables and node attributes, producing node-specific content. cookbook_file copies a static file unchanged, and remote_file downloads from a URL. directory only ensures a directory exists.

Question 20Chef Automation and Infrastructure Management

What does the `supports` stanza in metadata.rb affect?

  1. It documents which platforms the cookbook is intended to support and is used by tooling and dependency checks Correct answer.
  2. It installs platform-specific packages automatically during the run
  3. It restricts the cookbook to run only on the listed platforms at converge time
  4. It defines the cookbook's version constraints for dependencies

Explanation

The supports stanza records intended platform compatibility, which tooling such as Supermarket and some dependency checks use. It does not enforce platform restrictions at converge time, nor does it install packages. Dependency version constraints are declared separately with depends.

Question 21Chef Automation and Infrastructure Management

A node's run list contains `role[web]`, and that role's run list contains `recipe[nginx]`. What does the Chef Infra Client converge?

  1. The nginx recipe only if it is also listed directly in the node's run list
  2. The nginx recipe, expanded from the role's run list, along with the role's attribute and override settings Correct answer.
  3. Only the role resource, because recipes inside roles are not expanded automatically
  4. The nginx recipe twice, once for the role and once for the node

Explanation

Roles are expanded during run-list compilation, so recipes listed in a role are added to the effective run list and their attributes and overrides apply. Chef also de-duplicates recipes so a recipe is not converged twice. Direct listing in the node run list is not required.

Question 22Chef Automation and Infrastructure Management

Which statement best explains why `node.normal` attributes are discouraged compared with `node.default` in cookbooks?

  1. Normal attributes persist on the node object and can mask later default values, making behavior harder to reason about Correct answer.
  2. Normal attributes have lower precedence than default attributes
  3. Normal attributes are not visible to recipes and are ignored during convergence
  4. Normal attributes can only be set by the Chef Infra Server and never in cookbooks

Explanation

Normal attributes are stored on the node and persist across runs, so a value set once can override future default changes and create surprising behavior. Cookbooks should generally set defaults so operators can override them at higher precedence levels. Normal attributes are visible to recipes and have higher precedence than defaults.

Question 23Chef Automation and Infrastructure Management

During a Chef Infra Client run, a resource fails and the run aborts. What is the default behavior regarding resources that had already converged successfully earlier in the run?

  1. Their changes remain applied, and the run ends with a failure that is reported to the server Correct answer.
  2. The run continues with the remaining resources and reports success
  3. All earlier changes are automatically rolled back to their previous state
  4. The client retries the failed resource three times before aborting

Explanation

Chef converges resources in order and does not provide transactional rollback by default, so changes made before the failure persist. The run exits with a failure status and the error is reported. Retries and continue-on-error behavior require explicit configuration.

Question 24Chef Automation and Infrastructure Management

A cookbook uses `search(:node, 'role:db')` inside a recipe. Which condition must hold for this search to return meaningful results?

  1. The nodes must be registered and indexed on the Chef Infra Server, and the client must be able to query the server Correct answer.
  2. The search results must be cached in a local data bag before the run
  3. The search index must be rebuilt manually before every Chef Infra Client run
  4. The recipe must run in local mode with no server configured

Explanation

Chef search queries the server's search indexes, so nodes must exist and be indexed there and the client needs permission to query. In local mode there is no populated server index, so results are limited. Indexing is automatic as nodes check in.

Question 25Chef Automation and Infrastructure Management

A custom resource declares `property :config_path, String, name_property: true` and `action :create`. How is config_path resolved when a recipe uses `my_config 'app' do action :create end`?

  1. It defaults to the cookbook name combined with the resource name
  2. It raises a compile error because name_property cannot be used with String
  3. It remains nil and must be supplied explicitly with config_path
  4. It defaults to the resource's name, 'app', because name_property is set Correct answer.

Explanation

name_property: true makes the property default to the resource block's name when no value is given, so config_path becomes 'app'. This is the same mechanism built-in resources use for their name. String type coercion is compatible with name_property.

Question 26Chef Automation and Infrastructure Management

Which Chef Infra Client command uploads a cookbook to the Chef Infra Server after it has been validated locally?

  1. knife node run_list add
  2. knife cookbook download
  3. knife cookbook upload Correct answer.
  4. knife environment create

Explanation

`knife cookbook upload` transfers a local cookbook, including its version from metadata.rb, to the Chef Infra Server so nodes can fetch it. The download subcommand retrieves cookbooks from the server rather than publishing them.

Question 27Chef Automation and Infrastructure Management

Which file in a cookbook directory holds the recipe code that runs when `recipe[mycookbook::default]` is applied?

  1. attributes/default.rb
  2. recipes/default.rb Correct answer.
  3. files/default.conf
  4. templates/default.erb

Explanation

Recipes live under the recipes directory, and the recipe named `default` is stored as `recipes/default.rb`. Attribute files and template or file directories serve different purposes and are not executed as recipe code.

Question 28Chef Automation and Infrastructure Management

What does the `action :enable` on a `service` resource accomplish during a Chef Infra Client run?

  1. It stops the service and disables it from starting.
  2. It configures the service to start automatically at boot. Correct answer.
  3. It starts the service immediately if it is stopped.
  4. It reloads the service configuration without a restart.

Explanation

The `:enable` action registers the service with the init system so it starts at boot, independent of whether it is currently running. Starting the service now is the `:start` action, and reloading is `:reload`.

Question 29Chef Automation and Infrastructure Management

Which command shows the expanded run list of a node registered on the Chef Infra Server?

  1. knife cookbook list
  2. knife client list
  3. knife data bag show
  4. knife node show NODE -r Correct answer.

Explanation

`knife node show` with the `-r` flag prints the node's run list, which includes roles and recipes in the order the Chef Infra Client will evaluate them. The other commands list cookbooks, data bags or API clients.

Question 30Chef Automation and Infrastructure Management

What is the primary purpose of the `metadata.rb` file in a cookbook?

  1. It declares the cookbook name, version and dependencies on other cookbooks. Correct answer.
  2. It records the attributes that override role defaults.
  3. It stores the run list that nodes should execute.
  4. It defines the Chef Infra Server URL and client key for bootstrapping.

Explanation

`metadata.rb` is the cookbook's manifest: it sets the name, version, maintainer and the `depends` entries that make other cookbooks available during a run. Run lists live on nodes, roles or policyfiles, not in metadata.

Question 31Chef Automation and Infrastructure Management

Which Chef Infra resource is used to render a configuration file from an ERB template with node-specific values?

  1. cookbook_file
  2. file
  3. remote_file
  4. template Correct answer.

Explanation

The `template` resource processes an ERB template with variables from the recipe, producing node-specific content. `cookbook_file` and `remote_file` copy static content without variable interpolation.

Question 32Chef Automation and Infrastructure Management

Which Chef Infra Client command performs a full run using the run list stored on the node?

  1. ohai
  2. chef-shell
  3. chef-client Correct answer.
  4. knife bootstrap

Explanation

Running `chef-client` on a node fetches its run list and cookbooks from the server and converges the node. `ohai` only collects node data, and `knife bootstrap` runs from a workstation to install a client on a new host.

Question 33Chef Automation and Infrastructure Management

What does the `only_if` guard on a resource control?

  1. Whether the resource's action is executed at all during the run. Correct answer.
  2. Which action the resource takes when it converges.
  3. The order in which resources appear in the resource collection.
  4. Which notification the resource sends when it changes.

Explanation

A guard such as `only_if` is evaluated at converge time, and the resource is skipped unless the guard command exits successfully. It does not change the action, notifications, or resource ordering.

Question 34Chef Automation and Infrastructure Management

A recipe needs a value that differs per environment, such as a database hostname, and the value must beat role defaults. Which precedence level should be set in the environment object?

  1. default
  2. normal
  3. automatic
  4. override Correct answer.

Explanation

Environment attributes sit above role defaults, but an environment `override` outranks role `default` and cookbook `default` values. `normal` is persisted on the node and is discouraged for environment-scoped settings, while `automatic` is reserved for Ohai data.

Question 35Chef Automation and Infrastructure Management

A template resource must restart a service only when the rendered file actually changes. Which declaration achieves that?

  1. notifies :enable, 'service[app]', :delayed
  2. notifies :restart, 'service[app]', :immediately Correct answer.
  3. notifies :restart, 'service[app]', :before
  4. subscribes :restart, 'service[app]', :immediately

Explanation

`notifies` fires only when the notifying resource reports an updated state, so the restart is triggered by an actual content change. Using `:immediately` runs the notified action right away rather than queuing it to the end of the run.

Question 36Chef Automation and Infrastructure Management

How does the Chef Infra Client handle a resource declared with `action :nothing`?

  1. It is removed from the resource collection before convergence.
  2. It runs its default action at the end of the run.
  3. It raises a compile error because no action is specified.
  4. It is added to the resource collection but performs no action unless notified. Correct answer.

Explanation

`action :nothing` places the resource in the collection so other resources can notify it, but it does nothing on its own. This pattern is common for deferred restarts or one-off commands triggered by a change.

Question 37Chef Automation and Infrastructure Management

A cookbook must install a package only on nodes running the Debian family. Which recipe construct expresses that condition?

  1. package 'nginx' if node['platform_family'] == 'debian' Correct answer.
  2. package 'nginx' unless node['platform_family'] == 'debian'
  3. package 'nginx' do only_if node['platform_family'] end
  4. package 'nginx' do action :nothing end

Explanation

Ohai populates `node['platform_family']`, and a Ruby `if` modifier on the resource declaration prevents the resource from being added at all on other platforms. Using `only_if` with a bare string value would not evaluate the comparison correctly.

Question 38Chef Automation and Infrastructure Management

What is the effect of declaring `supports` in a cookbook's metadata.rb?

  1. It restricts the Chef Infra Client to running only on listed platforms.
  2. It selects which template variant is rendered for each platform.
  3. It advertises which platforms the cookbook is tested and intended to run on. Correct answer.
  4. It installs platform packages required by the cookbook automatically.

Explanation

`supports` is informational metadata that documents tested platforms and can be surfaced by tooling. It does not enforce platform checks at converge time or install anything.

Question 39Chef Automation and Infrastructure Management

Which approach correctly reads an encrypted data bag item named `db` in bag `secrets` from a recipe?

  1. data_bag('secrets')['db']
  2. search(:secrets, 'id:db')
  3. data_bag_item('secrets', 'db') Correct answer.
  4. node['secrets']['db']

Explanation

`data_bag_item` loads a single item and decrypts it when the item is encrypted and the secret is available to the client. `data_bag` returns only the list of item names, and search returns index results rather than decrypted content.

Question 40Chef Automation and Infrastructure Management

A recipe includes `include_recipe 'apt'` but the cookbook does not declare `depends 'apt'` in metadata.rb. What is the likely outcome?

  1. The run fails because the dependency cookbook is not available in the run's cookbook set. Correct answer.
  2. The include is silently skipped and the run continues.
  3. The recipe is inlined at upload time so no dependency is needed.
  4. The client downloads apt automatically from the Supermarket.

Explanation

Cookbook dependencies must be declared so the server includes them in the cookbook set for the node. Without the `depends` entry, `include_recipe` cannot resolve the cookbook and the run fails.

Question 41Chef Automation and Infrastructure Management

How is a custom resource's `name_property` used when a recipe declares `my_resource '/etc/app.conf'`?

  1. The string is passed to the resource's default action as an argument.
  2. The string becomes the value of the property marked as the name property. Correct answer.
  3. The string is used as the resource's display name only.
  4. The string is written to the node's normal attributes for later runs.

Explanation

When a resource block is given a name and a property is declared with `name_property: true`, that name is assigned to the property if no explicit value is set. This is why resources like `package 'nginx'` treat the name as the package name.

Question 42Chef Automation and Infrastructure Management

Which Chef Infra construct lets a recipe run a block of Ruby code at converge time with access to the current resource context?

  1. ruby_block Correct answer.
  2. script
  3. execute
  4. bash

Explanation

The `ruby_block` resource defers a Ruby block until the converge phase, where it can read and modify node state. The `execute`, `bash` and `script` resources run shell commands rather than in-process Ruby.

Question 43Chef Automation and Infrastructure Management

A policyfile is used to manage a node instead of roles and environments. Which file defines the run list, cookbook sources and default attributes for the policy?

  1. client.rb
  2. Policyfile.rb Correct answer.
  3. knife.rb
  4. metadata.rb

Explanation

`Policyfile.rb` declares the policy name, run list, cookbook sources and default attributes, and is compiled into a lockfile for reproducibility. The other files configure cookbook metadata or client and workstation behavior.

Question 44Chef Automation and Infrastructure Management

Which statement explains why `node.normal` attributes are discouraged for cookbook-managed settings?

  1. They are stored only in memory and are lost after convergence.
  2. They persist on the node and can outrank values set by cookbooks on later runs. Correct answer.
  3. They are ignored by the Chef Infra Server when building the run list.
  4. They are recalculated by Ohai on every run and overwrite recipe values.

Explanation

Normal attributes are saved in the node object on the server, so a value written once can survive and override cookbook defaults in subsequent runs. Cookbooks should prefer `node.default` for values they manage.

Question 45Chef Automation and Infrastructure Management

A recipe uses `search(:node, 'role:db')` to find database servers. Which condition is required for meaningful results?

  1. The Chef Infra Client must be running in client mode with access to the Chef Infra Server search index. Correct answer.
  2. The nodes must be listed in the cookbook's metadata.rb supports stanza.
  3. The recipe must be executed with `chef-client --local-mode`.
  4. The search results must be cached in an encrypted data bag first.

Explanation

Search queries the Chef Infra Server's Solr index, so the client needs server connectivity and the node data must have been indexed. Local mode has no server index, and metadata does not register nodes for search.

Question 46Chef Automation and Infrastructure Management

A recipe writes a file with `file '/etc/app/secret.conf'` that contains credentials. Which property keeps the credential value out of Chef Infra Client log output?

  1. sensitive true Correct answer.
  2. content lazy { secret }
  3. guard_interpreter :default
  4. mode '0600'

Explanation

`sensitive true` suppresses the resource's rendered content and command output from logs and reports. File permissions such as `0600` limit access on disk but do not redact log output.

Question 47Chef Automation and Infrastructure Management

During a Chef Infra Client run, a resource fails and the run aborts. What happens by default to resources that had already converged successfully?

  1. They are re-run in reverse order to undo their changes.
  2. They are reverted to their previous state automatically.
  3. They remain converged; the client does not roll them back. Correct answer.
  4. They are removed from the node's resource collection permanently.

Explanation

Chef Infra is not transactional: resources that converged before the failure keep their changes, and the run simply stops. Fixing the failure and re-running converges the remaining resources.

Question 48Chef Automation and Infrastructure Management

A cookbook needs a helper method usable inside its recipes. Where should the method be defined so recipes in that cookbook can call it?

  1. In attributes/default.rb as a Ruby method definition.
  2. In the templates directory as an ERB helper.
  3. In a library file under libraries/ that reopens the Chef recipe DSL module. Correct answer.
  4. In metadata.rb above the depends entries.

Explanation

Library files under `libraries/` are loaded before recipes and can add methods to the Chef recipe DSL, making them callable from recipes. Attribute and metadata files are evaluated as data, not as a method namespace for recipes.

Question 49Chef Automation and Infrastructure Management

A recipe uses `execute 'migrate'` with a command that is not idempotent. Which addition makes the resource converge only when the schema version file is missing?

  1. not_if { ::File.exist?('/var/lib/app/schema_v3') } Correct answer.
  2. action :nothing
  3. ignore_failure true
  4. only_if 'test -f /var/lib/app/schema_v3'

Explanation

`not_if` skips the resource when its condition is true, so the migration runs only while the marker file is absent. Using `only_if` with the same test would invert the logic and run only when the file exists.

Question 50Chef Automation and Infrastructure Management

Which statement about Chef Infra roles and environments is accurate when a node uses both?

  1. An environment supplies the run list, while a role pins cookbook versions.
  2. Roles and environments both pin cookbook versions with equal precedence.
  3. A role pins cookbook versions, while an environment only groups nodes for reporting.
  4. A role supplies run list entries and default attributes, while an environment scopes cookbook versions and can supply overrides. Correct answer.

Explanation

Roles bundle run lists and default attributes, and environments constrain which cookbook versions nodes may use while also carrying attribute overrides. Version pinning is the environment's responsibility, not the role's.