Skip to content

Commit

Permalink
Merge pull request sivajavatechie#2 from chef-cft/add_refactor
Browse files Browse the repository at this point in the history
Add refactor
  • Loading branch information
ncjohnson authored Oct 24, 2017
2 parents 1085872 + b6808ea commit cf14678
Show file tree
Hide file tree
Showing 19 changed files with 307 additions and 420 deletions.
45 changes: 45 additions & 0 deletions 1_MongoDB/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Install MongoDB

MongoDB is an open-source, document-oriented database designed for ease of development and scaling. The MongoDB documentation site includes a [tutorial on how to install MongoDB on RHEL-based system](http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/).

## Goal

Use Chef to successfully install MongoDB on a RHEL-based target system.

## Success Criteria

You should be prepared and able to demonstrate the following:

* Your Chef cookbook successfully executes on your target node without errors
* Your Chef cookbook is portable and can be run by Chef to validate your work. Please include any instructions or assumptions needed to successfully execute your cookbook.
* You can login to MongoDB by typing `mongo` on the target system
* You can run `chef-client` multiple times without failures
* Your GitHub.com source code repository shows the history of your work

You should be able to explain the following:

* Steps taken to achieve the end result
* Build and test process of Chef code
* Tools and resources used in the process

>Note: You are NOT required to use Chef Server for this exercise, but you may if that is your preference.
## Instructions

* Translate the MongoDB installation instructions from `install.rb` into Chef code that completes the installation
* Use the Chef [Resources Reference](https://docs.chef.io/resources.html) to find the most appropriate Chef resources to use for each task
* Once you feel you have met the success criteria outlined above, send a link to your GitHub.com repo to the person coordinating these workshops
* Provide instructions for us to run your cookbook so that we can test your work.

There are a couple of ways that you can write, test and run your cookbook.

* Write and test your cookbook locally using Test Kitchen via Vagrant + Virtual Box, or the cloud platform of your choice.
* Steps for this option are outlined [here](https://learn.chef.io/tutorials/local-development/)
* Develop directly on your RHEL-based virtual machine
* Write your cookbook in vim, nano or emacs, and run `chef-client` in `--local-mode`
* The ChefDK or Chef Client must be installed on the VM first

## Suggested Resources

* Use the [Chef Documentation](http://docs.chef.io) to identify and use resources that will help you model the desired state of your infrastructure.
* [MongoDB Installation Instructions](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/)
File renamed without changes.
40 changes: 24 additions & 16 deletions Tomcat/INSTRUCTIONS.md → 2_Tomcat/INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
# Installation Instructions
# Manual Installation Instructions for Tomcat

* To install OpenJDK 7 JDK using yum, run this command:
Install OpenJDK 7 JDK using yum, run this command:

```
```shell
$ sudo yum install java-1.7.0-openjdk-devel
```

* Create the User
Create a user for tomcat

```
$ sudo groupadd chef
$ sudo useradd -g chef chef
$ sudo groupadd tomcat
$ sudo useradd -M -s /bin/nologin -g tomcat -d /opt/tomcat tomcat
```

* Download the Tomcat Binary
Download the Tomcat Binary

> NOTE: A specific binary will be mentioned below but it will likely be out of date. You can find the binaries for Tomcat 8 here at https://archive.apache.org/dist/tomcat/tomcat-8/
```
$ cd /tmp
$ wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.33/
$ wget http://apache.cs.utah.edu/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz
```

* Extract the Tomcat Binary
Extract the Tomcat Binary

```
$ sudo mkdir /opt/tomcat
$ sudo tar xvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
```

* Update the Permissions
Update the Permissions

```
$ sudo chgrp -R tomcat conf
$ sudo chmod g+rwx conf
$ sudo chmod g+r conf/*
$ sudo chgrp -R tomcat /opt/tomcat
$ sudo chmod -R g+r conf
$ sudo chmod g+x conf
$ sudo chown -R tomcat webapps/ work/ temp/ logs/
```

* Install the Systemd Unit File
Install the Systemd Unit File

```
$ sudo vi /etc/systemd/system/tomcat.service
Expand Down Expand Up @@ -67,20 +67,28 @@ ExecStop=/bin/kill -15 $MAINPID
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
```

* Reload Systemd to load the Tomcat Unit file
Reload Systemd to load the Tomcat Unit file

```
$ sudo systemctl daemon-reload
```

Ensure `tomcat` is started and enabled

```
$ sudo systemctl start tomcat
$ sudo systemctl enable tomcat
```

* Verify that Tomcat is running by visiting the site
Verify that Tomcat is running by visiting the site

```
$ curl http://localhost:8080
Expand Down
45 changes: 45 additions & 0 deletions 2_Tomcat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Install and Configure Apache Tomcat

The [Apache Tomcat®](http://tomcat.apache.org/) software is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies. The Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket specifications are developed under the Java Community Process.

## Goal

Use Chef to successfully install and configure tomcat on a RHEL7-based target system.

## Success Criteria

You should be prepared and able to demonstrate the following:

* Your Chef cookbook successfully executes on your target node without errors
* Your Chef cookbook is portable and can be run by Chef to validate your work. Please include any instructions or assumptions needed to successfully execute your cookbook.
* You can interact with the default tomcat site in a browser or successfully `curl localhost` on the target system
* You can run `chef-client` multiple times without failures
* Your GitHub.com source code repository shows the history of your work

You should be able to explain the following:

* Steps taken to achieve the end result
* Build and test process of Chef code
* Tools and resources used in the process

>Note: You are NOT required to use Chef Server for this exercise, but you may if that is your preference.
## Instructions

* Translate the Tomcat installation instructions from `INSTRUCTIONS.rb` into Chef code that completes the installation and configuration
* Use the Chef [Resources Reference](https://docs.chef.io/resources.html) to find the most appropriate Chef resources to use for each task
* Once you feel you have met the success criteria outlined above, send a link to your GitHub.com repo to the person coordinating these workshops on your behalf
* Provide instructions for us to run your cookbook so that we can test your work.

There are a couple of ways that you can write, test and run your cookbook.

* Write and test your cookbook locally using Test Kitchen via Vagrant + Virtual Box, or the cloud platform of your choice.
* Steps for this option are outlined [here](https://learn.chef.io/tutorials/local-development/)
* Develop directly on your RHEL-based virtual machine
* Write your cookbook in vim, nano or emacs, and run `chef-client` in `--local-mode`
* The ChefDK or Chef Client must be installed on the VM first

## Suggested Resources

* Use the [Chef Documentation](http://docs.chef.io) to identify and use resources that will help you model the desired state of your infrastructure.
* [Tomcat Installation Instructions](https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-centos-7)
7 changes: 5 additions & 2 deletions Tomcat/tomcat.service → 2_Tomcat/tomcat.service
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=chef
Group=chef
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
48 changes: 48 additions & 0 deletions 3_Bonus/Awesome_Appliance_Repair/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Awesome Appliance Repair

[Awesome Appliance Repair](https://github.com/learnchef/Awesome-Appliance-Repair) is a sample web application written in Python. The application includes [instructions for installing and initializing the application](https://github.com/learnchef/Awesome-Appliance-Repair/blob/master/AARinstall.py) on Ubuntu using MySQL as the database and Apache as the web server.

## Goal

Use Chef to successfully install and configure the Awesome Appliance Repair application and database on an Ubuntu-based target system.

## Success Criteria

You should be prepared and able to demonstrate the following:

* Your Chef cookbook successfully executes on your target node without errors
* Your Chef cookbook is portable and can be run by Chef to validate your work. Please include any instructions or assumptions needed to successfully execute your cookbook.
* You can interact with the Awesome Appliance Repair site in a browser (e.g., login, etc.)
* You can run chef-client multiple times without failures
* Your GitHub.com source code repository shows the history of your work

You should be able to explain the following:

* Steps taken to achieve the end result
* Build and test process of Chef code
* Tools and resources used in the process

>NOTE: You are NOT required to use Chef Server for this exercise, but you may if that is your preference.
## Instructions

>NOTE: This workshop uses Ubuntu 12.04 or newer and NOT a RHEL-based distribution
* Translate the Awesome Appliance Repair python installation script [AARinstall.py](https://github.com/chef-training/Awesome-Appliance-Repair/blob/master/AARinstall.py) into Chef code that completes the installation and configuration
* Use the Chef [Resources Reference](https://docs.chef.io/resources.html) to find the most appropriate Chef resources to use for each task
* Once you feel you have met the success criteria outlined above, send a link to your GitHub.com repo to the person coordinating these workshops on your behalf
* Provide instructions for us to run your cookbook so that we can test your work.

There are a couple of ways that you can write, test and run your cookbook.

* Write and test your cookbook locally using Test Kitchen via Vagrant + Virtual Box, or the cloud platform of your choice.
* Steps for this option are outlined [here](https://learn.chef.io/tutorials/local-development/)
* Develop directly on your Ubuntu-based virtual machine
* Write your cookbook in vim, nano or emacs, and run `chef-client` in `--local-mode`
* The ChefDK or Chef Client must be installed on the VM first

## Suggested Resources

* Use the [Chef Documentation](http://docs.chef.io) to identify and use resources that will help you model the desired state of your infrastructure.
* The contents of [AARinstall.py](https://github.com/chef-training/Awesome-Appliance-Repair/blob/master/AARinstall.py) are included within this workshop. See `aar.rb`.
* `AwesomeApplianceRepair.pdf` includes some hints and suggestions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,88 +16,88 @@
# # -*- coding: utf-8 -*-
# from subprocess import Popen
# import os, sys, getpass, binascii
#
#
# # The following script assumes that apache2, mysql, and unzip have been installed.
#
#
# # 1. wget https://github.com/colincam/Awesome-Appliance-Repair/archive/master.zip
# # 2. unzip master.zip
# # 3. cd into Awesome-Appliance-Repair
# # 4. sudo mv AAR to /var/www/
# # 5. sudo su root
# # 6. run script: python AARinstall.py
# # 7. manually execute: apachectl graceful
#
#
# if __name__ == '__main__':
# root_dbpswd = getpass.getpass('enter the mysql root user password: ')
#
#
# Popen(['chown', '-R', 'www-data:www-data', '/var/www/AAR'], shell=False).wait()
#
# # apt-get the stuff we need
#
# # apt-get the stuff we need
# proc = Popen([
# 'apt-get', 'install', '-y',
# 'libapache2-mod-wsgi',
# 'python-pip',
# 'python-mysqldb'], shell=False)
# proc.wait()
#
#
# # pip install flask
# Popen(['pip', 'install', 'flask'], shell=False).wait()
#
#
# # Generate the apache config file in sites-enabled
# Popen(['apachectl', 'stop'], shell=False).wait()
#
#
# pth = '/etc/apache2/sites-enabled/'
# for f in os.listdir(pth):
# os.remove(pth + f)
#
#
# f = open('/etc/apache2/sites-enabled/AAR-apache.conf', 'w')
# f.write("""
# <VirtualHost *:80>
# ServerName /
# WSGIDaemonProcess /AAR user=www-data group=www-data threads=5
# WSGIProcessGroup /AAR
# WSGIScriptAlias / /var/www/AAR/awesomeapp.wsgi
#
#
# <Directory /var/www/AAR>
# WSGIApplicationGroup %{GLOBAL}
# WSGIScriptReloading On
# Order deny,allow
# Allow from all
# </Directory>
#
#
# CustomLog ${APACHE_LOG_DIR}/access.log combined
# ServerAdmin [email protected]
# </VirtualHost>
# """)
# f.close()
#
# # Generate AAR_config.py with secrets
#
# # Generate AAR_config.py with secrets
# f = open('/var/www/AAR/AAR_config.py', 'w')
# appdbpw = binascii.b2a_base64(os.urandom(6)).strip('\n')
# secretkey = binascii.b2a_base64(os.urandom(12)).strip('\n')
#
#
# conn_args_string = """CONNECTION_ARGS = {"host":"localhost", "user":"aarapp", "passwd":"%s", "db":"AARdb"}\n\n""" % appdbpw
#
#
# secret_key_string = """SECRET_KEY = "%s"\n\n""" % secretkey
#
#
# database_values_string = """DB_VALUES = [(3,'Maytag','Washer', None, 'pending', "outflow hoses leak"),(4,'GE','Refrigerator', '2013-11-01', 'completed', "Ices up; won't defrost"), (5,'Alessi','Teapot', None, 'pending', "explodes"), (6,'Amana','Range', '2013-11-02', 'completed', "oven heats unevenly"), (7,'Whirlpool','Refrigerator', '2013-11-03', 'pending', "Makes a rattling noise"), (8,'GE','Microwave', '2013-11-04', 'pending', "Sparks and smokes when I put forks in it"), (9,'Maytag','Drier', None, 'pending', "Never heats up"), (10,'Amana','Refrigerator', '2013-11-05', 'pending', "Temperature too low, can't adjust."), (11,'Samsung','Washer', None, 'pending', "Doesn't get my bear suit white"), (12,'Frigidaire','Refrigerator', '2013-11-06', 'completed', "Has a bad smell I can't get rid of."), (13,'In-Sink-Erator','Dispose-all', None, 'pending', "blades broken"), (14,'KitchenAid','Mixer', '2013-11-07', 'completed', "Blows my fuses"), (15,'Moulinex','Juicer', None, 'pending', "Won't start"), (16,'Viking','Range', '2013-11-08', 'completed', "Gas leak"), (17,'Aga','Range', None, 'pending', "burner cover is cracked"), (18,'Jennaire','Cooktop', '2013-11-09', 'completed', "Glass cracked"), (19,'Wolfe','Stove', None, 'pending', "Burners are uneven"), (20,'LG','Dehumidifier', '2013-11-10', 'pending', "Ices up when external temp is around freezing"), (21,'DeLonghi','Oil Space Heater', None, 'pending', "Smells bad"), (22,'Kenmore','Refrigerator', '2013-11-11', 'pending', "excessive vibration"), (23,'Maytag','Washer/Drier', None, 'pending', "outflow hoses leak"), (24,'GE','Refrigerator', '2013-11-12', 'pending', "Refrigerator light is defective"), (25,'Kenmore','Washer', None, 'pending', "Unbalanced spin cycle"), (26,'Cookmore','Outdoor Grill', '2013-11-13', 'pending', "Smoker box is stuck"), (27,'Kenmore','Water heater', None, 'pending', "Can't adjust temperature"), (28,'Sanyo','Minifridge', '2013-11-14', 'pending', "Makes a lot of noise"), (29,'Bosch','Dishwasher', None, 'pending', "leaves spots on my glasses"), (30,'Whirlpool','Trash Compactor', '2013-11-15', 'pending', "leaking hydraulic fluid")]
# """
#
#
# f.write(conn_args_string + secret_key_string + database_values_string)
# f.close()
#
#
# # Create DB, user, and permissions
# import MySQLdb
# db = MySQLdb.connect(host='localhost', user='root', passwd=root_dbpswd)
# sql_script = open('make_AARdb.sql', 'r').read()
#
#
# cur = db.cursor()
# cur.execute(sql_script)
# cur.close()
#
#
# cur = db.cursor()
# cur.execute('use AARdb')
# cur.execute("CREATE USER 'aarapp'@'localhost' IDENTIFIED BY %s", (appdbpw,))
# cur.execute("GRANT CREATE,INSERT,DELETE,UPDATE,SELECT on AARdb.* to aarapp@localhost")
# cur.close()
# db.close()#
# db.close()#
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,4 @@ case "$1" in
esac
:
```
```
Loading

0 comments on commit cf14678

Please sign in to comment.