Per-layer Operating System Package Installations
Important
AWS OpsWorks Stacks is no longer accepting new customers. Existing customers will be able to use the OpsWorks console, API, CLI, and CloudFormation resources as normal until May 26, 2024, at which time they will be discontinued. To prepare for this transition, we recommend you transition your stacks to AWS Systems Manager as soon as possible. For more information, see AWS OpsWorks Stacks End of Life FAQs and Migrating your AWS OpsWorks Stacks applications to AWS Systems Manager Application Manager.
Starting with Chef 12, you must use custom recipes to install packages on layers that are running different operating systems. This approach provides you with maximum flexibility and control over package installations.
For example, suppose that you want to install Apache on layers that are running RedHat,
Ubuntu, and Amazon versions of the Linux operating system. The Apache package for RedHat and
Amazon Linux is called httpd
, but on Ubuntu, it is called apache2
.
To address the difference in package naming, you can use syntax similar to that in the
following example recipe. The recipe installs the Apache package appropriate for each
operating system. This example is based on the Chef
documentation
package "Install Apache" do case node[:platform] when "redhat", "amazon" package_name "httpd" when "ubuntu" package_name "apache2" end end
For detailed information on how to use the package
resource to manage
packages, go to the package
Alternatively, you can use the value_for_platform
helper method from the Chef
Recipe DSL (domain-specific language), which accomplishes the same thing more succinctly:
package "Install Apache" do package_name value_for_platform( ["redhat", "amazon"] => { "default" => "httpd" }, ["ubuntu"] => { "default" => "apache2" } ) end
For information on using the value_for_platform
helper method, go to About the Recipe DSL