1. Define Chef?
Chef is a powerful automation platform that transforms infrastructure into code. Whether you’re operating in the cloud, on-premises, or in a hybrid environment, Chef automates how infrastructure is configured, deployed, and managed across your network, no matter its size.
2. Define Architecture of Chef ?
Chef Architecture include – Chef Workstation, Chef Server, Chef Node
Chef Workstation: Workstation is a node where you create & test your code.
Chef Server: The Chef server acts as a hub for configuration data. The Chef server stores cookbooks, the policies that are applied to nodes, and metadata that describes each registered node that is being managed by the chef-client.
Chef Node: A node is any machine—physical, virtual, cloud, network device, etc.—that is under management by Chef.
3. Define Chef Resource.
A resource is a statement of configuration policy that describe the desired state of a configuration item and declare the steps needed to bring that item to desired state.
4. Describe the syntax of a resource.
A resource is a Ruby block with four components
a) Type of Resource
b) Name of resource
c) Property of Resource
d) Actions of Resource
type ‘name’ do
attribute ‘value’
action :type_of_action
package ‘tar’ do
version ‘1.16.1’
action :install
5. Define Chef Recipe.
A Recipe is a collection of resources that are grouped together in a certain order to configure a part of the system. Apart from resources, a recipe can have helper code written in Ruby language and a recipe can have dependency on another recipe.
6. What is an Attribute?
An attribute is a specific details about a node. Chef-Client use attribute to evaluate the current state and desired state of the node.
7. How attributes are defined ?
Attributes are provided to the chef-client from the following locations :
a) The state of the node itself.
b) Cookbooks ( in recipes or attribute files )
c) Roles
d) Environments
8. How attributes works?
a) When chef-client runs all attribute ( expect for normal attributes ) are reset.
b) Chef-Client rebuilds them by data collected by OHAI, default and override attributes specified in Cookbooks,Roles,Environments.
c) All attributes are then merged and applied to the node according to attribute precedence.
d) At the end of the chef-client run, the attributes that were applied to the node are saved to the Chef server as part of the node object.
9. How attributes works?
a) Attributes are maintained in the chef-repo for environments, roles, and cookbooks (attribute files and recipes)
b) Some attributes are collected by Ohai on each individual node at the start of every chef-client run.
c) Attributes that are maintained in the chef-repo are uploaded to the Chef server from the workstation, periodically.
d) The chef-client will pull down the node object from the Chef server (which contains the attribute data from the previous chef-client run), after which all attributes (except normal are reset).
e) The chef-client will update the cookbooks on the node (if required), which updates the attributes contained in attribute files and recipes.
f) The chef-client will update the role and environment data (if required).
g) The chef-client will rebuild the attribute list and apply attribute precedence while configuring the node.
h) The chef-client pushes the node object to the Chef server at the end of the chef-client run; the updated node object on the Chef server is then indexed for search and is stored until the next chef-client run.
10. What is an Automatic attribute?
Attributes that are detected by OHAI and then used by chef-client to ensure that they are handled properly in next chef-chef-client run.
These attributes define specific detail about a node, such as an IP address, a host name, a list of loaded kernel modules, and so on.
All attributes collected by Ohai are unmodifiable by the chef-client.
e.g. node[‘platform’], node[‘ipaddress’], node[‘macaddress’], node[‘hostname’], node[‘fqdn’], node[‘recipes’]
11. Define Attribute File.
Apart from attributes generated by OHAI, we can also create custom attributes and they can be defined in a attribute files located inside attribute directory of a cookbook.
└── attributes
└── default.rb
default.rb is an attribute file and you can define custom attributes inside it.
12. Does custom attributes have any advantage over variables inside recipes?
Variables defined inside recipe have limited scope as they are local to the file in which they are defined.
e.g. filename defined in following code can be accessed within the file.
     filename = “/tmp/testing”
file filename do
  action :create
  content “This is a test file”
    But once you define attributes, they are globally available.
13. Give an example how to define a custom attribute in an attribute file.
default[‘jenkins’][‘dir’] = “/var/lib/jenkins”
precedence[cookbook-name][[attribute-name] = attribute-value
14. Give an example how to define a custom attribute in a recipe.
node.default[‘jenkins’][‘dir’] = “/var/lib/jenkins”
node.precedence[cookbook-name][[attribute-name] = attribute-value
15. Give order of precedence of different types of attributes.
automatic > force_override  > override > normal > force_default > default
16. How default attribute precedence work?
Since attributes can be defined at multiple location, therefore precedence decides which value need to be set.
default attribute in role > default attribute in environment > default attribute in recipe > default attribute in cookbook attribute file
17. How force_default attribute precedence work?
force_default attribute in recipe > force_default attribute in cookbook attribute file
18. How normal attribute precedence work?
Normal attribute in recipe > normal attribute in cookbook attribute file
19. How override attribute precedence work?
Override attribute in an environment > override attribute in a role > override attribute in a recipe > override attribute in a cookbook attribute file
20. How to blacklist attributes?
Attributes are blacklisted by attribute type, with each attribute type being blacklisted independently. These are defined in client.rb file at node.
e.g. automatic_attribute_blacklist [[‘filesystem’,’/dev/diskos2′]]
21. What are Whitelist Attributes?
Attributes that should be saved by a node may be whitelisted in the client.rb file. The whitelist is a hash of keys that specifies each attribute to be saved.
Attributes are whitelisted by attribute type, with each attribute type being whitelisted independently. To whitelist the network attributes and prevent the other attributes from being saved, update the client.rb file:
automatic_attribute_whitelist [‘network/interfaces/’]
22. What is data bag?
A data bag is a container that store global variables as JSON data and the information stored is not tied to a single node, that is information is available at global level ( across all environments ).
23. What are advantages of using data bag?
a) Data stored is available globally and it is the only way to define information at infrastructure level.
b) Data bags are indexed for searching and can be loaded by a cookbook or accessed during a search.
c) Data stored inside data bag can be encrypted.
24. How to create a data bag?
Data bag can be created either manually or by using knife command line tool.
25. How to create data bag manually?
Data bags and data bag items can be created manually under the data_bags directory in the chef-repo.
# mkdir data_bags/users
# vi data_bags/users/bob.json
‘id’ : 1,
‘username’ : ‘bob’,
‘first_name’ : ‘Bob’,
‘last_name’ : ‘Marley’
Chef Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *