DevOps Classroom Series – 03/Sept/2020

Chef Server Variants

  • Chef Server has three different variants used for different purposes
    • Chef Infra Server:
      • This is production grade infra server written in ruby on rails which can be used for chef infra.
      • Preferred way for run chef in enterprises.
    • Chef Zero:
      • It is an easy-install in-memory chef server.
      • It is a single node setup (It Runs locally)
      • This is used for chef-client testing
      • Test Kitchen uses chef zero to simulate chef-server
    • Chef Solo:
      • This is an open-source version of chef-client that allows you to run cookbooks without installing chef-server
      • It is a single node setup (It Runs locally)
      • It executes Chef-infra client in a way that it doesnot require chef server
      • This is used by infra provisioning tools like terraform/packer etc

Writing Tests

  • Lets create a cookbook for installing tomcat 9 on ubuntu 18.04
  • Documentation reference [Refer Here]
  • Manual Steps – flavor 1
sudo apt-get update
sudo apt-get install openjdk-11-jdk -y
tar xzf apache-tomcat-9.0.35.tar.gz
sudo mv apache-tomcat-9.0.35 /usr/local/tomcat9
echo "export CATALINA_HOME="/usr/local/tomcat9"" >> ~/.bashrc
echo "export JAVA_HOME="/usr/lib/jvm/java-11-oracle"" >> ~/.bashrc
echo "export JRE_HOME="/usr/lib/jvm/java-11-oracle"" >> ~/.bashrc
source ~/.bashrc

<!-- user manager can access only manager section -->
<role rolename="manager-gui" />
<user username="manager" password="_SECRET_PASSWORD_" roles="manager-gui" />

<!-- user admin can access manager and admin section both -->
<role rolename="admin-gui" />
<user username="admin" password="_SECRET_PASSWORD_" roles="manager-gui,admin-gui" />
  • manual steps flavor 2
sudo apt-get update
sudo apt-get install openjdk-11-jdk -y
sudo apt-get install tomcat9 -y
sudo apt-get install tomcat9-admin tomcat9-docs tomcat9-user tomcat9-examples tomcat9-common -y
edit /etc/tomcat7/tomcat-users.xml to add
<user username="admin" password="password" roles="manager-gui,admin-gui"/>
  • Lets start with flavor2
  • Try writing a recipe for the above steps
  • To create configuration files with static content we can create a file in the chef cookbook.
chef generate file . tomcat-users.xml
  • To copy the files from local cookbook to chef node there is a resource called as cookbook_file Refer Here
  • The contents of this cookbook are shared over here

Chef Inspec

  • Chef Inspec is an open-source framework for testing and auditing your applications & infrastructure.
  • Chef works by comparing the actual state of test kitchen instance with the expressed state of yours in easy to write inspec code.
  • Inspec desired state expression looks as shown below
describe <entity> do
  it { <expectation> }
  • In the <entity> section we can use inspec resources Refer Here
  • Expectations can be set by matchers Refer Here
  • Sample Test Execution Preview
  • The test code is hosted at here

Leave a Reply

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

About learningthoughtsadmin