Monk
Easy To Use Chef Recipes To Automate Boring Stuff.
Setup
Install the Chef Server Ubuntu 16.04 x64
- Ensure that the Server is Accessible by Hostname The first task you need to perform is to ensure that the hostname of the server is a resolvable fully qualified domain name (FQDN) or IP address. You can check this by typing:
hostname -f
It should be something like the following:
sudo nano /etc/hosts
127.0.1.1 fqdn_or_IP_address host_alias
127.0.0.1 localhost
IP_address fqdn_or_IP_address host_alias
- Ensure that Server are up-to-date:
sudo apt-get update
- Download the latest Chef server core (12.17.15 at the time of writing):
wget https://packages.chef.io/files/stable/chef-server/12.17.15/ubuntu/16.04/chef-server-core_12.17.15-1_amd64.deb
- Install the server:
sudo dpkg -i chef-server-core_*.deb
- Remove the download file:
rm chef-server-core_*.deb
- Run the chef-server-ctl command to start the Chef server services:
sudo chef-server-ctl reconfigure
Create an Admin User and Organization
- We can use the user-create sub-command of the chef-server-ctl command. The command requires a number of fields to be passed and The general syntax is:
chef-server-ctl user-create USERNAME FIRST_NAME LAST_NAME EMAIL PASSWORD
For example, Let's go with the following:
sudo chef-server-ctl user-create monk john doe [email protected] password -f monk.pem
- You can create an organization with the org-create sub-command.
chef-server-ctl org-create SHORTNAME LONGNAME --association_user USERNAME
For example, let's go with the following:
sudo chef-server-ctl org-create clivern "Clivern.com" --association_user monk -f clivern-validator.pem
Install Management Server
In order to install the management server, Just run the following:
chef-server-ctl install chef-manage
chef-server-ctl reconfigure
chef-manage-ctl reconfigure
Configure a Chef Workstation
- Clone this repository.
git clone https://github.com/Clivern/Monk.git Monk
-
Create
.chef
directory insideMonk
repository.
cd Monk
mkdir .chef
- Then transfer the previously created private keys on chef server to
.chef
directory.
cd Monk
scp root@chef_server_domain_or_ip:/root/monk.pem ./.chef
scp root@chef_server_domain_or_ip:/root/clivern-validator.pem ./.chef
Configuring Knife to Manage your Chef Environment
Now that you have your Chef keys available on your workstation, we can configure the knife to connect to and control your Chef infrastructure. This is done through a knife.rb file that we will place inside .chef
directory along with our keys.
nano ./.chef/knife.rb
In this file, paste the following information:
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name "username"
client_key "#{current_dir}/name_of_user_key"
validation_client_name "organization_name-validator"
validation_key "#{current_dir}/organization_key"
chef_server_url "https://server_domain_or_IP/organizations/organization_name"
syntax_check_cache_path "#{ENV['HOME']}/.chef/syntaxcache"
cookbook_path ["#{current_dir}/../cookbooks"]
Which on our case should be something like the following:
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name "monk"
client_key "#{current_dir}/monk.pem"
validation_client_name "clivern-validator"
validation_key "#{current_dir}/clivern-validator.pem"
chef_server_url "https://server_domain_or_IP/organizations/clivern"
syntax_check_cache_path "#{ENV['HOME']}/.chef/syntaxcache"
cookbook_path ["#{current_dir}/../cookbooks"]
Now if we run knife client list
, we should get clivern-validator
.
Bootstrapping a New Node with Knife
In order to bootstrap a new node, you can use the following command:
knife bootstrap node_domain_or_IP [options]
In case we want to bootstrap a node with name node-01
and username is root
and the private key is in .chef
directory, we should run the following on our chef workstation.
knife bootstrap node_domain_or_IP -x root -A -N node-01
Once your new node is bootstrapped, you should have a new client and a new node:
$ knife client list
clivern-validator
node-01
$ knife node list
node-01
Our Cookbooks
- Package Cookbook: Install and Configure Linux Packages.
- Apache Cookbook: Install and Configure Apache Server.
- Nginx Cookbook: Install and Configure Nginx Server.
- Django Apps Cookbook: Install and Configure Django/Python Apps.
- Consul Cookbook: Install and Configure Consul.
- HAProxy Cookbook: Install and Configure HAProxy.
- MySQL Replication Cookbook: Replicate MySQL With Chef.
- Prometheus Cookbook: Install and Configure Prometheus.
Community Cookbooks
- Users: Manages OS users from databags.
Acknowledgements
© 2018, Clivern. Released under The Apache Software License, Version 2.0.
Monk is authored and maintained by @clivern.