From 0299935b88152e589fd235409826052b2d387483 Mon Sep 17 00:00:00 2001 From: "Dr. Ogg" Date: Sat, 25 Feb 2017 19:33:04 -0800 Subject: [PATCH] updates to cookbook, and install scripts --- README.md | 6 +-- chef-solo-install/Berksfile | 5 +++ chef-solo-install/install.sh | 82 ++++++++++++++++++++++++++++++++++ chef-solo-install/run-chef.sh | 2 + chef-solo-install/solo.json | 30 +++++++++++++ chef-solo-install/solo.rb | 2 + recipes/configure-mariadb.rb | 7 ++- recipes/configure-webserver.rb | 4 +- 8 files changed, 129 insertions(+), 9 deletions(-) create mode 100644 chef-solo-install/Berksfile create mode 100644 chef-solo-install/install.sh create mode 100644 chef-solo-install/run-chef.sh create mode 100644 chef-solo-install/solo.json create mode 100644 chef-solo-install/solo.rb diff --git a/README.md b/README.md index 966c1c9..382f22a 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,10 @@ # chef-itdrc-snap-it Cookbook -# Vagrant requirements +# Dev requirements vagrant plugin install vagrant-omnibus vagrant plugin install vagrant-berkshelf vagrant plugin install vagrant-vbguest vagrant plugin install chef chef gem install berkshelf - - https://downloads.chef.io/chefdk https://www.vagrantup.com - -https://packages.chef.io/files/stable/chef/12.19.36/debian/8/chef_12.19.36-1_amd64.deb diff --git a/chef-solo-install/Berksfile b/chef-solo-install/Berksfile new file mode 100644 index 0000000..2e5a7b3 --- /dev/null +++ b/chef-solo-install/Berksfile @@ -0,0 +1,5 @@ +source 'https://supermarket.chef.io' +cookbook 'composer', '~> 2.5.2' +cookbook 'chef-itdrc-snap-it', git: "https://github.com/DoctorOgg/chef-itdrc-snap-it.git" +cookbook 'apt', '~> 6.0.0' +cookbook 'acme', '~> 2.0.0' diff --git a/chef-solo-install/install.sh b/chef-solo-install/install.sh new file mode 100644 index 0000000..3327ad0 --- /dev/null +++ b/chef-solo-install/install.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# This script used to bootstrap a chef-solo install of the itdrc Snap IT cookbook. +# For debian 8/8.5 machiens ONLY!!!! +# 'curl -sSL https://raw.githubusercontent.com/DoctorOgg/chef-itdrc-snap-it/chef-solo-install/install.sh | sudo bash' +# or: +# 'wget -qO- https://raw.githubusercontent.com/DoctorOgg/chef-itdrc-snap-it/chef-solo-install/install.sh | sudo bash' + +# Fyi, i borrowed inspiration for this script for the docker folk, thanks guys! + +set -e +CHEF_SOLO_DIR='/root/itdrc-sanp-it-installer' +BERKS_URL="https://raw.githubusercontent.com/DoctorOgg/chef-itdrc-snap-it/chef-solo-install/Berksfile" +SOLO_JSON_URL="https://raw.githubusercontent.com/DoctorOgg/chef-itdrc-snap-it/chef-solo-install/solo.json" +SOLO_RB_URL="https://raw.githubusercontent.com/DoctorOgg/chef-itdrc-snap-it/chef-solo-install/solo.rb" +CHEF_DK_URL="https://packages.chef.io/files/current/chefdk/1.3.10/debian/8/chefdk_1.3.10-1_amd64.deb" +RUN_CHEF_URL="https://raw.githubusercontent.com/DoctorOgg/chef-itdrc-snap-it/chef-solo-install/run-chef.sh" + +URLS=( $BERKS_URL $SOLO_JSON_URL $SOLO_RB_URL $CHEF_DK_URL $RUN_CHEF_URL) +command_exists() { + command -v "$@" > /dev/null 2>&1 +} + +if ! command_exists "curl"; then + echo "Alright, I dont have curl, i'm going to install curl!" + apt-get update + apt-get install -y curl +fi + +if ! command_exists "bc"; then + echo "Alright, I dont have curl, i'm going to install curl!" + apt-get update + apt-get install -y bc +fi + +# Before we continue, are we running debian 8 or above? Simple test, but better than nothing +if [ -e /etc/debian_version ]; then + echo "Looks like we are running a flavor of debian, now to check version." + debian_version=`cat /etc/debian_version` + if ! [ $(echo "$debian_version >= 8" | bc) -eq 1 ]; then + echo "Sorry, your ${debian_version}", is too old! + exit 1 + fi +else + echo "Hi, it looks like /etc/debian_version, does not exist, so i'm guessing we are not running debian." + echo "So i'm going to exit now, before we make more mistakes." + exit 1 +fi + +if [ -d $CHEF_SOLO_DIR ]; then + echo "Directory exists: ${CHEF_SOLO_DIR}" +else + mkdir -v ${CHEF_SOLO_DIR} +fi + +if [ -d "${CHEF_SOLO_DIR}/cookbooks" ]; then + echo "Directory exists: "${CHEF_SOLO_DIR}/cookbooks"" +else + mkdir -v "${CHEF_SOLO_DIR}/cookbooks" +fi + +echo "Ok, lets get the required files." +for i in "${URLS[@]}"; do + file=`echo ${i##*/}` + if ! [ -e "${CHEF_SOLO_DIR}/$file" ]; then + curl "${i}" -o "${CHEF_SOLO_DIR}/$file" + fi +done + +echo "Lets ensure run-chef.sh is execuitable" +run_chef_sh=`echo ${RUN_CHEF_URL##*/}` +( cd $CHEF_SOLO_DIR && chmod +x $run_chef_sh ) + +echo "Installing Chef DK" +deb=`echo ${CHEF_DK_URL##*/}` +dpkg -i "${CHEF_SOLO_DIR}/${deb}" + +echo "Retrieving cookbooks" +(cd $CHEF_SOLO_DIR && berks vendor cookbooks/ ) + +echo "Alright we got the requirements installed, you should now edit solo.json, then run ./run-chef.sh" + +exit 0 diff --git a/chef-solo-install/run-chef.sh b/chef-solo-install/run-chef.sh new file mode 100644 index 0000000..ba0e8a9 --- /dev/null +++ b/chef-solo-install/run-chef.sh @@ -0,0 +1,2 @@ +#!/bin/bash +chef-solo -j solo.json -c solo.rb diff --git a/chef-solo-install/solo.json b/chef-solo-install/solo.json new file mode 100644 index 0000000..b59935c --- /dev/null +++ b/chef-solo-install/solo.json @@ -0,0 +1,30 @@ +{ + "run_list": [ + "recipe[chef-itdrc-snap-it]", + "recipe[chef-itdrc-snap-it::configure-mariadb]" + ], + "itdrc": { + "snap-it": { + "letsencrypt": { + "contact": "mailto:youre@email-address.com", + "self-signed": false + }, + "mysql": { + "root_pw": "g00dluck" + }, + "app_config": { + "app_url": "https://example.com", + "db": { + "password": "g00dluck" + }, + "mail": { + "host": "SETME", + "username": "SETME", + "password": "SETME", + "from_address": "SETME", + "from_name": "ITDRC SNAP-IT" + } + } + } + } +} diff --git a/chef-solo-install/solo.rb b/chef-solo-install/solo.rb new file mode 100644 index 0000000..e3f05b5 --- /dev/null +++ b/chef-solo-install/solo.rb @@ -0,0 +1,2 @@ +file_cache_path Dir.pwd +cookbook_path file_cache_path + "/cookbooks" diff --git a/recipes/configure-mariadb.rb b/recipes/configure-mariadb.rb index 19c9a6a..d69049a 100644 --- a/recipes/configure-mariadb.rb +++ b/recipes/configure-mariadb.rb @@ -2,7 +2,10 @@ uri 'http://downloads.mariadb.com/MariaDB/mariadb-10.1.21/repo/debian/' trusted true components ['main'] + keyserver 'keys.gnupg.net' + key 'CBCB082A1BB943DB' end +# apt-key adv --keyserver keys.gnupg.net --recv CBCB082A1BB943DB package 'mariadb-server' do action :install @@ -19,9 +22,9 @@ code <<-EOF mysql -h #{node["itdrc"]["snap-it"]["app_config"]["db"]["host"]} -u root -e "UPDATE mysql.user SET Password=PASSWORD('#{node["itdrc"]["snap-it"]["mysql"]["root_pw"]}') WHERE User='root'; FLUSH PRIVILEGES;" /etc/init.d/mysql restart - touch /root/.irdc-mariadb-pw-set + touch /etc/mysql/irdc-mariadb-pw-set EOF - not_if do ::File.exists?('/root/.irdc-mariadb-pw-set') end + not_if do ::File.exists?('/etc/mysql/irdc-mariadb-pw-set') end end script 'create db and user' do diff --git a/recipes/configure-webserver.rb b/recipes/configure-webserver.rb index 9912ff4..66f0b18 100644 --- a/recipes/configure-webserver.rb +++ b/recipes/configure-webserver.rb @@ -1,6 +1,6 @@ include_recipe 'acme' -node.set['acme']['contact'] = node["itdrc"]["snap-it"]["letsencrypt"]["contact"] -node.set['acme']['endpoint'] = 'https://acme-v01.api.letsencrypt.org' +node.override['acme']['contact'] = node["itdrc"]["snap-it"]["letsencrypt"]["contact"] +node.override['acme']['endpoint'] = 'https://acme-v01.api.letsencrypt.org' site=URI.parse(node["itdrc"]["snap-it"]["app_config"]["app_url"]).host service 'apache2' do