Chef service resource

Chef resource represents a piece of the operating system at its desired state. It is a statement of configuration policy that describes the desired state of a node to which one wants to take the current configuration to use resource providers. It helps in knowing the current status of the target machine. The steps required to perform to get the target machine to that state. The resources are grouped in recipes that describe the working configuration.

In the case of Chef, chef::Platform maps the providers and platform versions of each node. At the beginning of every Chef-client run, the Chef server collects the details of any machine's current state. Later, the Chef server uses those values to identify the correct provider.

Resource Syntax

type 'name' do 

   attribute 'value' 

   action :type_of_action 

end

In the above syntax, ‘type’ is the resource type and ‘name’ is the name that we are going to use. In the ‘do’ and ‘end’ blocks, we have the attribute of that resource and the action that we need to take for that particular resource. Every resource that we use in the recipe has its own set of actions, which is defined inside the ‘do’ and ‘end’ blocks.

All resources share a common set of functionality, actions, properties, conditional execution, notification, and relevant path of action.

*Actions:The: nothing action can be used with any resource or custom resource.

*Properties: The ignore_failure, provider, retries, retry_delay, and supports properties can be used with any resource or custom resources.

*Guards: The not_if and only_if conditional executions can be used to put additional guards around certain resources so that they are only run when the condition is met.

*Guard Interpreters: Evaluates a string command using a script-based resource: bash, csh, Perl, powershell_script, python, or ruby.

*Notifications: The notifies and subscribes notifications can be used with any resource.

*Relative Paths: The #{ENV['HOME']} relative path can be used with any resource.

*Run in Compile Phase: Sometimes a resource needs to be run before every other resource or after all resources have been added to the resource collection.


Relevant Blogs:

Chef fact 

Chef files  

CIS Benchmark 

Salt stack orchestration

Recent Comments

No comments

Leave a Comment