Showing posts with label Chef. Show all posts
Showing posts with label Chef. Show all posts

Sunday, April 6, 2025

Chef Quiz : Question and Answers

1) Which of the following requires manual configuration

        a. Hosted chef

        b. On-Premises chef

 

2)  Which tab in Chef-server webUI has list of cookbooks uploaded?

        a. Cookbooks

        b. Nodes

        c. Bookshelf

        d. Policy


3)  Which among the following is a load balancer in chef server

        a. Lucene

        b. RabitMQ

        c. Solr

        d. Ngnix


4)  Which among the following file has knife configuration data

        a. config.rb

        b. default.rb

        c. knifeConfig.rb

        d. knife.rb


5)  Which among the following act as a local repository for cookbooks

        a. Chef-supermarket

        b. Workstation

        c. Chef-Server

        d. Nodes


6)  Chef is written using

        a. None of the options

        b. Erlang

        c. Ruby

        d. both the options


7)  In workstation chef is installed using _____ installer

        a. Onewaybus

        b. Multibus

        c. Omnibus

        d. all the options


8)  Which one of the following is not a knife command

        a. Knife list

        b. Knife open

        c. Knife node

        d. all the options


9)  ______ helps in keeping the chef-repo in sync with Git

        a. Chef-Server

        b. Workstation

        c. Chef-supermarket

        d. Nodes


10)  Multiple users can access a single organization

        a. True

        b. False


11)  After installing chefDK you can verify the installation using the command

        a. chef –version

        b. chef verify

        c. both the options

        d. None of the options


12)  Which of the Following command will create knife.rb and client.rb file

        a. knife client

        b. knife create

        c. knife configure

        d. knife execute


13)  A collection of resource forms a ________

        a. repository

        b. recipe

        c. cookbook

        d. node


14)  If you don't specify action in resource an exception will be shown

        a. True

        b. False


15)  Cookbook recipes are created using

        a. ruby

        b. erlang

        c. both the options

        d. None of the options


16)  It is not possible to start a service using a recipe

        a. True

        b. False


17) Recipes will execute in based on priority

        a. True

        b. False


18)  To run a cookbook in local-mode run chef-client with

        a. -z

        b. -x

        c. -v

        d. -y


19)  Knife uses ___________ for authentication

        a. User.pem

        b. Password

        c. Validator.pem

        d. Client.pem


20)  _______ helps in collecting the system configuration data.

        a. Ohai

        b. Chef-Server

        c. Chef-client

        d. Knife


21)  Chef-client uses _______ for authentication

        a. User.pem

        b. Password

        c. Validator.pem

        d. Client.pem


22)  Every node should have _____ installed in it.

        a. Chef-supermarket

        b. Chef-client

        c. Chef-Host

        d. Chef-node


23)  During Knife bootstrap -N is used to specify the ______

        a. Chef-supermarket

        b. Chef-client

        c. Chef-Host

        d. Chef-node


24)  Which of the following can be a node?

        a. Switch

        b. Router

        c. Virtual machine

        d. all the options


25)  To install chef-client and run the cookbook use the command

        a. kitchen execute

        b. kitchen converge

        c. kitchen create

        d. kitchen run


26) A run-list can have roles specified in it

        a. True

        b. False


27) Kitchen automate command will test the cookbook automatically using inspec

        a. True

        b. False


28) The driver details of virtual machine is specified in knife.rb file

        a. True

        b. False


29) _______ helps in simulating the production environment.

        a. Test kitchen

        b. Chef-client

        c. supermarket

        d. Knife


30) If a recipe is added twice in run-list then it will be executed twice during chef run (True/False)

        a. True

        b. False


31) A Node can be tied to different environment (True/False)

        a. True

        b. False


32)  Roles can be added to a node during bootstrap

        a. True

        b. False


32)  Data Bag follows _________ format

        a. ERB

        b. YAML

        c. JSON

        d. HTML


33)  Cookbook is a collection of ---------------

        a. Resource

        b. Run_list

        c. Recipes

        d. None of the options


34)  Node is a made up of ---------------

        a. Attributes

        b. Files

        c. Templates

        d. None of the options


35)  Chef is a --------------- framework

        a. Problem management

        b. Capacity management

        c. Configuration management

        d. Incident management


36)   In what language chef-client has been written?

        a. Ruby

        b. Perl

        c. Python

        d. Erlang


37)  Every request made to chef server has to be signed (True/False)

        a. True

        b. False


38)   Resource which supports dynamic file generation

        a. Cookbook_file

        b. File

        c. Template

        d. All the above


39)  Ruby code gets executed only in execute phase (True/False)

        a. True

        b. False


40)  Resources are always declarative (True/False)

        a. True

        b. False


41)  A Node can’t be share across organization (True/False)

        a. True

        b. False


42)   To search all the nodes use ______

a. knife search node All

b. knife search node "*:*"

c. knife search node "**"

d. knife search node "*"


43)   The details of all the nodes connected to a server are stored in ________

a. kitchen.yml

b. databags

c. roles

d. environment


44)   In what language chef server has been written?

a. Perl

b. Ruby

c. Python

d. Erlang


45)   Cookbook is a collection of ___________

a. Run_list

b. Resource

c. Recipes

d.  None


 46)   Choose the correct attributes precedence

a. By Ohai, In roles, In environments, In cookbook recipes, In cookbook attribute files

b. In roles, In environments, In cookbook recipes, In cookbook attribute files, By Ohai  --wrong

c. In environments, By Ohai, In roles, In cookbook recipes, In cookbook attribute files

d.  In cookbook attribute files, By Ohai, In roles, In environments, In cookbook recipes


47)   Knife.rb is a ____________

a. Authentication file

b. Configuration file

c. Executable file

              d.  All the above


48)   What is the option to execute chef-client in chef zero mode?

a. --local

b. --local-mode

c. --mode-local

              d.  --chef-zero


49)   _______ discovers automatic attribute

a. Ohai

b. Nhai

c. Node

              d.  Search


50)   Chef is a ______ framework

a. Configuration management

b. Incident management

c. Problem management

              d.  Capacity management


51)   Nodes are made up of __________

a. Attributes

b. Files

c. Templates

              d.  None of the above


52)   “@” signifies _____________

a.  Class variable

b.  Instance variable

c.  Override annotation

              d.  Attribute

Sunday, March 23, 2025

Chef client cookbook to run from local system : Install Oracle 19c Client Software in Linux Machine

To Install Oracle Client we need to download and place this in Oracle Directory. 

First go to the chef cookbook location and create below directories

  cd cookbooks
  mkdir -p Oracle_Client_Install/recipes
  mkdir -p Oracle_Client_Install/files/default 

Once we create the default directories. We need to create a sh script in default directory and rb script in recipes directory.
our directory structure will now looks like this

  ~/cookbooks
     Oracle_Client_Install
        recipes
           OracleClientInstall.sh
        files
           default
           	OracleClientInstall.rb

Download the Oracle Client software and keep that in directory "/opt/sw/oracle". Then unzip the file. Add the below path in the client_install.rsp file

UNIX_GROUP_NAME=oracle
INVENTORY_LOCATION=/opt/sw/app/oraInventory
ORACLE_HOME=/opt/sw/oracle/Oracle19c/client/home
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
ORACLE_BASE=/opt/sw/oracle 

Copy the below content into the OracleClientInstall.sh.

#!/bin/bash
cd /opt/sw/oracle
mkdir -m 775 -p /opt/sw/oracle/Oracle19c/client/home/network/admin
mkdir -m 775 -p /opt/sw/app/oraInventory
export CV_ASSUME_DISTID = OLE7.8
unset ORACLE_HOME
unset TNS_ADMIN
unset ORACLE_SID
cd /opt/sw/oracle/Oracle19c/client
./runInstaller -silent -responseFile /opt/sw/oracle/Oracle19c/client/response/client_install.rsp

Copy the below content into the OracleClientInstall.rb
#recipes/display_certificates.rb
#Cook book : Oracle_Client_Install
#Recipe : OracleClientInstall.rb
execute 'Install Oracle Client' do
  command 'bash ~/cookbooks/Oracle_Client_Install/files/default/OracleClientInstall.sh
  user 'oracle'
  group 'oinstall'
  action :run
end
 
Save the files and run the chef client using the below code
chef-client -zr recipe[Oracle_Client_Install::OracleClientInstall]
It will install the Oracle Client Software

Thursday, March 20, 2025

Chef Client Cookbook to run from local system : Taking backup using tar command

 First go to the chef cookbook location and create below directories
cd cookbooks
mkdir -p backupfolder/recipes
create the cookbook backupfolder.rb
execute 'Backup Directory' do
	command 'tar -cvf /opt/sw/backup_$(date +"%Y%m%d%H%M%S%3N").tar /opt/sw/conf  /opt/sw/apps'
	action :run
end
the above code will take backup of conf folder and apps folder into a single tar file with datetime stamp. To run the chef client we use the below command
chef-client -zr recipe[backupfolder::backupfolder]

Sunday, March 16, 2025

Chef client cookbook to run from local system : Check validity of the certificates and remove expired certificates

To perform this activity using the chef client we will create new cookbook display_certificates.

First go to the chef cookbook location and create below directories

  cd cookbooks
  mkdir -p display_certificates/recipes
  mkdir -p display_certificates/files/default 

Once we create the default directories. We need to create a sh script in default directory and rb script in recipes directory.
our directory structure will now looks like this

  ~/cookbooks
     display_certifies
        recipes
           display_certificates.sh
        files
           default
           	display_certificates.rb 

Copy the below content into the display_certificates.sh. change keystore path and password as per keystore location. aliasname is certificatename which can be used to delete certificate from keystore.

   #!/bin/bash
  KEYSTORE_PATH="/opt/sw/keystore/keystore.jks"
  KEYSTORE_PASSWORD="changeit"
  keytool -list -v -keystore "$KEYSTORE_PATH" -storepass "$KEYSTORE_PASSWORD" | grep -E "Alias|Valid"
  keytool -delete -alias "aliasname" -keystore "$KEYSTORE_PATH" -storepass "$KEYSTORE_PASSWORD" 
Copy the below content into the display_certificates.rb
#recipes/display_certificates.rb
cookbook_file '/tmp/display_certificates.sh' do
  source 'display_certificates.sh'
  mode '0755'
  owner 'root'
  group 'root'
  action :create
end

execute 'display_certificates' do
  command 'bash /tmp/display_certificates.sh'
  live_stream true
end 
Save the files and run the chef client using the below code
chef-client -zr recipe[display_certificates::display_certificates]
It will display the certificates in the keystore file with certificatename and its expiry date.

Chef Client Cookbook to run from local system : Download File from artifactory

We can use chef receipes to download the files from artifactory 

To verify current chef client version we can use the below command
Chef-shell --version
We will get output like 
Chef Infra Client :  18.4.12 
1. Go to cookbooks
cd ~/cookbooks/
2. Create a directory for cookbook and recipe using the following structure.
mkdir -p downloads/recipes
3. Go to the directory
 cd downloads/recipes
4. Create a below file to download file
vi FileDownload.rb
5. Paste the below content in the file Filedownload.rb
#Cookbook : downloads
#Recipe : FileDownload.rb
#To Download the file from artifactory using the curl script
execute 'Download File'
user 'root'
command 'curl -o ~/cookbooks/downloads/recipes/File.txt -O https://artifactory.srv.mytest.com.au/application/env/File.txt'
live_stream true
action : run
end

6. Save the file using esc+:wq and run using the below command

chef-client -zr recipe[downloads::FileDownload]



7.  Alternatively we can run the chef cookbook using below command

chef-client --local-mode --runlist 'recipe[downloads::FileDownload]'

8. We can use native chef resource to download the file


#Cookbook : downloads 
#Recipe : FileDownload.rb
#To Download the file from artifactory chef resource and keep in required folder

remote_file '/tmp/File.txt' do
source 'https://artifactory.srv.mytest.com.au/application/env/File.txt'
owner 'root'
group 'root'
action :create
end

execute 'move file' do
command 'mv /tmp/File.txt ~/cookbooks/downloads/recipes/File.txt'
action :run
not_if {::File.exist?('~/cookbooks/downloads/recipes/File.txt')}
end