Chef Automation Part-1
Chef Automation Part-1
A chef is open source tool that is a automation platform that configure and manage your
infrastructure. It is written in Ruby and Erlang languages, it can easily integrate with cloud
platforms to automatically provision and configure new servers.
Features of Chef
• You can easily manage thousands of servers using only a handful of employees.
• Chef is written in Ruby language, so you can customize Chef.
• You are not locked into one way of using Chef. A chef can operate in a distributed stand-
alone mode or in a centralized mode requiring a server.
• Chef is open source and supported by a vibrant community of system administrators
and developers.
• Chef Server
• Workstation
• Chef Node
Chef Server
The Chef server is the brains of the operation which acts as a hub to store configuration data
that is available to every node and also administer access rights.
The Chef Server stores and holds all the cookbooks, recipes and metadata that illustrates each
and every registered node which is being managed by the chef-client and the policies that are
applied to nodes.
Workstation
Workstation is the development machine from where users run all configuration related tasks
which includes creation of cookbooks and recipes, updating chef-repo, interacting with the
single Chef server and many more.
Chef Nodes
A node can be a physical, virtual or cloud machine that contain the chef-client which performs
all the infrastructure automation. Nodes are the computers that we manage using chef and it
act as server in our infrastructure.
Environment
Prerequisites
Host should have fully configured hostname.
Update FQDN – Server, Workstation, and Node
# vim /etc/hosts
172.16.10.123 master.example.com master
172.16.15.1 work.example.com work
172.16.15.2 node1.example.com node1
2- Check domain name for your Chef server to resolve requests correctly
For 64 Bit
[root@master ~]# wget https://packages.chef.io/files/stable/chef-server/12.15.8/el/7/chef-
server-core-12.15.8-1.el7.x86_64.rpm
For 32 Bit
[root@master ~]# wget https://packages.chef.io/files/stable/chef-server/12.15.8/el/7/chef-
server-core-12.15.8-1.el7.s390x.rpm
[root@master ~]#
5- Run below command to configure Chef Server and start all the services
run: bookshelf: (pid 903) 2677s; run: log: (pid 902) 2677s
run: nginx: (pid 890) 2677s; run: log: (pid 889) 2677s
run: oc_bifrost: (pid 894) 2677s; run: log: (pid 893) 2677s
run: oc_id: (pid 886) 2677s; run: log: (pid 885) 2677s
run: opscode-erchef: (pid 904) 2677s; run: log: (pid 901) 2677s
run: opscode-expander: (pid 892) 2677s; run: log: (pid 891) 2677s
run: opscode-solr4: (pid 884) 2677s; run: log: (pid 883) 2677s
run: postgresql: (pid 896) 2677s; run: log: (pid 895) 2677s
run: rabbitmq: (pid 898) 2677s; run: log: (pid 897) 2677s
run: redis_lb: (pid 888) 2677s; run: log: (pid 887) 2677s
[root@master ~]#
8- Create Organization
ashudevops
Name must begin with lowercase letter or digit, may contain lowercase letter, numbers,
hyphens, and underscores, and must be between 1 and 255 characters
Linux ORG
Must begin with non-white space character and must be between 1 and 1023 characters
admin
This option will associate the previously created user (admin) with the admins security group on
the chef server
Linuxorg-validator.pem
Command will generate the RSA private key automatically and should be saved to a safe
location
Note - The “chef-server-ctl” command is used on the Chef Server system for management. It
has built-in help (-h) that will display the various sub-commands.
9- Create chef server Management Console (This is the additional feature of the Chef)
10- You can access Chef Management Console using your server IP Address or hostname
https://172.16.10.123 or https://master.example.com
Chef Server Configuration Successfully Done…..!!
5- Generate Chef-Repo & Setup a user with the email address to begin the git configuration.
[root@work ~]# cd
[root@work ~]# chef generate repo chef-repo
[root@work ~]# ll -a chef-repo/
6- Create a hidden directory called “.chef” under the chef-repo directory. Add and commit all
existing files.
Note: This hidden directory will hold the RSA keys that we created on the Chef server.
9- Cretae a knife.rb file - Knife is a command line interface for between a local chef-repo and
the Chef server
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name "admin"
client_key "#{current_dir}/admin.pem"
validation_client_name "linuxorg-validator"
validation_key "#{current_dir}/linuxorg_validator.pem"
chef_server_url "https://master.example.com/organizations/ashudevops"
syntax_check_cache_path "#{ENV['HOME']}/.chef/syntaxcache"
cookbook_path ["#{current_dir}/../cookbooks"]
log_level: The amount of logging that will be stored in the log file.
log_location: The location of the log file.
node_name: The username of the person using the workstation.
client_key: The location of the user’s authorization key.
validation_client_name: The name for the server validation key that will determine whether a
node is registered with the Chef server.
validation_key: The path to your organization’s validation key.
chef_server_url: The URL of the Chef server, with shortname being the defined shortname of
your organization. /organizations/shortname must be included in the URL.
syntax_check_cache_path: The location in which knife stores information about files that have
been checked for appropriate Ruby syntax.
cookbook_path: The path to the cookbook directory.
[root@work ~]#
2- Now run the following command in order for a client to register itself with Chef Server. -
From Workstation Machine
Doing old-style registration with the validation key at /root/chef- (SHOW THE OUTPUT)
repo/.chef/linuxorg_validator.pem...
Delete your validation key in order to use your user credentials instead
Connecting to node1.example.com
node1.example.com -----> Installing Chef Omnibus (-v 12)
node1.example.com downloading https://omnitruck-direct.chef.io/chef/install.sh
node1.example.com to file /tmp/install.sh.670/install.sh
node1.example.com trying wget...
node1.example.com el 6 x86_64
node1.example.com Getting information for chef stable 12 for el...
node1.example.com downloading https://omnitruck-
direct.chef.io/stable/chef/metadata?v=12&p=el&pv=6&m=x86_64
node1.example.com to file /tmp/install.sh.679/metadata.txt
node1.example.com trying wget...
node1.example.com sha1 e1f7d3c6ee99aedeac4ad8a950877af7edc8164c
node1.example.com sha256
6a47f8f88d3f4568defa13076a21a005bd48ee3e7100d3c66d8f0cc41554306e
node1.example.com url https://packages.chef.io/files/stable/chef/12.21.26/el/6/chef-
12.21.26-1.el6.x86_64.rpm
node3.example.com version 12.21.26
node1.example.com downloaded metadata file looks valid...
node1.example.com downloading
https://packages.chef.io/files/stable/chef/12.21.26/el/6/chef-12.21.26-1.el6.x86_64.rpm
node1.example.com to file /tmp/install.sh.679/chef-12.21.26-1.el6.x86_64.rpm
node1.example.com trying wget...
node1.example.com Comparing checksum with sha256sum...
node1.example.com Installing chef 12
node1.example.com installing with rpm...
node1.example.com warning: /tmp/install.sh.473/chef-12.21.26-1.el7.x86_64.rpm: Header V4
DSA/SHA1 Signature, key ID 83ef826a: NOKEY
node1.example.com Preparing... ################################# [100%]
node1.example.com Updating / installing...
node1.example.com 1:chef-12.21.26-1.el7 ########################## [100%]
node1.example.com Thank you for installing Chef!
node1.example.com Starting the first Chef Client run...
node1.example.com Starting Chef Client, version 12.21.26
node1.example.com [2017-12-05T02:24:05-05:00] INFO: *** Chef 12.21.26 ***
node1.example.com [2017-12-05T02:24:05-05:00] INFO: Platform: x86_64-linux
node1.example.com [2017-12-05T02:24:05-05:00] INFO: Chef-client pid: 621
node1.example.com [2017-12-05T02:24:09-05:00] INFO: Run List is []
node1.example.com [2017-12-05T02:24:09-05:00] INFO: Run List expands to []
node1.example.com [2017-12-05T02:24:09-05:00] INFO: Starting Chef Run for node1
node1.example.com [2017-12-05T02:24:09-05:00] INFO: Running start handlers
node1.example.com [2017-12-05T02:24:09-05:00] INFO: Start handlers complete.
node1.example.com [2017-12-05T02:24:09-05:00] INFO: Error while reporting run start to
node1.example.com resolving cookbooks for run list: []
node1.example.com [2017-12-05T02:24:09-05:00] INFO: Loading cookbooks []
node1.example.com Synchronizing Cookbooks:
node1.example.com Installing Cookbook Gems:
node1.example.com Compiling Cookbooks...
node1.example.com Converging 0 resources
node1.example.com [2017-12-05T02:24:10-05:00] INFO: Chef Run complete in 0.360935465
seconds
node1.example.com
node1.example.com Running handlers:
node1.example.com [2017-12-05T02:24:10-05:00] INFO: Running report handlers
node1.example.com Running handlers complete
node1.example.com [2017-12-05T02:24:10-05:00] INFO: Report handlers complete
node1.example.com Chef Client finished, 0/0 resources updated in 04 seconds
[root@work chef-repo]#
[root@work chef-repo]#
3- Verify the Node is successfully registered with Chef Server using - From Workstation
Machine
Reference- Ashutosh
https://docs.chef.io/install_server.html