Table of contents
1.
Introduction
2.
Syntax for windows_firewall
2.1.
Example
3.
Action
4.
Common properties
5.
Notification
6.
Guard
6.1.
Properties
7.
Frequently Asked Questions
7.1.
Why do we need windows_firewall resources?
7.2.
Can we ignore a failure and continue with execution?
7.3.
Can we set the timer for the notification?
7.4.
What if we don't declare the type of action in window_firewall?
7.5.
What is the ruby type for properties in window_defender_exlusion resource?
8.
Conclusion
Last Updated: Mar 27, 2024
Medium

CHEF- RESOURCES - windows_firewall Resource

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

Introduction

In this blog, you will learn about windows_firewall, a resource in Chef. If you are unfamiliar with the word firewall, let us give you a brief. A firewall is network software that monitors and observes all the outgoing and incoming packets from the router to the network and filters out suspicious packets.

We will learn how to enable and disable windows firewall resources in chef.

windows_firewall Resource

Syntax for windows_firewall

windows_firewall 'name' do
  action      Symbol # defaults to enable if not specified
end

Above is the correct syntax to create the script. 

  • windows_firewall is one of the resources in chef.
  • Write the name for the resource in the ‘name’ tag.
  • In action, we declare what operation the should chef infra client perform to bring the node to the intended state.

Example

windows_firewall 'Enable firewall' do
  action :enable
end

Action

This section describes all available actions for the windows_firewall resource.

  • :disable - Disable the window firewall.
  • :enable - Enable the window firewall.
  • :nothing - This action will let the resource until it gets confirmation from the other resource. Once it gets notified, it might run or queue for the run.

Common properties

Some common properties we can apply to available resources in chef infra client.

  • ignore_fiaiure - To ignore a failure.
  • retires - To catch a number of exceptions and retry resources.
  • retry_delay - Add’s delay during the execution.
  • sensitive - To check if the chef infra client logs in sensitive data.
  • Compile_time - Control the stage of the node's resource execution.

Notification

Type of notification methods we can use in the script.

notifies: notifies let you notify another resource to take action if there is a change in its state.

Syntax:

notifies :action, 'resource[name]', :timer

Just specify an action, resource name, and time for the notification.

Types of timers:

  • :before - It notify to execute an action in a resource before processing.
  • :delayed - It notify to queued and run at the end.
  • :immediate and :immediately - It notifies to run immediately.


subscribe: This lets the resource listen to a particular resource and works if there is a change in the state of the listening resource.

Syntax:

subscribe :action, 'resource[name]', :timer

Just specify an action, resource name, and time for the notification.

Types of timers:

  • :before - It notify to execute an action in a resource before processing.
  • :delayed - It notify to queued and run at the end.
  • :immediate and :immediately - It notifies to run immediately.

Guard

  • During the execution stage of a Chef Infra Client run, the condition of a node can be assessed using a guard property. 
  • A guard property is then used to inform Chef Infra Client whether it should keep running a resource in response to the findings of this assessment.
  •  A Ruby block value and a string value are acceptable values for a guard property.

Properties

not_if - to stop the execution if the given condition is true.

only_if - to execute a resource if the condition is true.

Frequently Asked Questions

Why do we need windows_firewall resources?

To prevent any suspicious and harmful packets in the network.

Can we ignore a failure and continue with execution?

Yes, by using the ignore_failure property, we can ignore failures.

Can we set the timer for the notification?

Yes, we can set the notification according to our need using :before, :delayed, and :immediately tag.

What if we don't declare the type of action in window_firewall?

The default value for action is :enable.

What is the ruby type for properties in window_defender_exlusion resource?

There are not any properties specifically for the windows_firewall resource.

Conclusion

In this blog, we learned about one of the resources, windows_firewall, available in chef. We discussed the syntax of windows_firewall and various properties and actions available for the windows_firewall resource.

To learn more about chefs, check out the articles given below:

To learn more about DSA, competitive coding, and many more knowledgeable topics, please look into the guided paths on Coding Ninjas Studio. Also, you can enroll in our courses and check out the mock test and problems available to you. Please check out our interview experiences and interview bundle for placement preparations.

Live masterclass