If package "nginx"
in Chef gets translated into apt-get install nginx
on an Ubuntu node, what can be written in a Chef recipe that would translate into:
apt-get -y update
apt-get -y upgrade
Couldn't figure out from the apt
cookbook.
What is the difference between apt update and apt upgrade? “apt-get update” updates the package sources list to get the latest list of available packages in the repositories and “apt-get upgrade” updates all the packages presently installed in our Linux system to their latest versions.
sudo apt-get update and sudo apt-get upgrade are two commands you can use to keep all of your packages up to date in Debian or a Debian-based Linux distribution. They're common commands for Linux admins and people doing DevOps, but are handy to know even if you don't use the command line often.
Upgrading software with Apt Open a terminal and use the update command. The update command will update the list of available packages for your machine. 2. Run the upgrade command to download and install the latest software.
The Opscode "apt" cookbook's default recipe will run apt-get update
to ensure that the package cache is updated. We recommend putting that early in your node's run list so later on packages can be installed with the correct versions.
We generally don't recommend that users use "apt-get upgrade
" in a recipe, for a couple reasons.
apt-get
may upgrade a package that has conflicting configuration or other issues that cannot be resolved without running the command again, or running other apt/dpkg commands manually.Instead, use the "upgrade" action for packages that should always update to the latest version.
package "nginx" do
action :upgrade
end
If you're reusing a cookbook that defines the cookbook, you can write a recipe that modifies the action of the existing resource, like this:
resources("package[nginx]").action(:upgrade)
The #resources
method in a recipe will look up in the Resource Collection the specified resource (package nginx). Then sending the #action
method with the argument :upgrade
will tell Chef that the action should be to upgrade.
Edit Update: Do be careful when choosing packages that would be upgraded automatically in this way. An upstream change in a package can cause detrimental effects on the system. This is especially true if such a package does a restart of services it manages during the post installation scripts. Know your infrastructure, and if in doubt run your own package repository that has the critical packages you need for the application stack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With