Run List and include_recipe in Chef

Share via:

Run List and include_recipe in Chef

chef-client

We run chef-client to apply recipe to bring mode into desired state.

We call this process as convergence.

Run List

Where we mentioned the recipes we called Run List.

Run the recipes in a sequence order that we mentioned in Run List.

To apply each recipe from each cookbook (not multiple recipes from same cookbook) at a time by using chef-client.

To run the command be inside the cookbooks.

Note

Condition

One recipe from one cookbook only.

Include_recipe

To call recipe/recipes from another recipe with in the same cookbook.

To run multiple recipes from same cookbook.

Here comes the default recipe into action.

We need to mention recipes inside the default recipe (same cookbook)

we can mention any number of recipes inside the default recipe.

All recipes must be same cookbook.

We can use default recipe to call remaining recipes.

Run the default recipe be inside the cookbooks.

Note

Condition

All recipes must be same cookbook.

Implementation Steps

Run List

  1. See the list of available cookbook.
  2. See the recipes inside the two cookbook “ktexperts-apache-cookbook” and “ktexperts-cookbook”.
  3. Modify the recipe”ktexperts-apache-recipe.rb”.
  4. Verify syntax of recipe.
  5. Modify the recipe “ktexperts-recipe.rb.
  6. Verify syntax of recipe.
  7. Execute the Recipe/call chef-client based on Run List condition (one recipe from one cookbook).
  8. Verify content of Apache Web Server.
  9. Verify user,group and file.

Include_recipe

  1. To see the list of inside the two cookbook “ktexperts-apache-cookbook”.
  2. Add  ktexperts-apache-recipe.rb and ktexperts-sample-recipe.rb inside the default.rb.
  3. Modify the recipe”ktexperts-apache-recipe.rb”.
  4. Modify the recipe”ktexperts-sample-recipe.rb”.
  5. Execute the default Recipe/call chef-client.
  6. Verify file “ohaifile”.
  7. Verify content of Apache Web Server.

Combine Run List and include_recipe

Execute the multiple recipes from multiple cookbook

Run List

To see the list of available cookbook 

[root@ip-172-31-42-243 cookbooks]# ls
ktexperts-apache-cookbook ktexperts-cookbook

To see the recipes inside the two cookbook “ktexperts-apache-cookbook” and “ktexperts-cookbook”

we have 3 recipes from both cookbook.

Note

We have to follow the Run List condition,i.e we need to take one one recipe from both cookbook.

Now,I am taking ktexperts-apache-recipe.rb from ktexperts-apache-cookbook and ktexperts-sample-recipe.rb from ktexperts-apache-cookbook.

Modify the recipe”ktexperts-apache-recipe.rb”

Open existing recipe “ktexperts-apache-recipe.rb” and write script to change the content of apache web server

Note

:wq! — to quit

Verify syntax of recipe

Modify the recipe “ktexperts-recipe.rb

Open existing recipe ktexperts-recipe.rb” and write script to create user,group and file

Note

:wq! — to quit

Verify syntax of recipe

Execute the Recipe/call chef-client based on Run List condition (one recipe from one cookbook)

Verify content of Apache Web Server

Copy IPV4  Public IP from Chef-Workstation.

Search PV4  Public IP in browser

we can able to see the content of apache web server.

Verify user,group and file

Verify user “ram”

Verify group “ktexperts-DevOps”

Verify file “ramfile”

Include_recipe

To see the list of inside the two cookbook “ktexperts-apache-cookbook” 

we can see 3 recipes inside the cookbook “ktexperts-apache-cookbook”

Note

If we want to run multiple recipes from same cookbook,we have to mention remaining recipes inside the default recipe

All recipes must be same cook only.

Now,I am going to mention ktexperts-apache-recipe.rb and ktexperts-sample-recipe.rb inside the default.rb of ktexperts-apache-cookbook.

Add  ktexperts-apache-recipe.rb and ktexperts-sample-recipe.rb inside the default.rb 

Note

:wq! — to quit

Modify the recipe”ktexperts-apache-recipe.rb”

Open existing recipe “ktexperts-apache-recipe.rb” and write script to change the content of apache web server

Note

:wq! — to quit

Modify the recipe”ktexperts-sample-recipe.rb “

Open existing recipe “ktexperts-sample-recipe.rb ” and write script to update the system information.

Note

:wq! — to quit

Execute the default Recipe/call chef-client

Verify file “ohaifile”

To see the content of ohaifile

Verify content of Apache Web Server

Copy IPV4  Public IP from Chef-Workstation.

Search PV4  Public IP in browser

we can able to see the content of apache web server.

Combine Run List and include_recipe

As of now we have seen Run List and include_recipe

Run List —–>  one recipe from one cookbook

include_recipe —–>  All recipes must be same cookbook.

Combine Run List and include-_recipe ——–> All recipes from from different cookbook.

we can run any number of recipes from any number of cookbook.

Note

Here,I am modifying the recipe.

we can modify if required.

Execute the multiple recipes from multiple cookbook

I didn’t do any changes in the all recipes that’s why it’s showing 0/5 resources.

 

Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates

KTEXPERTS is always active on below social media platforms.

 

Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading...

One thought on “Run List and include_recipe in Chef

  1. I was looking for something to educate my team as part of a new requirement. My college recommended me this site and I found it outstanding.

Leave a Reply to Anonymous Cancel reply