Setup Chef Server on Ubuntu

Hi There! I am back after a long time πŸ˜‰ Was really stuck with other things.

In this post, I will explain how you can setup your Chef Server on an Ubuntu machine. Chef, as we know, is an Infrastructure Automation platform that helps manage, maintain & housekeep a number of servers by keeping them in the desired state. Sounds complicated? Ok, let me put this in an easy way πŸ˜‰

Suppose you have 25 servers in your infrastructure. 10 are Apache web-servers, 5 are Database servers, 2 are monitoring servers, 2 are LDAP servers & rest are Tomcat servers. You are given the responsibility to set up all of them πŸ˜€ You will have to install packages, create users & groups & do tons of modifications like editingΒ /etc/hosts or /etc/resolv.conf files. All this leads to a lot of wastage in terms of time & resources. That’s where Chef or similar software helps. Chef will allow you to do all these tasks in much simpler & efficient manner. You define what packages are to be installed on what servers & Chef will do it. Add users to theΒ Β passwd file & Chef will populate this file to all the required servers. This is known as Chef recipes. Seems fun, right? πŸ˜‰

Chef has 3 components.

  • Workstation : – A server on which you define all your modifications like contents of passwd file, packages to be installed etc. In other words, here you create Chef recipes & cookbooks.
  • Server : – Where you manage all your nodes & where all the recipes are sent to. Server then adjusts the nodes according to the recipes. It also has a web UI where you can see & manage your nodes. Chef Server can only be installed on Unix/Linux machines.
  • Nodes : – The individual servers that are to be managed by Chef. Like your Apache or DB servers. Could be any OS.

Now that you know the basic terminologies, lets setup our Chef Server πŸ™‚

Lab Description : –

  • OS – Ubuntu 14.04
  • RAM – 4 GB
  • IP Address range – 192.168.0.XX
  • Chef Server version – 12.4.0
  • Chef Manage version – 2.3.0

Steps to perform : –Β 

1. Download & Install Chef Server package. Go toΒ and download the package for your OS. In this tutorial, I have chosen Ubuntu.Β Install it by using below command.

root@chef-server:/home/shashank# dpkg -i chef-server-core_12.4.0-1_amd64.deb
Selecting previously unselected package chef-server-core.
(Reading database ... 166216 files and directories currently installed.)
Preparing to unpack chef-server-core_12.4.0-1_amd64.deb ...
Unpacking chef-server-core (12.4.0-1) ...

2. Configure Chef Server. Next step will be to configure it. So run the command mentioned below. It will dump an output similar to it. Please note that this step will take around 2-3 minutes or more.

root@chef-server:/home/shashank# chef-server-ctl reconfigure
Starting Chef Client, version 12.6.0
resolving cookbooks for run list: ["private-chef::default"]
Synchronizing Cookbooks:

Deprecated features used!
Cannot specify both default and name_property together on property path of resource yum_globalconfig. Only one (name_property) will be obeyed. In Chef 13, this will become an error. Please remove one or the other from the property. at 1 location:
- /opt/opscode/embedded/cookbooks/cache/cookbooks/yum/resources/globalconfig.rb:76:in `class_from_file'

Chef Client finished, 323/451 resources updated in 03 minutes 10 seconds
Chef Server Reconfigured!

3. Create Chef user & its organisation.Β Issue below command to create a user & its organisation for Chef. This user will be used to log-in to its web UI & perform other admin tasks. These .pem keys will be used to authenticate & validate the certificates. Choose any desired location.

root@chef-server:/home/shashank# chef-server-ctl user-create chef-admin Chef Admin root@chef-server 'chefadmin' --filename /home/shashank/chef-admin.pem
root@chef-server:/home/shashank#Β chef-server-ctl org-create shashank 'Shashank Chef Server' --association_user chef-admin --filename /home/shashank/chef-validator.pem

4. Install Chef Manage(web UI). Default step is to install it using Chef itself by issuing chef-server-ctl install chef-manage command But it threw an error on my machine that apt-get update was unable to retrieve this package. So, I downloaded the package from Chef’s site & installed it using dpkg command. It will ask you to accept the license agreement.

root@chef-server:/home/shashank# dpkg -i Downloads/chef-manage_2.3.0-1_amd64.deb

To use this software, you must agree to the terms of the software license agreement.
Press any key to continue.
Type 'yes' to accept the software license agreement, or anything else to cancel.
Starting Chef Client, version 12.4.1

When its done installing it, it will prompt you to issue another command.

Chef Client finished, 323/451 resources updated in 03 minutes 10 seconds
Chef Server Reconfigured!
Thank you for installing the Chef Management Console add-on!

The next step in the process is to run:

chef-manage-ctl reconfigure

5. Configure Chef Manage. Issue above command to configure it. It will take some time. Wait for it to finish.

6. Configure Chef Server again. RunΒ chef-server-ctl reconfigure again to configure it.

If everything goes well, you will have your Chef Server ready.

7. Login to Web console (UI). Point your browser to https://localhost:443/login. You may also use IP address. Enter the credentials that you used in step 3 above. And lo!! You are done πŸ™‚

Chef Manage

Logging into Chef Server UI

Chef Manage UI

Chef Server UI

Watch out for other Chef posts on my blog! Coming soon πŸ˜‰


See Cricket Match Score Without Opening a Website As a Notification on Mac/Linux/Windows

Well, this one is not exactly a tutorial on Linux. But it will definitely be a great experience reading this πŸ˜‰ In this post, I will demonstrate how we can use a Python script to see Live Cricket scores as notification alerts right on out laptops/desktops. Without opening a browser πŸ™‚ And all this along-with some learning about Linux/Mac. Sounds interesting? Read on πŸ˜‰

All this has been done on a Mac but same can be done on a Linux/Windows machine.

Install Python 3. Go to official site & download the stable version for your OS.

Download pip tool

bash-3.2# curl -O
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:03 --:--:--     0

Now execute this Python script.

bash-3.2# python3.4

Now try installing a Python package called Beautiful Soup.

bash-3.2# pip3 install beautifulsoup4
Collecting beautifulsoup4
  Downloading beautifulsoup4-4.4.1-py3-none-any.whl (81kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 81kB 2.2MB/s 
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.4.1
You are using pip version 7.1.2, however version 8.0.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

If you face similar issue, then upgrade your pip using below command.

bash-3.2# pip3 install --upgrade pip
Collecting pip
  Downloading pip-8.0.0-py2.py3-none-any.whl (1.2MB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1.2MB 433kB/s 
Installing collected packages: pip
  Found existing installation: pip 7.1.2
    Uninstalling pip-7.1.2:
      Successfully uninstalled pip-7.1.2
Successfully installed pip-8.0.0

Now install below mentioned Python packages. These may or may not be already installed.

  • pync
  • python-dateutil
  • requests
  • six
bash-3.2# pip3 install pync
Collecting pync
  Downloading pync-1.6.1.tar.gz (363kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 364kB 463kB/s 
Collecting python-dateutil>=2.0 (from pync)
  Downloading python_dateutil-2.4.2-py2.py3-none-any.whl (188kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 192kB 1.3MB/s 
Collecting six>=1.5 (from python-dateutil>=2.0->pync)
  Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, pync
  Running install for pync ... done
Successfully installed pync-1.6.1 python-dateutil-2.4.2 six-1.10.0
bash-3.2# pip3 install python-dateutil
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from python-dateutil)
bash-3.2# pip3 install requests
Collecting requests
  Downloading requests-2.9.1-py2.py3-none-any.whl (501kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 503kB 21kB/s 
Installing collected packages: requests
Successfully installed requests-2.9.1
bash-3.2# pip3 install six
Requirement already satisfied (use --upgrade to upgrade): six in /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages

Thats it. All Python packages have been installed. Now install one more component terminal-notifier. Homebrew is a package manager for Mac. Please install it first to install other Mac stuff (like terminal-notifier) not bundled with its OS.

Shashank-MacBook-Pro:~ admin$ brew install terminal-notifier
==> Downloading
######################################################################## 100.0%
==> Pouring terminal-notifier-1.6.3.el_capitan.bottle.tar.gz
==> Caveats
.app bundles were installed.
Run `brew linkapps terminal-notifier` to symlink these to /Applications.
==> Summary
🍺  /usr/local/Cellar/terminal-notifier/1.6.3: 12 files, 2.1M

Download score-notify Python script. Lets now download the actual Python script that will do the trick. Go to this siteΒΒ & download this. All credit goes to this developer. His script does all the magic & he deserves all the accolades πŸ™‚ I am just using his work to demonstrate.

Once downloaded, just run it using Python.

bash-3.2# python3.4 -f 30
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/ UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

To get rid of this warning, change this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "html.parser")


Following live scores are available now:

1 Afghanistan A 484/8  v Zimbabwe A 139/1 *
2 East Zone (Bangladesh) 203/8 * v North Zone (Bangladesh)
3 South Zone (Bangladesh) v Central Zone (Bangladesh) 233/5 *
4 Australia 348/8  v India 245/1 *
5 Colts Cricket Club 163/9  v Badureliya Sports Club 147/8 *
6 Sri Lanka Ports Authority Cricket Club 150/8  v Sri Lanka Army 153/4 *
7 Moors Sports Club 111/10 * v Saracens Sports Club 180/6 
8 England Lions 6 * v Pakistan A 192/10 
9 Bangladesh v Zimbabwe 72/1 *
10 Chilaw Marians Cricket Club 188/6 * v Tamil Union Cricket and Athletic Club
11 Bloomfield Cricket and Athletic Club v Galle Cricket Club 126/4 *
12 Nondescripts Cricket Club 129/5 * v Sinhalese Sports Club
13 Baroda v Uttar Pradesh
14 Trinidad & Tobago v Guyana

Enter your choice: 4

Great! I will keep displaying the scores now for every 30 seconds. And proxy set is to False.

This will show notifications about scores every 30 seconds πŸ™‚


EICAR Test File

Open Notepad & paste the following content there : –

Now save the file with .com extentsion. Try double clicking it. EICAR test file will print “EICAR-STANDARD-ANTIVIRUS-TEST-FILE!”

What makes this file special? Well most Antivirus (AV) software will detect this file as a virus! Why?? Because the code written in this file is a Machine Code instruction. Also, the code is self-modiying or mutating one! This spectacular behavior is the reason most AntiVirus software stop it’s execution & only the text is printed!

But the best thing is that this file doesn’t do anything harmful as all the code is in ASCII human-readable characters & it only prints the the text “EICAR-STANDARD-ANTIVIRUS-TEST-FILE!”.

PS – This file is used to test the functionality of AntiVirus software in a safe manner. Rather than testing AntiVirus with real virus, AV Software companies test their product with EICAR test file. πŸ™‚