Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Have you ever tried automating your organization's network and server equipment management using any software or tool?
This article focuses on one of the automation software, which is Chef. In detail, we will also study one of the Chef Resources, known as the macos_automatic_logout Resource. We will also learn about syntax and properties. Let's dive into the blog to see all these things in more detail.
About Chef
Chef is a tool for automating cloud infrastructure administration. The Chef configuration management tool, was developed by Opscode, which eventually adopted the name Chef.
To automate server deployment and management, Chef turns infrastructure into code. A DevOps expert sets up the Chef Development Kit (Chef DK) on a workstation to specify components and communicate with the Chef Server.
Servers, cloud virtual machines, network devices, and containers are just a few of the node types that Chef can manage. It oversees various systems, including Linux, Windows, mainframes, and others. The solution is designed to enable developers and IT operations specialists to collaborate on deploying applications on IT infrastructure.
Syntax of macos_automatic_logout Resource
There are many properties that are available to the macos_automatic_logout resource. Following is the complete syntax for all these properties:
macos_automatic_logout 'name' do
autologout_time Integer # default value: 3600
action Symbol # defaults to :enable if not specified
end
In the above syntax,
The resource name is macos_automatic_logout.
The name of the resource block is given using the name.
The steps taken by Chef Infra Client to bring the node into the required state are identified by action.
autologout_time is the property that is available to the resource.
Actions of macos_automatic_logout Resource
Following are the actions that the macos_automatic_logout resource has:
:disable- It is used to disable the resource.
:enable- It is used to enable the resource.
:nothing- This resource block will not act unless it is notified by any other resource to take action. Once notified, this resource block will either run immediately or be queued up to run at the end of a Chef Infra Client run.
Properties of macos_automatic_logout Resource
Following are the properties that the macos_automatic_logout resource has:
:autologout_time- It is the amount of time (in seconds) to elapse before logging out of the system. The default value is 1 hour.
Common Resource Functionality of macos_automatic_logout Resource
Chef resources also include some common properties, notifications, and resource guards.
Common Properties
Following are the properties that are common to every resource:
compile_time: It controls the phase during which the resource is run on the node. We can set it to “true” to run while the resource collection is being created (the compile phase). We can set it to “false” to run while Chef Infra Client is working on the node configuration (the converge phase).
ignore_failure: It helps in running a recipe even if a resource has failed for any reason. :quiet will not show the full stack trace. As a result, the recipe will continue to run even if a resource fails.
retries: It is the number of attempts to catch an exception and retry the resource.
sensitive: It ensures that Chef Infra Client does not log sensitive resource data.
retry_delay: It is the delay in seconds between the retry attempts.
Notifications
notifies: When one resource's state changes, it may notify another resource to take appropriate action. A resource can notify multiple resources. It uses a “notifies” statement for each resource that has to be notified.
subscribes: If the status of the resource being listened to changes, the resource that is listening may take action after doing so.
A timer is used to specify the point during a Chef Infra Client run at which a notification will run. The following timers are available:
:before- It specifies that the action on a notified resource must run before processing the resource block in which the notification is present.
:delayed- It specifies that a notification should be queued up and executed at the end of a Chef Infra Client run.
:immediate, :immediately- It specifies that a notification should run immediately for each resource that has been notified.
Guards
When a Chef Infra Client run is executed, a node's state can be assessed using a guard property. Depending on these results, a guard property is then used to inform the Chef Infra Client whether it should further carry out a resource's execution. A Ruby block value or a string value can be used to specify a guard property:
Properties
not_if: It prevents a resource from executing when the condition returns true.
only_if: It allows a resource to execute only if the condition returns true.
Examples
The following examples demonstrate various approaches for using the macos_automatic_software_updates resource in recipes:
Setting up Automatic Logouts:
automatic_logout 'Automatically logout for inactivity' do
autologout_time 900
action :enable
end
Disabling the Automatic Logouts:
automatic_logout 'Automatically logout for inactivity' do
action :disable
end
Frequently Asked Questions
Does Chef have a GUI or Graphical User Interface?
Chef is written in Ruby and Erlang and uses a pure-Ruby DSL in the Knife CLI. It also includes a nice GUI for easy management.
What are the three main components of a chef?
Workstations, servers, and nodes are the three main components of Chef.
What is a client in Chef?
On each node that Chef is responsible for managing, an agent called a chef-client runs locally.
Which language is used by Chef?
The chef develops a domain-specific language using the well-known Ruby language. The chef doesn't assume anything about a node's present state. It makes use of its mechanisms to determine the machine's current status. The cloud's software, storage, and server are best deployed and managed using Chef.
Conclusion
In this article, in detail, we have studied one of the Chef Resources, known as the macos_automatic_software_updates Resource.