by
Joaquín Menchaca
SENIOR DEVOPS BUILD/RELEASE ENGINEER
aka
Linux Ninja Pants Automation Engineering Mutant
actual photo
git clone \
https://github.com/darkn3rd/lisa18_test_driven_infra
cd lisa18_test_driven_infra
# Using Virtual Workstation
vagrant up
vagrant ssh
cd lisa18_test_driven_infra
# Using Host (MacOS X or Linux)
#### Install Requirements
# Using Host (Windows)
#### Install Rrequiremnts
#### Warning: Might not work, had success w/ Chef
must be able to run
Docker
or
Vagrant
ChefDK - bundles ruby, test kitchen, inspec
Docker - fastest way to run stuff (virtual virtual machines)
Easiest Path is Docker Desktop
choco install docker-for-windows
brew cask install docker
https://chocolatey.org/
https://brew.sh/
https://www.docker.com/products/docker-desktop
sudo apt-get update -qq
sudo apt-get install -y apt-transport-https \
curl ca-certificates software-properties-common
DOCKER_REPO="https://download.docker.com/linux/ubuntu"
curl -fsSL ${DOCKER_REPO}/gpg | \
sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] ${DOCKER_REPO} \
$(lsb_release -cs) \
stable"
sudo apt-get update -qq
sudo apt-get install -y docker-ce
sudo usermod -aG docker $USER
Debian Package on Ubuntu
Easiest Way to Get Test Kitchen and InSpec
choco install chefdk
chef gem install kitchen-ansible
chef gem install kitchen-docker
brew tap chef/chef
brew cask install chefdk
chef gem install kitchen-ansible
chef gem install kitchen-docker
https://chocolatey.org/
https://brew.sh/
https://downloads.chef.io/chefdk/
VER=3.2.30
PKG=chefdk_${VER}-1_amd64.deb
PREFIX=https://packages.chef.io/files/stable/chefdk/
# Fetch and Install
wget --quiet ${PREFIX}/${VER}/ubuntu/16.04/${PKG}
sudo dpkg -i ${PKG}
# Local ChefDK Ruby Gems
chef gem install kitchen-ansible
chef gem install kitchen-docker
Debian Package on Ubuntu
Destroy and Recreate with Ease
Because Tests…
Create (Vagrant)→Converge(Chef)→Verify(InSpec)
---
driver:
name: vagrant
provider: hyperv
provisioner:
name: chef_zero
verifier:
name: inspec
platforms:
- name: ubuntu-16.04
suites:
- name: default
Create (Docker)→Converge(Ansible)→Verify(InSpec)
---
driver:
name: docker
provisioner:
name: ansible_playbook
verifier:
name: inspec
platforms:
- name: ubuntu-16.04
suites:
- name: default
control 'ez_apache-contract-01' do
describe port(80) do
it { should be_listening }
end
end
control 'ez_mysql-security-conf-01' do
describe file(mysql_data_path) do
it { should be_directory }
it { should be_owned_by 'mysql' }
it { should be_grouped_into 'mysql' }
end
end
package 'apache2'
service 'apache2' do
action %i(enable start)
supports(
status: true,
restart: true,
reload: true
)
end
cookbook_file "#{node['docroot']}/index.html" do
source 'index.html'
action :create
end
- name: "Install Web Service"
package:
name: apache2
state: present
- name: "Start Web Service"
service:
name: apache2
state: started
enabled: yes
- name: "Copy Content"
copy:
src: "{{ role_path }}/files/index.html"
dest: "{{ docroot }}/index.html"
./chef/cookbooks/ez_mysql
├── attributes
│ └── default.rb
├── Berksfile
├── kitchen.docker.yml
├── kitchen.hyperv.yml
├── kitchen.vbox.yml
├── metadata.rb
├── README.md
├── recipes
│ ├── client.rb
│ ├── database.rb
│ ├── default.rb
│ ├── harden.rb
│ ├── install.rb
│ └── service.rb
├── templates
│ └── security.cnf.erb
└── test -> ../../../inspec/ez_mysql/test
./inspec/ez_mysql
└── test
└── integration
└── default
├── ansible.cfg
├── conform_test.rb
├── contract_test.rb
├── default.yml
└── security_test.rb
Shared Test for ANY change configuration, e.g.
CAPS (Chef, Ansible, Puppet, Salt Stack), or other automation
# Setup (tell kitchen to use docker)
export KITCHEN_YAML=kitchen.docker.yml
# Create Environment
kitchen create
# (optional) Login into environment
kitchen login
# Converge to Desired State
kitchen converge
# Verify Environment
kitchen verify
include_recipe 'ez_mysql::install'
include_recipe 'ez_mysql::service'
# include_recipe 'ez_mysql::database'
include_recipe 'ez_mysql::harden'
include_recipe 'ez_mysql::install'
include_recipe 'ez_mysql::service'
include_recipe 'ez_mysql::database'
include_recipe 'ez_mysql::harden'
./ansible/roles/ez_mysql
├── defaults
│ └── main.yml
├── handlers
│ └── main.yml
├── kitchen.docker.yml
├── kitchen.hyperv.yml
├── kitchen.vbox.yml
├── meta
│ └── main.yml
├── tasks
│ ├── client.yml
│ ├── database.yml
│ ├── harden.yml
│ ├── install.yml
│ ├── main.yml
│ └── service.yml
├── templates
│ └── security.cnf.j2
└─── test -> ../../../inspec/ez_mysql/test
./inspec/ez_mysql
└── test
└── integration
└── default
├── ansible.cfg
├── conform_test.rb
├── contract_test.rb
├── default.yml
└── security_test.rb
Shared Test for ANY change configuration, e.g.
CAPS (Chef, Ansible, Puppet, Salt Stack), or other automation
# Setup (tell kitchen to use docker)
export KITCHEN_YAML=kitchen.docker.yml
# Create Environment
kitchen create
# (optional) Login into environment
kitchen login
# Converge to Desired State
kitchen converge
# Verify Environment
kitchen verify
- include: install.yml
- include: config.yml
- include: service.yml
# - include: harden.yml
- include: install.yml
- include: config.yml
- include: service.yml
- include: harden.yml
(secret)
(for reference)
☑ Mac/Vagrant (Virtualbox) / TestKitchen (Docker) / Chef
☑ Mac/Vagrant (Virtualbox)/ TestKitchen (Docker) / Ansible
☑ Win/Vagrant (HyperV) / TestKitchen (Docker) / Chef
☐ Win/Vagrant (HyperV)/ TestKitchen (Docker) / Ansible
☑ TestKitchen (HyperV) / Chef
☒ TestKitchen (HyperV) / Ansible
☐ TestKitchen (Docker) / Chef
☐ TestKitchen (Docker) / Ansible
☑ TestKitchen (Virtualbox) / Chef
☑ TestKitchen (Virtualbox) / Ansible
☑ TestKitchen (Docker) / Chef
☑ TestKitchen (Docker) / Ansible