Table of contents
1.
Introduction
2.
Syntax
3.
Actions:
4.
Properties 
5.
Common Functionalities of Resource 
5.1.
Chef resources have a variety of resource guards, common general properties and notifications, which are discussed below in detail: 
5.2.
Common Properties 
5.3.
Notifications 
5.4.
Guards
5.4.1.
Properties for Guards: 
6.
Example Statements 
7.
Frequently Asked Questions
7.1.
How to install and use Chef?
7.2.
What is macos_power_management resource?
7.3.
What is Gorilla? What is its use?
8.
Conclusion 
Last Updated: Aug 13, 2025

Chef- Resources -macos_power_management Resource

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Chef is a purely Ruby-encoded open source technology which helps in infrastructure automation, reducing the tedious process of manually managing infrastructure and version deployment. The main goal is to define and develop infrastructure into code. Here we will talk about the macos_power_management resource of chef infra, which is used to set the power settings of a kiosk-style device when it is needed always-on.
 

The official logo of the Chef open source platform

Syntax

The full syntax of this resource is:
 

macos_power_management 'name' do
  computer_sleep_time      String # default: "never"
  disk_sleep_time          String # default: "never"
  display_sleep_time       String # default: "never"
  action                   Symbol # defaults: set if not specified
end


Where the terms mean:

  • macos_power_management: resource name 
  • name: name given to the resource 
  • action: steps the Chef Infra Client needs to take to bring the node into the desired state
  • computer_sleep_time, disk_sleep_time, and display_sleep_time: properties available to this resource.
     

Actions:

This resource has the following actions:

:nothing

The resource block will not act unless it is requested to do so by another resource explicitly. Once notified, it either queues it at the end of a Chef Infra Client run or runs it immediately.

:set

This sets the policy as defined in the property. 
 

Properties 

The macos_power_management resource has the following properties:
 

computer_sleep_time 

  • Ruby Type: string
  • Default value: never 

Used to set the computer to sleep after 1-60 minutes, or never. The default value is never.
 

disk_sleep_time 

  • Ruby Type: string 
  • Default value: never 

Sets the hard disk to sleep after 1-60 minutes or never. The default value is never. 
 

display_sleep_time 

  • Ruby Type: string
  • Default value: never 

Used to set the display to sleep after 1-60 minutes or never. The default value is never.
 

Common Functionalities of Resource 

Chef resources have a variety of resource guards, common general properties and notifications, which are discussed below in detail:
 

Common Properties 

Here are discussed some common properties of Chef resources:
 

complie_time

  • Ruby Type: true, false 
  • Default value: false 

Used to specify the duration for which the resource is run on the node. It is set to true during the compile phase- when the resource collection is being built. It is set to false during the converge phase- when the Chef Infra Client is configuring the node.

 

retry_delay

  • Ruby Type: integer 
  • Default value: 2

Specifies the delay time between two successive retrie
 

sensitive 

  • Ruby Type: true, false 
  • Default value: false

To make sure the Chef Infra Client does not log the sensitive resource data.
 

ignore_failure

  • Ruby Type: true, false
  • Default value: false 

Recipe will continue running even after a resource failure is encountered. :quiet ensures the full stack trace is not displayed, and the recipe keeps running over the failure.
 

retries 

  • Ruby Type: integer 
  • Default value: 0

Specifies the number of tries/attempts  to retry the resource and catch exceptions 

 

Notifications 

1.notifies

Ruby Type: Symbol, ‘Chef::Resource[String]’
 

Syntax:

notifies :action , ‘resource_name’, :timer 
 

Notifications are used so that a resource may notify another resource to implement an action after the change of state or completion of a previous action. For this, specify the ‘resource_name’ and :action to be taken, with the :timer for that action. For notifying multiple resources, multiple notifies need to be written separately for each resource.
 

subscribes is used to prevent failure in case the references resource is not found. Otherwise, an error is raised if the required resource is missing in a default condition.
 

The following timers are available for the notification :timer, to specify when the Chef Infra Client is supposed to run a notification:
 

  • :before 

Asks the client to run the action on a resource before processing the resource block.
 

  • :immediately, :immediate 

Specifies that the action should be performed immediately when the resource block is encountered 
 

  • :delayed

In this case, the notification is queued up and executed at the end of a Chef Infra Client Run.
 

2.subscribes 

Ruby Type: Symbol, 'Chef::Resource[String]'
 

Syntax:

subscribes :action, 'resource_name', :timer
 

If one resource is listening to another resource, it may want to take action when the state of the resource it is listening to changes. For this, subscribes is used by specifying the resource_name, :action and :timing of performance.
 

subscribes does not apply the mentioned action to the resource it listens to. It only applies the action to its resource. 
 

Guards

Guard properties are used to examine a node's state during the execution phase of a Chef Infra Client. It accepts a string or a Ruby block value. The result of this property is used to determine whether the resource should be executed further by the Chef Infra Client. The difference in implementation on the two different datatypes are:

  • string: executed as a shell command. If 0 is returned, the guard is executed. For any other returned value, the guard property is not applied. String guards in a powershell_script run Windows PowerShell commands and may return true in addition to 0.
  • Block: executed as a ruby code and returns true or false. The guard is applied for returned value as true; otherwise, not. 

Guards are used to making sure that resources are idempotent. It allows the resource to test for the desired state during its execution. If the desired state is present, the Chef Infra Client is asked not to do anything. 
 

Properties for Guards: 

  • not_if : resource not executed when condition returns true 
  • only_if : resource executed only when condition returns true 
     

Example Statements 

Here is a demonstrative approach to using the macos_power_management resource in recipes:
 

macos_power_management 'Set device to a custom power level' do
  computer_sleep_time 'never'
  display_sleep_time 'never'
  disk_sleep_time 'never'
  action :set
end


Frequently Asked Questions

How to install and use Chef?

Chef is an open source software coded in Ruby, used to implement infrastructure to code. For a detailed explanation of the chef software and its usage, visit our Chef-Installation Guide.
 

What is macos_power_management resource?

The macos_power_management resource is a chef resource that is used to customise and set the power level of kiosk-type devices. You can control and function the sleep time of the system hard disk and display to manage the power levels.
 

What is Gorilla? What is its use?

Chef is a software used to provide an automated management setup. It enables us to manage the users’ desktop applications with ease. For management in Windows, Gorilla is used. 

 

Conclusion 

In this blog, we learnt how to use the macos_power_management resource to update and set the power levels of kiosk-type devices. For more information on Chef and its client-server applications, visit Chef-basicsAnsible VS Chef. To get an insight into the fundamentals of computers, read about the primary topics like DBMSDSACompetitive ProgrammingPythonJava, etc. Share this blog if you find it helpful to help fellow ninjas get acquainted with it and help them grow. Happy Coding!!

 

Live masterclass