Bootstrap a node with chef

Bootstrap a node with chef

Create First Cookbook in Chef


Before bootstrapping a node, will first create a cookbook which will install tmux on the node while bootstrapping. If you are confused with the term bootstrap, It is a process of installing chef-client on the node so that it can communicate to the chef-server.

Video tutorial for this post:



Let’s create a cookbook. All cookbooks will be stored in the directory cookbooks


mkdir ~/mychef/chef-repo/cookbooks


Now go to mychef directory

cd ~/mychef/chef-repo

Generate a cookbook common_packages, which will have installation of basic packages on the node.

chef generate cookbook cookbooks/common_packages
This will generate the basic scaffolding which is as follow:


cookbooks
├── chefignore
├── common_packages
│ ├── Berksfile
│ ├── README.md
│ ├── chefignore
│ ├── metadata.rb
│ ├── recipes
│ │ └── default.rb
│ ├── spec
│ │ ├── spec_helper.rb
│ │ └── unit
│ │ └── recipes
│ │ └── default_spec.rb
│ └── test
│ └── recipes
│ └── default_test.rb
└── starter
├── attributes
│ └── default.rb
├── files
│ └── default
│ └── sample.txt
├── metadata.rb
├── recipes
│ └── default.rb
└── templates
└── default
└── sample.erb


Let’s write a recipe (a part of cookbook which do some tasks) in ~/mychef/chef-repo/cookbooks/common_packages/recipes/default.rb. Write the following code to install tmux package.


package 'tmux'


Let’s create a role now which would be applied to all the node as it will contain the runlist to be applied which is common to all node.

vi ~/mychef/chef-repo/roles/common.json


Put the following content in it

{
"name": "common",
"description": "This role installs the common packages to be present on all servers",
"run_list": [
"recipe[common_packages]"
]
}


We have created the cookbook, now we will upload the cookbook to chef-server


knife cookbook upload common_packages


To verify if uploaded, run:

knife cookbook list


Go to ~/mychef/chef-repo directory and run the following command to bootstrap a node:

Syntax:

knife bootstrap ADDRESS --ssh-user USER --sudo --identity-file IDENTITY_FILE --node-name node1 --run-list 'recipe[COOKBOOK_NAME]'


Actual Command:

knife bootstrap X.X.X.X --ssh-user ec2-user --sudo --identity-file ~/.ssh/pemfile/ajeet.pem --node-name api-server --run-list 'recipe[common_packages]'


This will bootstrap the node. Now check if the node is being registered to chef-server or not by running following command


knife node list

This will give you the name of the node given while bootstrapping it. You can also verify the node is registered to chef-server or not by seeing nodes tab in chef-web-UI.

Also SSH on node and check if the required package ‘tmux‘ is installed or not.


One thought on “Bootstrap a node with chef

  • April 24, 2017 at 10:28 am
    Permalink

    I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Bootstrap, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on Bootstrap. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Nitesh Kumar
    MaxMunus
    E-mail: [email protected]
    Skype id: nitesh_maxmunus
    Ph:(+91) 8553912023
    http://www.maxmunus.com/

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *