LEVEL DEVil
Developer. IBMer. Vi(m) lover. DevOps kid. Runner. Performing cloud infrastructure and application architecture with passion for the edge thing.
Reach me on Twitter as @epcim
Background | Practice | Expectations
Morning | Intro DevOps intro (J.Svoboda) DevOps kung-fu (P.Michalec) |
Review day 1 InSpec, Compliance tests Chef Lab II. |
Chef intro Prerequisites / Lab 0. |
Chef workflow, CI/CD Chef Lab III. |
|
Afternoon | Cookbook development Chef Lab I. |
Chef Delivery, Analytics Chef Lab IV. |
TDD, Advanced practices Chef Lab II. |
Experiments ... |
T | Day 1 | Day 2 |
---|
Buzzword
You can't buy/hire/adopt it
DevOps is an enterprise capability for continuous software delivery that enables clients to seize market opportunities and reduce time to customer feedback
Pick #1
A cultural and professional movement, focused on how we build and operate high velocity organizations, born from the experiences of its practitioners.
Pick #2
The principles that all of the DevOps patterns can be derived from
Gee Kim, Co-Author of: “The Phoenix Project: A Novel About IT, DevOps, and Helping Your Business Win.”
Pick #3
Buzzwords
Links and presenatation in workshop materials.
Jan Svoboda
(~ 5 min)
From traditional IT to microservices
API loosely coupled architectures and micro services
Technology shift on frontends
Design for speed and simplicity
Cross platform requirements (Go, mobile platforms)
Measure for feedback, data analytics, visualization
Stream data
Dynamic configuration
Deploy and operate all infrastructures by code, as applications are code too.
As traditional IT becomes "truck" and cloud native is a "car". Practice DevOps and apply cloud architectures to acquire expertise, tools and operational skills to drive.
(~ 5 min)
Orchestration
Infrastructure as code
OS/Application configuration
w/Agent
Platforms supproted
Language
DSL
Encryption
Config store
ACL
Frequency
Chef | Puppet | Ansible | SaltStack | uDeploy| GRTE | CloudFactory | Lotus Automator | . . .
Whether it's agent less (Ansible) or need an agent at endpoint (Chef, puppet)
The level of abstraction Fabric vs. Chef|Salt|Puppet
Whether the aim is to install or install & maintain
Level of customized / automated configuration you need to apply vs. how advanced and complex are available community resources (cookbooks etc)
Integration to in house tools (CI,...)
Platforms and environments involved
Configure vs. deploy
Backup slides
Traditional IT
IaaS - OpenStack
IBM Cloud Orchestrator, RedHat CloudForms, HP Helion, ...
PaaS - Cloud Foundry
Heroku, IBM Bluemix
Heat patterns, IBM PureApps
Backup slide
This means that Chef can:
Chef is a configuration management
and automation platform
chef-provisioning
recipes
knife-softlayer
knife-ec2
knife-google
Chef Development Kit (ChefDK)
$ chef generate app cookbook_name
$ chef generate attribute
$ chef generate recipe
$ chef generate lwrp
$ chef-apply name_of_recipe.rb
include_recipe 'apache2'
user 'userdoc' do
supports manage_home: true
comment 'userdoc (bind user)'
gid 'users'
home '/home/userdoc'
password '$1$9p26dAeZ$qZ7P4XW.ASDG4DSD3234vK0'
end
directory '/var/www/userdoc' do
mode 00775
owner 'apache2'
group 'users'
recursive true
end
web_app 'userdoc' do
server_name "udoc.#{node['domain']}"
server_aliases ["userdoc.#{node['system']['domain_name']}"
docroot '/var/www/userdoc'
cookbook 'apache2'
directory_options 'Indexes FollowSymLinks'
end
cookbooks, recipes
cookbook
|
├── .kitchen.yml
├── Berksfile
├── metadata.rb
├── attributes
│ └── default.rb
├── recipes
│ └── default.rb
└── templates
└── default
└── index.html.erb
# metadata.md
name 'gitzone'
maintainer 'Petr Michalec'
maintainer_email 'epcim@apealive.net'
license 'Apache 2.0'
description 'Installs/Configures gitzone managed zone files for Bind'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '1.0.15'
recipe 'gitzone::default', 'Install and fully configure gitzone using the install and configure recipes'
recipe 'gitzone::install', 'Install gitzone scripts'
recipe 'gitzone::configure', 'Configure gitzone (including BIND and default zones)'
recipe 'gitzone::configure_zonefile', 'Deploy zone files'
supports 'ubuntu'
supports 'centos'
depends 'bind'
depends 'git'
depends 'sudo'
depends 'system'
depends 'build-essential'
depends 'simple_iptables'
chef supermarket
$ knife search node "platform:centos AND languages_ruby_version:1.8*"
$ knife search node "chef_environment:production AND platform:ubuntu"
$ knife ssh 'name:* AND NOT name:chef*' 'sudo postmap -p /etc/postfix/transport'
$ knife bootstrap --environment dev --node-name catalog.lab.dev 10.10.50.15 \
--ssh-password passw0rd --run-list "role[base]" --server-url "https://10.10.50.2" \
--json-attributes '{ "hostname": "catalog","name": "catalog.lab.dev", \
"system":{ "short_hostname":"catalog", "domain_name":"lab.dev" } }' \
--secret-file .chef/encrypted_data_bag_secret
$ knife node run_list add ora.kb.dev "role[git], recipe[backup::gitlab]"
$ knife role from file roles/*.rb
$ knife environment from file staging.rb
knife
** KNIFE COMMANDS **
bootstrap, client, configure, cookbook, cookbook site, data bag, delete, deps,
diff, download, edit, environment, exec, list, node, raw, recipe_list, role,
search, serve, show, ssh, ssl check, ssl fetch, status, tag, upload, user
** NODE COMMANDS **
knife node bulk delete REGEX (options)
knife node create NODE (options)
knife node delete NODE (options)
knife node edit NODE (options)
knife node environment set NODE ENVIRONMENT
knife node from file FILE (options)
knife node list (options)
knife node run_list add [NODE] [ENTRY[,ENTRY]] (options)
knife node run_list remove [NODE] [ENTRY[,ENTRY]] (options)
knife node run_list set NODE ENTRIES (options)
knife node show NODE (options)
** SOFTLAYER COMMANDS **
knife softlayer datacenter list (options)
knife softlayer datacenter show DATACENTER
knife softlayer flavor list (options)
knife softlayer global ip list (options)
knife softlayer image list
knife softlayer key pair create
knife softlayer key pair list
knife softlayer server create (options)
knife softlayer server destroy (options)
knife softlayer server list (options)
knife softlayer server relaunch <NODE NAME> [<NODE NAME>]
knife softlayer vlan create
knife softlayer vlan list (options)
knife softlayer vlan show ID (options)
knife plugins
require 'chef/provisioning'
with_driver 'fog:OpenStack'
...
# PRE ALLOCATE
machine_batch do
%w(chef web repo ci).each do |m|
machine "#{m}.lab.ci" do
action :allocate
add_machine_options bootstrap_options: PER_MACHINE_BOOTSTRAP_OPTIONS[m] || {}
retries 1
end
end
end
# BOOTSTRAP/CONVERGE NODE
machine 'chef.lab.ci' do
ohai_hints 'openstack' => '{}'
attribute %w(apt compile_time_update), true
attribute %w(resolver nameservers), search(:node, 'role:dns').map \
{ |x| x.automatic.ipaddress } unless search(:node, 'role:dns').empty?
recipe 'lab_base::default'
role 'chef'
add_machine_options bootstrap_options: PER_MACHINE_BOOTSTRAP_OPTIONS['chef'] || {}
files('/etc/chef/encrypted_data_bag_secret' => "#{dtbgsec}")
action [:ready, :converge]
converge true
end
Chef-Zero
Simple, easy-run, fast-start in-memory Chef server for testing and solo purposes
chef-provisioning, chef-zero
Chef-Provisioning
A collection of resources that enable the creation of machines and machine infrastructures using the chef-client.
Analytics & audits
# in audit recipe
control_group 'ssh' do
control 'password authentication' do
it 'is disabled' do
expect(file('/etc/ssh/sshd_config')).to_not \
match(/^PasswordAuthentication\s+yes/i)
end
end
end
# in analytics rule
rules 'failed-audit'
rule on run_control_group
when
status != 'success'
then
notify('slack', "{
'username': 'Audit Alarm', 'text': "{{message.name}} (cookbook {{message.cookbook_name}})\n
had '{{message.number_failed}}' failed audit test(s) on node '{{message.run.node_name}}'"
}")
end
end
Backup slides
(~ 5 min)
PartA, develpop cookbooks/repo/recipes
PartB - execute serverspec/inspec audit
(as needed)
Continuous Integration test Continuous Deployment cycle
---
# https://docs.chef.io/config_yml_kitchen.html
driver:
name: vagrant
use_sudo: false
provisioner:
name: chef_zero
cookbook_path: ['.','cookbooks', 'test/cookbooks']
platforms:
- name: centos-7.1
run_list:
- recipe[selinux::disabled]
- name: ubuntu-14.04
suites:
- name: default
run_list:
- recipe[lab_base]
- recipe[lab_gitlab::db]
- recipe[lab_gitlab::default]
attributes:
apt:
compile_time_update: true
mysql:
server_root_password: test
gitlab:
database:
host: 127.0.0.1
password: test
# vim: sw=2 ts=2 sts=2
$ cd <cookbook>
$ tree
/test
├── chef
│ ├── data_bags
│ │ └── users
│ | └── testuser.json
│ └── encrypted_data_bag_secret
└── integration
├── default
│ ├── serverspec
│ │ └── default_spec.rb
│ └── ssh_spec.rb
└── helpers
└── serverspec
└── spec_helper.rb
8 directories, 4 files
# Serverspec
$ cat default/serverspec/default_spec.rb
require 'spec_helper'
describe 'base-linux::default' do
# Serverspec examples can be found at
# http://serverspec.org/resource_types.html
describe port(80) do
it { should be_listening }
end
describe command('curl http://localhost') do
its(:stdout) { should match /Hello, world!/ }
end
describe file('/etc/services') do
its(:selinux_label) { should eq 'system_u:object_r:etc_t:s0' }
end
describe host('serverspec.org') do
it { should be_resolvable.by('dns') }
end
end
# InSpec
$ cat test/integration/default/ssh_spec.rb
only_if do
command('sshd').exist?
end
describe service('ssh') do
it { should be_enabled }
it { should be_running }
end
control 'sshd-11' do
impact 1.0
title 'Server: Set protocol version to SSHv2'
desc 'Set the SSH protocol version to 2'
describe sshd_config do
its('Protocol') { should eq('2') }
end
end
control 'sshd-7' do
impact 1.0
title 'Server: Do not permit root-based login with password.'
desc "To reduce the potential to gain full privileges, do not allow login as root with password"
describe sshd_config do
its('PermitRootLogin') { should match(/no|without-password/) }
end
end
Test cookbook recipes and provided metadata
$ cd <cookbook>
$ tree
/spec
├── spec_helper.rb
└── unit
└── recipes
├── default_spec.rb
├── sysctl_spec.rb
└── users_spec.rb
2 directories, 4 files
require 'chefspec'
describe 'cookbook_name::install' do
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
it 'creates a template with attributes' do
expect(chef_run).to create_template('/tmp/with_attributes').with(
user: 'user',
group: 'group',
backup: false,
)
end
it 'includes resource that have guards that evalute to true' do
expect(chef_run).to start_service('true_guard')
end
it 'includes the `other` recipe' do
expect(chef_run).to include_recipe('include_recipe::other')
end
it 'removes a package with an explicit action' do
expect(chef_run).to remove_package('explicit_action')
end
end
# Cookbook Name:: base-linux
# Spec:: default
#
# Copyright (c) 2016 The Authors, All Rights Reserved.
require 'spec_helper'
describe 'base-linux::default' do
context 'When all attributes are default, on an unspecified platform' do
before do
stub_command('which sudo').and_return('/usr/bin/sudo')
end
let(:chef_run) do
runner = ChefSpec::ServerRunner.new
runner.node.set['virtualization']['system'] = 'vmware'
runner.converge(described_recipe)
end
it 'converges successfully' do
expect { chef_run }.to_not raise_error
end
end
end
PartA, develpop cookbooks/repo/recipes
PartB - execute serverspec/inspec audit
(~ 5 min)
check WLP at https://github.com/WASdev/ci.chef.wlp
wlp_server "myInstance" do
config ({
"featureManager" => {
"feature" => [ "jsp-2.2", "jaxws-2.1" ]
},
"httpEndpoint" => {
"id" => "defaultHttpEndpoint",
"host" => "*",
"httpPort" => "9080",
"httpsPort" => "9443"
},
"application" => {
"id" => "example",
"name" => "example",
"type" => "war",
"location" => "/apps/example.war"
}
})
jvmOptions [ "-Djava.net.ipv4=true" ]
serverEnv "JAVA_HOME" => "/usr/lib/j2sdk1.7-ibm/"
bootstrapProperties "default.http.port" => "9080", "default.https.port" => "9443"
action :create
end
wlp_download_feature "mongodb" do
name "mongodb-2.0"
directory "/opt/ibm/wlp/features"
accept_license true
end
ci.chef.wlp
Chef cookbook for installing and managing WebSphere Application Server Liberty Profile #devops
Updated 21 days ago
ci.chef.iim
Chef Cookbook to install, configure and run IBM Installation Manager
Updated on Nov 3, 2015
ci.chef.ihs
Chef cookbook for installing and managing IBM HTTP Server #devops
Updated on Jun 18, 2015
ci.chef.wxs
Chef Cookbook to install and configure WebSphere eXtreme Scale
Updated on Sep 12, 2014
ci.chef.was
Chef cookbook for installing and managing WebSphere Application Server with wsadmin #devops
Updated on Sep 12, 2014
ci.chef.ihs.config
Chef cookbook for configuring IHS WebSphere Plugin
Updated on Sep 12, 2014
ci.chef.wlp.application
Chef cookbook for deploying applications to the WebSphere Application Server Liberty Profile #devops
Updated on Sep 12, 2014
ci.chef.wlp.samples
# cd <repo>/cookbooks/base-linux
# cat spec/spec_helper.rb
require 'chefspec'
require 'chefspec/berkshelf'
RSpec.configure do |config|
# Specify the Chef log_level (default: :warn)
config.log_level = :debug
end
# rspec spec |wc -l
348945
System cookbook in place, still passing UNIT tests
# chef exec chef -v
Chef Development Kit Version: 0.10.0
chef-client version: 12.6.0
berks version: 4.0.1
kitchen version: 1.5.0
# berks
Resolving cookbook dependencies...
Fetching 'base-linux' from source at .
Using apparmor (2.0.1)
Using apt (3.0.0)
Using base-linux (0.1.0) from source at .
Using chef-sugar (3.3.0)
Using chef_handler (1.3.0)
Using compat_resource (12.7.3)
Using cron (1.7.5)
Using firewall (2.4.0)
Using hostsfile (2.4.5)
Using motd (0.6.3)
Using ntp (1.10.1)
Using ohai (2.1.0)
Using selinux (0.9.0)
Using sudo (2.9.0)
Using sysctl (0.7.0) from https://github.com/svanzoest-cookbooks/sysctl (at master)
Using system (0.10.1)
Using users (2.0.3)
Using windows (1.39.2)
Using yum (3.10.0)
Using yum-epel (0.6.6)
everybody else
hard way, dont't fork, merge with me
what else
whate about to check commits history at my repo
Fix Lab I/II.
(last today, ask for it when needed)
rake berks # Berks install/update/vendor
rake bootstrap:chefonly # Boostrap CHEF ONLY with SSH
rake bootstrap:ci # Boostrap CI against OpenStack env
rake bootstrap:gtshub # Boostrap gtshub using SSH
rake bootstrap:setup # Bootstrap local cfg for chef-provisioning setup
rake bootstrap:test # Boostrap TEST against OpenStack env
rake bootstrap:vagrant # Bootstrap Vagrant env
rake chef:hosts # Create a hosts.yml file based on knife information
rake chef:hosts_local # Create a hosts.yml file based on local ChefZero information
rake chef:nodes_local # Print ip + fqdn from nodes records
rake convert # Convert ruby classes to json
rake convert:env_to_json # Convert ruby environments from ruby to json, creating/overwriting json files
rake convert:metadata_to_json # Convert all metadata from ruby to json
rake convert:role_to_json # Convert ruby roles from ruby to json, creating/overwriting json files
rake destroy:ci # Destroy CI environment
rake dev:bootstrap # Run task bootstrap:ci in local DEV environment
rake dev:cls # Clean up local chef-zero instances
rake dev:setup # Setup local development ENV variables
rake foodcritic # Foodcritic
rake knife:bootstrap # Bootstrap new node using knife
rake lint # Lint & syntax checks
rake provision:chefonly # Provision CHEF server with SSH
rake provision:ci # Provision CI environment against Openstack
rake provision:gtshub # Provision gtshub environment with SSH
rake provision:test # Provision TEST environment with Openstack
rake rubocop # Run RuboCop style and lint checks
rake rubocop:auto_correct # Auto-correct RuboCop offenses
rake spec # Run serverspec to all hosts
rake vagrant:create # Create the Vagrant machine
rake vagrant:destroy # Stop and delete the Vagrant machine
rake vagrant:login # Log into the Vagrant machine via SSH
rake vagrant:provision # Provision the Vagrant machine with Chef
Run chef-client at remote node with chef-zero(local-mode) via HTTP over SSH port fowarding.
Amazon Web Services | A Chef provisioning driver for Amazon Web Services (AWS). |
Docker | A Chef provisioning driver for Docker. |
Fog | A Chef provisioning driver for Fog. |
Hanlon | A Chef provisioning driver for Hanlon. |
LXC | A Chef provisioning driver for LXC. |
Microsoft Azure | A Chef provisioning driver for Microsoft Azure. |
OpenNebula | A Chef provisioning driver for OpenNebula. |
SSH | A Chef provisioning driver for SSH. |
Vagrant | A Chef provisioning driver for Vagrant. |
vSphere | A Chef provisioning driver for VMware vSphere. |
machine 'server_a' do
recipe 'base_recipes'
end
machine 'server_b' do
recipe 'base_recipes'
recipe 'theserver'
end
machine_batch do
machine 'db' do
recipe 'mysql'
end
1.upto(50) do |i|
machine "#{web}#{i}" do
recipe 'apache'
end
end
end
Developers check out code into their private workspaces. When done, the commit changes to the repository.
The CI server monitors the repository, checks out on changes.
The CI server builds the system and runs unit and integration tests.
The CI server releases deployable artefacts for testing.
The CI server assigns a build label to the version of the code it just built.
The CI server informs the team of the successful build.
If the build or tests fail, the CI server alerts the team.
The team fix the issue at the earliest opportunity.
Continue to continually integrate and test throughout the project.
Team Responsibilities
App A
App C
App B
ENTERPR
I
SE
cache:
mount:
- .berkshelf/cookbooks
env:
- CI=drone
- LABREPO=https://git.vums.blueit/chef-cookbooks
build:
image: epcim/drone-chef-ci
commands:
# RUN TESTS
# Rspec
- chef exec rspec spec
# Kitchen soap
- KITCHEN_LOCAL_YAML=.kitchen.cloud.yml chef exec kitchen test || E=$?; test -n $E && /bin/sleep 300 #--concurrency 2
- KITCHEN_LOCAL_YAML=.kitchen.cloud.yml chef exec kitchen destroy
# Exit on fail
- test ${E:-0} -ne 0 && exit $E
# RUN LINT CHECKERS
- chef exec foodcritic "-f any -f ~FC014 -f ~FC015 -f ~FC024 -f ~FC043" .
- chef exec rubocop -a || chef exec rubocop . #|| echo "ignoring failed rubocop check"
# TAG SUCCESSFUL VERSION
- VERSION=`ruby -r 'chef/cookbook/metadata' -e "m=Chef::Cookbook::Metadata.new;m.from_file('metadata.rb');puts m.version"`
- git config remote.origin.url `git config --get remote.origin.url | sed "s/https:\/\//https:\/\/$GIT_USERNAME:$GIT_PASSWORD@/"`
- git tag -a v${VERSION} -m 'CI tagged successful build'
- git push origin v${VERSION} 2> /dev/null || echo $?
notify:
slack:
webhook_url: 'https:#hooks.slack.com/services/T0SDDASD43/BSDFD84QY/buISDF436dsfjsdlEoo57qO'
username: 'drone.io'
channel: '#lab-cookboks'
on_started: false
on_success: true
on_failure: false
cache:
mount:
- .berkshelf/cookbooks
clone:
skip_verify: true
environment:
- DRONE_GITLAB_SKIP_VERIFY=true
- GIT_CURL_VERBOSE=1
- GIT_SSL_NO_VERIFY=1
env:
- CI=drone
- LABREPO=https://git.vums.blueit/chef-cookbooks
build:
image: epcim/drone-chef-ci
privileged: true
environment:
- OS_USERNAME=$$OS_USERNAME
- OS_PASSWORD=$$OS_PASSWORD
- OS_TENANT_NAME=$$OS_TENANT_NAME
- OS_AUTH_URL=$$OS_AUTH_URL
- BOOTSTRAP_SSH_KEY=$$BOOTSTRAP_SSH_KEY
- BOOTSTRAP_SSH_PUB=$$BOOTSTRAP_SSH_PUB
- GIT_USERNAME=$$GIT_USERNAME
- GIT_PASSWORD=$$GIT_PASSWORD
- GIT_COMMITTER_NAME=$$GIT_COMMITTER_NAME
- GIT_COMMITTER_EMAIL=$$GIT_COMMITTER_EMAIL
commands:
### INITIALIZE CI ENV ###
- . /root/.bash_profile
- eval "$(chef shell-init sh)"
- export LANG="en_US.UTF-8"
- export SSL_CERT_FILE=/opt/chefdk/embedded/ssl/certs/cacert.pem
- chef exec berks install
### INITIALIZE REMOTE CI ENV ###
- BOOTSTRAP_KEYFILE=/root/.ssh/bootstrap_insecure
- echo "$BOOTSTRAP_SSH_KEY" > $BOOTSTRAP_KEYFILE; chmod 0600 $BOOTSTRAP_KEYFILE
- eval `ssh-agent`
- ssh-add $BOOTSTRAP_KEYFILE
- ssh-add ./id_rsa_bootstrap_insecure
#- chef exec bundle install
- chef gem install kitchen-openstack
# RUN TESTS
# Rspec
- chef exec rspec spec
# Kitchen soap
- KITCHEN_LOCAL_YAML=.kitchen.cloud.yml chef exec kitchen test || E=$?; test -n $E && /bin/sleep 300 #--concurrency 2
- KITCHEN_LOCAL_YAML=.kitchen.cloud.yml chef exec kitchen destroy
# Exit on fail
- test ${E:-0} -ne 0 && exit $E
# RUN LINT CHECKERS
- chef exec foodcritic "-f any -f ~FC014 -f ~FC015 -f ~FC024 -f ~FC043" .
- chef exec rubocop -a || chef exec rubocop . #|| echo "ignoring failed rubocop check"
# TAG SUCCESSFUL VERSION
- VERSION=`ruby -r 'chef/cookbook/metadata' -e "m=Chef::Cookbook::Metadata.new;m.from_file('metadata.rb');puts m.version"`
- git config remote.origin.url `git config --get remote.origin.url | sed "s/https:\/\//https:\/\/$GIT_USERNAME:$GIT_PASSWORD@/"`
- git tag -a v${VERSION} -m 'CI tagged successful build'
- git push origin v${VERSION} 2> /dev/null || echo $?
notify:
slack:
webhook_url: 'https:#hooks.slack.com/services/T0SDDASD43/BSDFD84QY/buISDF436dsfjsdlEoo57qO'
username: 'drone.io'
channel: '#lab-cookboks'
on_started: false
on_success: true
on_failure: false
image: epcim/drone-chef-ci:dind
env:
- CI=drone
- LABREPO=https://gitlab.lab.local/chef-cookbooks
script:
- source /root/.bash_profile
- eval "$(chef shell-init bash)"
- export LANG="en_US.UTF-8"
- export SSL_CERT_FILE=/opt/chefdk/embedded/ssl/certs/cacert.pem
- chef exec berks install
- chef gem install chef-rewind
- wrapdocker
- chef exec rspec spec
- chef exec kitchen test
- chef exec foodcritic "-f any -f ~FC014 -f ~FC015 -f ~FC024 -f ~FC043" .
- chef exec rubocop -a || chef exec rubocop .
notify:
slack:
webhook_url: 'https:#hooks.slack.com/services/T0SDDASD43/BSDFD84QY/buISDF436dsfjsdlEoo57qO'
username: 'drone.io'
channel: '#lab-cookboks'
on_started: false
on_success: true
on_failure: false
# it's just a "serverspec"...
control_group 'SSH Service compliance' do
control 'ssh service' do
it 'should be listening on port 22' do
expect(port(22)).to be_listening
end
end
control 'ssh configuration' do
it 'ssh disables root logins' do
expect(file('/etc/ssh/sshd_config')).to contain('PermitRootLogin no')
end
it 'is disabled' do
expect(file('/etc/ssh/sshd_config')).to_not \
match(/^PasswordAuthentication\s+yes/i)
end
end
end
# use basic tests
describe package('nginx') do
it { should be_installed }
end
# extend tests with metadata
control '01' do
impact 0.7
title 'Verify nginx service'
desc 'Ensures nginx service is up and running'
describe service('nginx') do
it { should be_enabled }
it { should be_installed }
it { should be_running }
end
end
# implement os dependent tests
web_user = 'www-data'
web_user = 'nginx' if os[:family] == 'centos'
describe user(web_user) do
it { should exist }
Behind the scene is actually a cookbook