DevOps Classroom Series – 04/Dec/2019

Environment File

  • In the chef-repo file create folder called as environments
  • In the environments create two files called as qa.rb and uat.rb
  • qa.rb contents are
name "qa"
description "This is the qa version"
cookbook_versions({
  'envroledemo'=>'= 1.1.0'
})
  • uat.rb contents are
name "uat"
description "This is the uat version"
cookbook_versions({
  'envroledemo'=>'= 1.0.0'
})
  • Upload environments to chef server using knife environment from file <filename>
  • Apply environment to nodes

Attribute Precedence:

  • Attributes can be defined in

    • recipe
    • Attributes files
    • role
    • environment
  • Each Attribute has type.

    • default
    • force_default
    • normal
    • override
    • force_override
  • Chef defines priority for each position in the combination of Place of Attribute definition and Attribute Type Preview

  • Refer

Chef Templates

  • Templates are used for configuration files.
  • Consider this scenario.
  • Install apache server. Create a file called as index.html in /var/www/html/index.html with following content
Hello , 
Operating System is <os>
ip address is <ipadress>
  • Generate cookbook
chef generate cookbook -b templatedemo
  • Now generate a template
chef generate template . index.html
  • A new folder called as templates with index.html.erb file gets created.
  • In this file add the following content
Hi,
Operating System is <%= node['platform'] %>
Ip address is <%= node['ipaddress'] %>


  • In the recipes\default.rb file add the template resource

template 'home/ubuntu/index.html' do
    source 'index.html.erb'
    action :create
end
  • upload and test this cookbook in kitchen to find the dynamic values in the index.html on the node.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner