Chef Interview Questions

Chef Interview Questions

Tell me a suggestion you have made that was implemented in this chef field?

Ans. It’s not necessary to give any very complex example, A simple implementation would be enough, which you know very well and have done as exercise. But its important that whatever you say, must be able to explain in detail.

What experience do you have in this chef field?

Ans. It’s not wise to tell a higher number of years and not able to answer accordingly. Always keep the exp as per your knowledge.

In Chef, which file contains hints to the Chef server that enables cookbooks to be deployed in the right node.

Ans. metadata.rb

In Chef, a knife data bag item is encrypted using which of the following methods?

Ans. Shared secret encryption.

What is a resource?
Ans. -A resource represents a piece of infrastructure and its desired state, such as a package that should be installed, a service that should be running, or a file that should be generated.

What is a recipe?
Ans. A recipe is a collection of resources that describes a particular configuration or policy. A recipe describes everything that is required to configure part of a system. Recipes do things such as:

install and configure software components.
manage files.
deploy applications.
execute other recipes.

What happens when you don’t specify a resource’s action?
Ans. When you don’t specify a resource’s action, Chef applies the default action.

Are these two recipes the same?

package ‘httpd’

service ‘httpd’ do    action [:enable, :start]  end

&&

service ‘httpd’ do    action [:enable, :start]    end

package ‘httpd’

Ans. No, they are not. Remember that Chef applies resources in the order they appear. So the first recipe ensures that the httpd package is installed and then configures the service. The second recipe configures the service and then ensures the package is installed.

The second recipe may not work as you’d expect because the service resource will fail if the package is not yet installed.

 Are these two recipes the same?

package ‘httpd’

service ‘httpd’ do    action [:enable, :start]    end

package ‘httpd’

service ‘httpd’ do    action [:start, :enable]    end

Ans. No, they are not. Although both recipes ensure that the httpd package is installed before configuring its service, the first recipe enables the service when the system boots and then starts it. The second recipe starts the service and then enables it to start on reboot.

Are these two recipes the same?

file ‘/etc/motd’ do
owner ‘root’
group ‘root’
mode ‘0755’
action :create
end

file ‘/etc/motd’ do
action :create
mode ‘0755’
group ‘root’
owner ‘root’
end

Ans. Yes, they are! Order matters with a lot of things in Chef, but you can order resource attributes any way you want.

Write a service resource that stops and then disables the httpd service from starting when the system boots.

Ans. service ‘httpd’ do
action [:stop, :disable]
end

How does a cookbook differ from a recipe?
Ans. A recipe is a collection of resources, and typically configures a software package or some piece of infrastructure. A cookbook groups together recipes and other information in a way that is more manageable than having just recipes alone.

For example, in this lesson you used a template resource to manage your HTML home page from an external file. The recipe stated the configuration policy for your web site, and the template file contained the data. You used a cookbook to package both parts up into a single unit that you can later deploy.

How does chef-apply differ from chef-client?

Ans. chef-apply applies a single recipe; chef-client applies a cookbook.