Chef-Client as Daemon and Chef-Shell

Last updated on Nov 12 2021
Yogesh Ajmera

Table of Contents

Chef-Client as Daemon and Chef-Shell

Chef – Chef-Client as Daemon

Running Chef-Client as daemon helps in knowing the state of all the nodes at any point of time. This help in running the Chef-Client at any point of time.

Pre-requisites

The node should be registered with Chef server and it should be running Chef-Client without any error.

Chef-Client in Daemon Mode

Start Chef-Client in daemon mode, running every 30 minutes.
user@server:~$ sudo chef-client -i 1800
In the above code, – i enables to run the Chef-Client in daemon mode on the required node and 1800 seconds define that the Chef-Client daemon should run in every 30 minutes.

Validating Daemon Run

Validate that the Chef-Client is running as a daemon.
user@server:~$ ps auxw | grep chef-client
The above command will grep the running daemon process of Chef-Client.

Other Ways

Instead of running Chef-Client as a daemon, we can run the same as a cron job.
user@server:~$ subl /etc/cron.d/chef_client
PATH=/usr/local/bin:/usr/bin:/bin
# m h dom mon dow user command
*/15 * * * * root chef-client -l warn | grep -v ‘retrying [1234]/5 in’
The above cron job will run after every 15 minutes.

Chef – Chef-Shell

Writing Chef cookbooks is always hard. It makes it even harder because of long feedback cycle of uploading them to the Chef server, provisioning a vagrant VM, checking how they failed there, rinsing and repeating. It would be easier if we could try to test some pieces or recipes before we do all this heavy lifting at once.
Chef comes with Chef-Shell, which is essentially an interactive Ruby session with Chef. In the Chef-Shell, we can create −
• Attributes
• Write Recipes
• Initializing Chef runs
It is used to evaluate parts of recipes on the fly, before uploading them to Chef server and execute complete cookbooks on the node.

Running Shell

Step 1 − Run Chef-Shell in a standalone mode.
mma@laptop:~/chef-repo $ chef-shell
loading configuration: none (standalone chef-shell session)
Session type: standalone
Loading...[2017-01-12T20:48:01+01:00] INFO: Run List is []
[2017-01-12T20:48:01+01:00] INFO: Run List expands to []
done.
This is chef-shell, the Chef Shell.
Chef Version: 11.0.0
http://www.opscode.com/chef
http://wiki.opscode.com/display/chef/Home
run `help' for help, `exit' or ^D to quit.
Ohai2u mma@laptop!
chef >
Step 2 − Switch to attribute mode in the Chef-Shell
• chef > attributes_mode
Step 3 − Setting attribute value.
• chef:attributes > set[:title] = "Chef Cookbook"
o "Chef Cookbook"
• chef:attributes > quit
o :attributes
• chef >
Step 4 − Switch to recipe mode.
• chef > recipe_mode
Step 5 − Create a file resource.
chef:recipe > file "/tmp/book.txt" do
chef:recipe > content node.title
chef:recipe ?> end
=> <file[/tmp/book.txt] @name: "/tmp/book.txt" @noop: nil @
before: nil @params: {} @provider: Chef::Provider::File @allowed_
actions: [:nothing, :create, :delete, :touch, :create_if_missing]
@action: "create" @updated: false @updated_by_last_action: false
@supports: {} @ignore_failure: false @retries: 0 @retry_delay:
2 @source_line: "(irb#1):1:in `irb_binding'" @elapsed_time: 0 @
resource_name: :file @path: "/tmp/book.txt" @backup: 5 @diff: nil
@cookbook_name: nil @recipe_name: nil @content: "Chef Cookbook">

chef:recipe >
Step 6 − Commence Chef run to create the file with the given content.
• chef:recipe > run_chef
[2017-01-12T21:07:49+01:00] INFO: Processing file[/tmp/book.txt]
action create ((irb#1) line 1)
--- /var/folders/1r/_35fx24d0y5g08qs131c33nw0000gn/T/cheftempfile20121212-
11348-dwp1zs 2012-12-12 21:07:49.000000000
+0100
+++ /var/folders/1r/_35fx24d0y5g08qs131c33nw0000gn/T/chefdiff20121212-
11348-hdzcp1 2012-12-12 21:07:49.000000000 +0100
@@ -0,0 +1 @@
+Chef Cookbook
\ No newline at end of file
[2017-01-12T21:07:49+01:00] INFO: entered create
[2017-01-12T21:07:49+01:00] INFO: file[/tmp/book.txt] created file
/tmp/book.txt

How it Works

• Chef-Shell starts with an Interactive Ruby (IRB) session enhanced with some specific features.
• It offers modes such as attributes_mode and interactive_mode.
• It helps in writing commands, which are written inside a recipe or cookbook.
• It runs everything in an interactive mode.
We can run Chef-Shell in three different modes: Standalone mode, Client mode, and Solo mode.
Standalone mode − It is the default mode. No cookbooks are loaded, and the run-list is empty.
Client mode − Here, the chef-shell acts as a chef-client.
Solo mode − Here, the chef-shell acts as a chef-solo client.
So, this brings us to the end of blog. This Tecklearn ‘Chef-Client as Daemon and Chef-Shell’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Chef and build a career in DevOps domain, then check out our interactive, Continuous Delivery using Chef Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/continuous-delivery-using-chef/

Continuous Delivery using Chef Training

About the Course

Tecklearn has specially designed this Continuous Delivery using Chef Training Course to advance your skills for a successful career in this domain. The course will cover different components of Chef and how they are used in software development operations. The course consists of important concepts like Continuous Delivery (CD) using Chef, Chef Framework, How Chef Works, Chef Advantages and Chef Installation. You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Chef.

Why Should you take Continuous Delivery using Chef Training?

• The average salary for a Senior Development Operations (DevOps) Engineer with Chef skills is $118, 435. – PayScale.com
• Airbnb, Facebook, Slack, Shopify, Digital Ocean & many other MNC’s worldwide use Chef across industries.
• According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.

What you will Learn in this Course?

Introduction to DevOps
• What is Software Development
• Software Development Life Cycle
• Why DevOps?
• What is DevOps?
• DevOps Lifecycle
• DevOps Tools
• Benefits of DevOps
• How DevOps is related to Agile Delivery
• DevOps Implementation
Continuous Delivery using Chef
• Continuous Delivery
• What is Chef
• Chef Framework
• How Chef Works
• Chef Advantages
• Chef Installation
• Hands on

Got a question for us? Please mention it in the comments section and we will get back to you.

 

0 responses on "Chef-Client as Daemon and Chef-Shell"

Leave a Message

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