10 Best Chef Commands for DevOps Engineer

In this tutorial, I will take you through top 10 chef commands which will be generally used by DevOps Engineer.

Chef is consist of a Chef server, one or more workstations, and a node where the chef-client is installed. Components name is based on the roles played by each machine in the Chef ecosystem.

Chef Server: It is responsible for managing the chef nodes by pushing the configuration through recipes and cookbooks. It also interacts with the nodes through chief client installed in every client nodes.

10 Best Chef Commands for DevOps Engineer 1

Chef Workstations: This where recipes, cookbooks, and other chef configuration details are created or edited. All these are then pushed to the Chef server from the workstation, where they will be available to deploy to chef-client nodes.

Chef Client: This the target node where the configurations are deployed in which the chef-client is installed. A node can be any machine (physical, virtual, cloud, network device, etc..)

Chef Commands

Also Read: 50 Best Docker Interview Questions and Answers

1. Create a Chef User

To create an user you need to use chef-server-ctl user-create chef commands as shown below. In this example I am creating an user with below information:-

Advertisements

User Name: admin

First Name: admin

Last Name: admin

Email: admin@cyberithub.local

Pass: test@123$

Syntax

chef-server-ctl user-create USER_NAME FIRST_NAME [MIDDLE_NAME] LAST_NAME EMAIL 'PASSWORD' (options)

Example

[root@chef-server ~]#chef-server-ctl user-create admin admin admin admin@cyberithub.local test@123$ -f /etc/chef/admin.pem

2. Create an Organization

You need to use chef-server-ctl org-create chef commands to create an organization. In this example I am creating an organization with below information:-

Organization Name: cyberithub

Organization Full Name: CyberiITHub, Inc.

Syntax

chef-server-ctl org-create ORG_NAME "ORG_FULL_NAME" (options)

Example

[root@chef-server ~]#chef-server-ctl org-create cyberithub "CyberITHub, Inc" --association_user admin -f /etc/chef/cyberithub-validator.pem

3. Delete Organization

You can use chef-server-ctl org-delete chef commands to delete an organization. In this example, I am deleting an organization cyberithub as you can see from below output.

Syntax

chef-server-ctl org-delete ORG_NAME

Example

[root@chef-server ~]# chef-server-ctl org-delete cyberithub
Do you want to delete the organization cyberithub? (Y/N) y
full_name: CyberITHub, Inc
guid: 3b213c89a62c71341df66ea7025160f2
name: cyberithub

4. To show all the Organization

If you want to see all the organizations, you need to use chef-server-ctl org-show chef commands. As you can see from the below output, there is only one organization cyberithub currently available in the Server.

Syntax

chef-server-ctl org-show ORG_NAME

Example

[root@chef-server ~]# chef-server-ctl org-show
cyberithub: https://127.0.0.1/organizations/cyberithub

5. Show all the Users

If you want to see all the Chef users, use chef-server-ctl user-list chef commands. As you can see from below output, there are two users currently available in the Server.

Syntax

chef-server-ctl user-list

Example

[root@chef-server ~]# chef-server-ctl user-list
admin
pivotal

6. Delete User 

If you want to delete an user admin, you need to use chef-server-ctl user-delete chef commands. In this example I am deleting user admin as you can see below.

Syntax

chef-server-ctl user-delete USER_NAME

Example

[root@chef-server ~]# chef-server-ctl user-delete admin
Do you want to delete the user admin? (Y/N) y
Checking organization memberships...
Deleting user admin.

7. Check Chef Server Status

To check the status of all the services, you can use chef-server-ctl status command as shown below. In the below output, you can see all the running services and their process Id(pid).

[root@chef-server ~]# chef-server-ctl status
run: bookshelf: (pid 1288) 7842s; run: log: (pid 1287) 7842s
run: nginx: (pid 20819) 1699s; run: log: (pid 1308) 7842s
run: oc_bifrost: (pid 1285) 7842s; run: log: (pid 1277) 7842s
run: oc_id: (pid 1279) 7842s; run: log: (pid 1278) 7842s
run: opscode-erchef: (pid 1303) 7842s; run: log: (pid 1302) 7842s
run: opscode-expander: (pid 1284) 7842s; run: log: (pid 1275) 7842s
run: opscode-solr4: (pid 3468) 7526s; run: log: (pid 1280) 7842s
run: postgresql: (pid 7170) 7447s; run: log: (pid 1273) 7842s
run: rabbitmq: (pid 1306) 7842s; run: log: (pid 1305) 7842s
run: redis_lb: (pid 17269) 1746s; run: log: (pid 1295) 7842s

8. Check Chef Server Version

If you want to check the Chef Server version, you need to use chef-server-ctl version command. As you can see from below output, current chef server version is 13.1.13.

[root@chef-server ~]# chef-server-ctl version
13.1.13

9. Take Chef Server Backup

If you want to take Chef Server backup, you need to use chef-server-ctl backup chef commands. As you can see from below example, we are using option --config-only to take only configuration backup of Chef Server.

Syntax

chef-server-ctl backup

Example

[root@chef-server ~]# chef-server-ctl backup --config-only
Locating rsync..
/usr/bin/rsync
Starting Chef Server backup (config only)
Writing backup manifest
Creating backup tarball
/opt/opscode/embedded/lib/ruby/gems/2.6.0/gems/mixlib-shellout-3.0.7/lib/mixlib/shellout/unix.rb:187: warning: conflicting chdir during another chdir block
tar: Removing leading `/' from member names
Exporting tarball to /var/opt/chef-backup
Cleaning up /tmp/chef_backup20191214-26800-9d3a76
Backup Complete!

10. Reset user password

Sometimes you might need to reset User password. For that you need to run chef-server-ctl password chef commands as mentioned below. In this example I am resetting admin user password.

Syntax

chef-server-ctl password USERNAME

Example

[root@chef-server ~]# chef-server-ctl password admin
Enter the new password: *********
Enter the new password again: *********
Authentication info updated for admin.
User's password has been updated.

 

 

Reference: Chef Documentation

Advertisements

Leave a Reply