Actions

The resource windows admin control has the following actions: disable, enable, and nothing.
This resource block does not act until notified to do so by another resource. When a Chef Infra Client run ends, this resource block either executes right away or waits to do so.
Common Resource Functionality
Common characteristics such as notifications and resource guards are examples of Chef resources.
Common Properties
Every resource has the following characteristics:
Values: true or false | Default: false
Control the phase of the resource's execution on the node. To execute while the resource collection is being constructed, set to true (the compile phase). Set to false to prevent the Chef Infra Client from running while the node is configured.
Type: true or false, :quiet | Default State: false
If a resource fails for whatever reason, continue running the recipe. If a resource fails, ": quiet" will not display the whole stack trace, and the recipe will continue to run.
Ruby Type: Integer | Default Value: 0
The number of times an exception is caught and the resource is retried.
Ruby Type: Integer | Default Value: 2
The time between retry attempts is in seconds.
Ruby Type: true, false | Default Value: false
Ensure that Chef Infra Client does not log sensitive resource data.
Notifications

Ruby Type: Symbol, 'Chef::Resource[String]'
When a resource's status changes, It could notify another resource to take action. Provided a "resource[name]," the ": action" that resource should take, and the ": timer" for that action. A resource may alert more than one resource, with each being alerted separately., use a "notifies" statement.
An error is raised if the referenced resource does not exist. "Subscribes," on the other hand, will not fail if the source resource is not found.
A timer specifies when a notice is sent during a Chef Infra Client execution. There are the following timers available:
It specifies that an action should be taken on a resource that has been alerted before processing the resource block that contains the notification.
Default. This property specifies that a notification should be queued and executed at the end of a Chef Infra Client run.
- : immediate, : immediately
Specifies that a notice should be sent out promptly for each resource that has been informed.
The syntax for notifies is as follows:
notifies : action, 'resource[name]', : timer
If the status of the resource being listened to changes, the resource may take action. Enter a "resource[name]," the ": action" to be performed, and the ": timer" for that action.
file '/nginx/ssl/demo.crt' do
mode '0700'
owner 'adm'
end
service 'nginx' do
subscribes : reload, 'file[/nginx/demo.crt]', : immediately
end
The subscribes property in this case reloads the nginx service whenever its certificate file, /etc/nginx/ssl/example.crt, is modified. Subscribes makes no changes to the certificate file; it just listens for changes to the file and runs the : reload action for its resource (in this case, nginx) when a change is detected.
The subscription will not throw an error if the other resource does not exist. In contrast, the tighter semantics of notifies will throw an error if the other resource does not exist.
A timer specifies when a notice is sent during a Chef Infra Client execution. There are the following timers available:
It specifies that an action should be taken on a resource that has been alerted before processing the resource block that contains the notification.
Default. This property specifies that a notification should be queued and then executed at the end of a Chef Infra Client run.
- : immediate, : immediately
Specifies that a notice should be sent out promptly for each resource that has been informed.
The syntax for “subscribes” is as follows:
subscribes : action, 'resource[name]', : timer
Guards
During the execution stage of a Chef Infra Client run, the condition of a node can be assessed using a guard property.. Based on the results of this review, a guard property is utilized to indicate Chef Infra Client whether it should continue executing a resource. A guard property can take a string or a Ruby block value:
-
As a shell command, a string is performed.The guard is turned on if the command returns 0. The guard property is disregarded if the command returns a different value. String guards in a "powershell script" execute Windows PowerShell commands and may return true in addition to 0 if they are successful.
-
A Ruby code block is performed and must return true or false. In the event that the block returns true, the guard property is used. The guard attribute is not applied if the block returns false.
Properties
A guard can be defined using the following properties, which are assessed throughout the execution phase of a Chef Infra Client run:
-
not_if: Prevents a resource from being executed when the condition is true.
- only_if: Allow a resource to be executed only if the condition is met.
Examples
The following examples show multiple ways to use the windows admin control resource in recipes:
Turns on UAC to need administrative access for changes:
admin_control 'To make system-wide modifications, you must have administrative privileges.' do
action :enable
end
Turns off UAC:
admin_control 'System-wide changes do not necessitate administrative privileges.' do
action :disable
end
Frequently Asked Questions ⁉️
What does a DevOps Chef do?
Chef is an open-source cloud deployment and configuration management tool. Anyone can use it to organize servers, whether they are in a departmental data center or the cloud.
Why is Chef crucial to DevOps?
Chef treats infrastructure like code, which aids in finding a solution. The machine setup is explained in a Chef's recipe rather than having to be changed manually.
In DevOps, what do Chef and Puppet do?
The DevOps pioneers Chef and Puppet both provide well-liked enterprise-grade configuration automation tools.
What is a command line interface?
A command-line interface(CLI) is a text-based user interface (UI) used to get commands from the user in the form of texts.
In which language is Chef written?
Chef is written in ruby and erlang programming language.
Conclusion
This article discussed the Chef resources mainly windows_admin_control, it’s syntax, actions etc.
We hope this blog on Chef resources - windows_admin_control was helpful.
You can refer to other similar articles as well -
And many more on our website.
Visit our website to read more such blogs. Make sure you enroll in our courses, take mock tests, solve problems, and interview puzzles. Also, you can pay attention to interview stuff- interview experiences and an interview bundle for placement preparations.