MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Chef Tutorials: Uninstalling Chef Software, chef-automate and chef-server

This guide shows how to fully remove Chef Automate, Chef Infra Server and the Chef client tools from a Linux host. It explains what each command in the example above does, gives a safer corrected order, covers backups and leftover files, and ends with checks that confirm the host is clean.


$ systemctl stop chef-automate
$ pkill chef-automate
$ rm -rf /hab
$ userdel hab
$ chef-server-ctl uninstall


What the commands above do

Chef Automate 2.x runs as a set of Habitat services under /hab, managed by one systemd unit named chef-automate. A standalone Chef Infra Server is an Omnibus package installed under /opt/opscode and managed with chef-server-ctl. The example above mixes both products, so it helps to know what each line affects.

CommandEffectWhat it leaves behind
systemctl stop chef-automateStops the Automate systemd unit and its Habitat supervisorThe unit stays enabled and starts again after a reboot
pkill chef-automateKills any remaining chef-automate processeshab-launch, hab-sup and service processes with other names
rm -rf /habDeletes all Habitat packages, service data and configurationThe systemd unit file and the chef-automate binary
userdel habRemoves the hab userThe hab group, if other members still use it
chef-server-ctl uninstallStops Infra Server services and removes the applicationAll data in /var/opt/opscode, the configuration and the chef-server-core package

Note: Every command here needs root. Run them as root or with sudo. The $ prompt in the example above suggests a normal user, which makes most of them fail with permission errors.

Back up before you remove anything

All of these steps destroy data for good. If there is any chance you will need the cookbooks, node data, compliance reports or user accounts later, take a backup first and copy it off the host.

# Chef Automate: creates a backup under /var/opt/chef-automate/backups by default
sudo chef-automate backup create
sudo chef-automate backup list

# Standalone Chef Infra Server: writes a tarball under /var/opt/chef-backup
sudo chef-server-ctl backup

# Copy the backups somewhere safe before uninstalling
sudo rsync -a /var/opt/chef-automate/backups/ backup-host:/srv/chef-automate-backups/
sudo rsync -a /var/opt/chef-backup/ backup-host:/srv/chef-server-backups/Code language: PHP (php)

Backup locations can be changed in configuration. If the paths above are empty, check the output of the backup command for the real location.

Corrected version of the commands above

Chef Automate has its own uninstall subcommand. It stops the services, removes the systemd unit and deletes Automate data, so you do not need to kill processes or delete /hab by hand. If Chef Infra Server was deployed with Automate (chef-automate deploy --product automate --product infra-server), it runs as a Habitat package, and chef-automate uninstall removes it too. In that setup chef-server-ctl lives under /hab, so it stops working once /hab is deleted. That is why the last line of the original fails.

# 1. Uninstall Chef Automate (and any Infra Server deployed with it)
sudo chef-automate uninstall

# 2. If the systemd unit is still present, stop, disable and remove it
sudo systemctl stop chef-automate 2>/dev/null
sudo systemctl disable chef-automate 2>/dev/null
sudo rm -f /etc/systemd/system/chef-automate.service
sudo systemctl daemon-reload

# 3. Kill any leftover Habitat processes
sudo pkill -f hab-launch
sudo pkill -f hab-sup

# 4. Remove Habitat data, user and group (only if nothing else on the host uses Habitat)
sudo rm -rf /hab
sudo userdel hab 2>/dev/null
sudo groupdel hab 2>/dev/null

# 5. Remove the chef-automate binary you downloaded
which chef-automate && sudo rm -f "$(which chef-automate)"Code language: PHP (php)

chef-automate uninstall asks for confirmation. On a host you are about to rebuild, the manual steps 2 to 5 only act as a safety net. If the uninstall finished cleanly, most of them do nothing.

Note: Do not delete /hab or the hab user on a host that runs other Habitat services. They share the same supervisor and package store.

Uninstall a standalone Chef Infra Server

chef-server-ctl uninstall removes the running application, but by design it keeps the data. To remove everything, wipe the data with cleanse, uninstall, remove the package, then delete the leftover directories.

  1. If Chef Manage (the web UI) is installed, remove it first: sudo chef-manage-ctl cleanse, then remove the chef-manage package.
  2. Run sudo chef-server-ctl cleanse. This stops services and deletes data, logs and generated configuration. It asks for confirmation before it continues.
  3. Run sudo chef-server-ctl uninstall to stop the runit supervisor and remove the application.
  4. Remove the package: sudo apt-get purge -y chef-server-core on Debian or Ubuntu, or sudo dnf remove -y chef-server-core on RHEL-family systems.
  5. Delete what is left: sudo rm -rf /opt/opscode /var/opt/opscode /var/log/opscode /etc/opscode.
  6. Remove the service accounts the package created, if they still exist: sudo userdel opscode and sudo userdel opscode-pgsql.
sudo chef-server-ctl cleanse
sudo chef-server-ctl uninstall
sudo apt-get purge -y chef-server-core      # or: sudo dnf remove -y chef-server-core
sudo rm -rf /opt/opscode /var/opt/opscode /var/log/opscode /etc/opscode
sudo userdel opscode 2>/dev/null; sudo userdel opscode-pgsql 2>/dev/nullCode language: PHP (php)

Remove Chef Infra Client and Chef Workstation

Nodes that registered with the server still have the client installed and a node and client object on the server. Delete those objects from a workstation before you remove the server, then uninstall the client on each node. See the knife command line reference for more options.

# From the workstation, while the server is still up
knife node delete web01 -y
knife client delete web01 -y

# On each node: remove Chef Infra Client
sudo apt-get purge -y chef        # Debian/Ubuntu
sudo dnf remove -y chef           # RHEL family
sudo rm -rf /opt/chef /etc/chef /var/chef /var/log/chef

# On a Linux workstation: remove Chef Workstation
sudo apt-get purge -y chef-workstation   # or: sudo dnf remove -y chef-workstation
sudo rm -rf /opt/chef-workstation
# Optional: removes your knife config and keys
rm -rf ~/.chefCode language: PHP (php)

On Windows, remove Chef Infra Client or Chef Workstation from Apps and Features, then delete C:\chef and C:\opscode if they remain.

Verify the host is clean

# No Chef, Habitat or Omnibus processes should be listed
ps -ef | grep -E 'hab-|chef|opscode|runsv' | grep -v grep

# Ports 80 and 443 should no longer be held by nginx from Chef
sudo ss -tlnp | grep -E ':(80|443)\s'

# No units or directories left behind
systemctl list-unit-files | grep -Ei 'chef|runsvdir'
ls -d /hab /opt/opscode /var/opt/opscode /opt/chef* 2>/dev/null

# Service accounts gone
id hab; id opscodeCode language: PHP (php)

Each command should return nothing, or no such user for the id checks. If something still shows up, stop the process or unit, then remove the remaining path.

Common errors and fixes

SymptomCauseFix
chef-server-ctl: command not found/hab was deleted first, and Infra Server was deployed through AutomateNothing more to uninstall with chef-server-ctl. Remove the leftover systemd unit and directories by hand
rm: cannot remove '/hab/...': Device or resource busyHabitat processes still running, or a mounted path under /habStop the processes with pkill -f hab-, check with mount | grep /hab, then retry
userdel: user hab is currently used by processSupervisor or service processes still own filesKill the processes listed, then run userdel again
Automate starts again after a rebootThe systemd unit was stopped but not disabled or removedRun systemctl disable chef-automate, remove the unit file and run daemon-reload
Reinstall fails because the port is in use or old data is presentOld nginx or /var/opt/opscode data left behindRun the verification checks and remove whatever is left

Frequently asked questions

Does chef-server-ctl uninstall delete my Chef Infra Server data?

No. It stops the services and removes the application, but it leaves data and configuration in place. Use chef-server-ctl cleanse to wipe the data, then remove the chef-server-core package.

How do I uninstall Chef Automate cleanly?

Run sudo chef-automate uninstall. It stops the services, removes the systemd unit and deletes Automate data. Afterwards, check that no hab-sup processes and no /hab directory remain.

Is it safe to run rm -rf /hab?

Only if no other Habitat-managed services run on the host. /hab holds every Habitat package and all service data, so deleting it removes all of them.

Do I need to remove nodes from the Chef server before uninstalling it?

It is not required if the server is being destroyed. Still, deleting the node and client objects with knife first, and uninstalling the client on each node, stops nodes from failing their scheduled chef-client runs against a server that no longer exists.

Can I reinstall Chef Automate or Infra Server on the same host afterwards?

Yes, once the verification checks show no leftover processes, units, directories or users. Leftover data in /hab or /var/opt/opscode is the most common reason a reinstall fails.

Related tutorials

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Chef Tutorials: Chef Infra Server & Chef Automate Backup and Restore

Chef Infra Server is backed up with chef-server-ctl backup and restored with chef-server-ctl restore. Chef Automate has its own commands, chef-automate backup create and chef-automate backup restore….

Read More

Bootstrap a Windows Node with Chef over WinRM (Knife Windows Guide)

Learn how to bootstrap a Microsoft Windows node using Chef with the `knife bootstrap windows winrm` workflow. This revised guide adds prerequisites, command variants, validation steps, and operational pitfalls.

Read More

Chef Tutorials: Load balancer for Chef Automate and Chef Infra

Reference Load Balancing Progress Chef Automate and Infra Server Rajesh Kumar I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical…

Read More

Chef Tutorials: Chef roles Tutorials and Example

What is Role? A role is a way to define certain patterns and processes that exist across nodes in an organization as belonging to a single job…

Read More

Chef Tutorials: Configure Workstation with knife

Install Chef Workstation Configure Chef Workstation with Chef Infra Server using Knife Rajesh Kumar I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate…

Read More

Chef Tutorials: Install and Configure Chef Automate and Infra Server

Step – 1 – Setup Chef Automate and Chef Infra Server If you want to start from scratch, create a Linux VM or cloud instance, login as…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x