Snippets to help you writing Serverspec specs in Atom
# Serverspec# Resource Types http://serverspec.org/resource_types.html# http://serverspec.org/resource_types.html#cgroupdescribe 'Linux cgroup resource type' do# cgroup + [TAB]describe cgroup('group1') doits('cpuset.cpus') { should eq 1 }endend# http://serverspec.org/resource_types.html#commanddescribe 'Command resource type' do# command + [TAB]describe command('whoami') do# return_stdout + [TAB]it { should return_stdout 'root' }enddescribe command('ls /foo') do# return_stderr + [TAB]it { should return_stderr 'ls: /foo: No such file or directory' }enddescribe command('ls /tmp') do# return_exit_status + [TAB]it { should return_exit_status '0' }end# command_stdout + [TAB]describe command('ls -al /') doits(:stdout) { should match /bin/ }end# command_stderr + [TAB]describe command('ls /foo') doits(:stderr) { should match /No such file or directory/ }endend# http://serverspec.org/resource_types.html#crondescribe 'Cron resource type' do# cron + [TAB]describe cron doit { should have_entry '* * * * * /usr/bin/foo' }end# cron_with_user + [TAB]describe cron doit { should have_entry('* * * * * /usr/bin/foo').with_user('Tomohiro') }endend# http://serverspec.org/resource_types.html#default_gatewaydescribe 'Default gateway resource type' dodescribe default_gateway doits(:ipaddress) { should eq '192.168.10.1' }its(:interface) { should eq 'br0' }endend# http://serverspec.org/resource_types.html#filedescribe 'File and directory resource type' do# file + [TAB]describe file('/etc/passwd') do# be_file + [TAB]it { should be_file }enddescribe file('/var/log/httpd') do# be_directory + [TAB]it { should be_directory }enddescribe file('/var/run/unicorn.sock') do# be_socket + [TAB]it { should be_socket }enddescribe file('/etc/httpd/conf/httpd.conf') do# content + [TAB]its(:content) { should match /ServerName www.example.com/ }enddescribe file('/etc/sudoers') do# be_mode + [TAB]it { should be_mode 440 }# be_owned_by + [TAB]it { should be_owned_by 'root' }# be_grouped_into + [TAB]it { should be_grouped_into 'wheel' }# be_readable + [TAB]it { should be_readable }# be_readable_by + [TAB]it { should by_readable.by('root') }# be_readable_by_user + [TAB]it { should by_readable.by_user('apache') }enddescribe file('/etc/sudoers') do# be_writable + [TAB]it { should be_writable }# be_writable + [TAB]it { should by_writable.by('root') }# be_writable + [TAB]it { should by_writable.by_user('apache') }enddescribe file('/etc/init.d/httpd') do# be_executable + [TAB]it { should be_executable }# be_executable_by + [TAB]it { should by_executable.by('root') }# be_executable_by_user + [TAB]it { should by_executable.by_user('httpd') }enddescribe file('/') do# be_mounted + [TAB]it { should be_mounted }# be_mounted_with_type + [TAB]it { should be_mounted.with( :type => 'ext4' ) }# be_mounted_with_options + [TAB]it { should be_mounted.with( :options => { :rw => true } ) }# be_mounted_only_with + [TAB]it doshould be_mounted.only_with(:device => '/dev/mapper/VolGroup-lv_root',:type => 'ext4',:options => {:rw => true,:mode => 620})endenddescribe file('C:\\Windows\\System32\\wuapi.dll') do# be_version + [TAB]it { should be_version('7.6.7600.256') }enddescribe file('/etc/services') do# match_md5checksum + [TAB]it { should match_md5checksum '35435ea447c19f0ea5ef971837ab9ced' }# match_sha256checksum + [TAB]it { should match_sha256checksum 'a861c49e9a76d64d0a756e1c9125ae3aa6b88df3f814a51cecffd3e89cce6210' }endend# http://serverspec.org/resource_types.html#groupdescribe 'Group resource type' do# group + [TAB]describe group('root') do# exist + [TAB]it { should exist }# have_gid + [TAB]it { should have_gid 0 }endend# http://serverspec.org/resource_types.html#hostdescribe 'Host resource type' dodescribe host('serverspec.org') do# be_resolvable + [TAB]it { should be_resolvable }# be_resolvable_by_hosts + [TAB]it { should be_resolvable.by('hosts') }# be_resolvable_by_dns + [TAB]it { should be_resolvable.by('dns') }# be_reachable + [TAB]it { should be_reachable }# be_reachable_with + [TAB]it { should be_reachable.with( :port => 22 ) }end# host_address + [TAB]describe host('example.com') doits(:ipaddress) { should eq '1.2.3.4' }endend# http://serverspec.org/resource_types.html#iis_app_pooldescribe 'IIS Application Pool resource type' dodescribe iis_app_pool('Default App Pool') do# have_dotnet_version + [TAB]it { should have_dotnet_version('2.0') }endend# http://serverspec.org/resource_types.html#iis_websitedescribe 'IIS Website resource type' dodescribe iis_website('Default Website') do# exists + [TAB]it { should exist }# be_enabled + [TAB]it { should be_enabled }# be_running + [TAB]it { should be_running }# be_in_app_pool + [TAB]it { should be_in_app_pool('Default App Pool') }# have_physial_path + [TAB]it { have_physial_path('C:\\inetpub\\www') }endend# http://serverspec.org/resource_types.html#interfacedescribe 'Network interface resource type' do# interface + [TAB]describe interface('eth0') do# have_ipv4_address + [TAB]it { should have_ipv4_address('192.168.10.10') }end# interface_speed + [TAB]describe interface('eth0') doits(:speed) { should eq 1000 }endend# http://serverspec.org/resource_types.html#ipfilterdescribe 'Ipfilter resource type' do# ipfilter + [TAB]describe ipfilter doit { should have_rule 'pass in quick on lo0 all' }endend# http://serverspec.org/resource_types.html#ipnatdescribe 'Ipnat resource type' do# ipnat + [TAB]describe ipnat doit { should _have_rule 'map net1 192.168.0.0/24 -> 0.0.0.0/32' }endend# http://serverspec.org/resource_types.html#iptablesdescribe 'Iptables resource type' do# iptables + [TAB]describe iptables doit { should have_rule '-P ACCCEPT' }# have_rule_table_chain + [TAB]it { should have_rule('-P INPUT ACCEPT').with_table('mangle').with_chain('INPUT') }endend# http://serverspec.org/resource_types.html#kernel_moduledescribe 'Kernel module resource type' do# kernel_module + [TAB]describe kernel_module('virtio_balloon') doit { should be_loaded }endend# http://serverspec.org/resource_types.html#linux_kernel_parameterdescribe 'Linux kernel parameter resource type' do# linux_kernel_parameters + [TAB]describe 'Linux kernel parameters' docontext linux_kernel_parameter('net.ipv4.tcp_syncookies') doits(:value) { should eq 1 }endend# linux_kernel_parameter + [TAB]describe linux_kernel_parameter('kernel.osrelease') doits(:value) { should be eq '2.6.32-131.0.15.el6.x86_64' }endend# http://serverspec.org/resource_types.html#lxcdescribe 'LXC(Linux Container) resource type' do# lxc + [TAB]describe lxc('ct01') do# be_running + [TAB]it { should be_running }endend# http://serverspec.org/resource_types.html#mail_aliasdescribe 'Mail alias resource type' do# mail_alias + [TAB]describe mail_alias('daemon') doit { should be_aliased_to 'root' }endend# http://serverspec.org/resource_types.html#packagedescribe 'Package resource type' do# package + [TAB]describe package('httpd') doit { should be_installed }end# package_installed_bydescribe package('jekyll') doit { should be_installed.by('gem').with_version('0.12.1') }endend# http://serverspec.org/resource_types.html#php_configdescribe 'PHP config resource type' do# php_config_parameters + [TAB]describe 'PHP config prameters' docontext php_config('default_mimetype') doits(:value) { should eq 'text/html'}endend# php_config + [TAB]describe php_config('session.cache_expire') doits(:value) { should eq '180' }endend# http://serverspec.org/resource_types.html#portdescribe 'Port resource type' do# port + [TAB]describe port(80) do# be_listening + [TAB]it { should be_listening }# be_listening_with + [TAB]it { should be_listening.with('tcp') }endend# http://serverspec.org/resource_types.html#ppadescribe 'PPA resource type' do# ppa + [TAB]describe ppa('launchpad-username/ppa-name') do# exists + [TAB]it { should exist }endend# http://serverspec.org/resource_types.html#processdescribe 'Process resource type' do# process + [TAB]describe process('memchached') do# be_running + [TAB]it { should be_running }end# process_parameter + [TAB]describe process('memcached') doits(:args) { should match /-c 32000\b/ }endend# http://serverspec.org/resource_types.html#routing_tabledescribe 'Routing table resource type' do# routing_table + [TAB]describe routing_table doit doshould have_entry(:destination => '192.168.100.0/24',:interface => 'eth1',:gateway => '192.168.10.1')endendend# http://serverspec.org/resource_types.html#selinuxdescribe 'SELinux resource type' do# selinux + [TAB]describe selinux do# be_disabled + [TAB]it { should be_disabled }# be_enforcing + [TAB]it { should be_enforcing }# be_permissive + [TAB]it { should be_permissive }endend# http://serverspec.org/resource_types.html#servicedescribe 'Service resource type' do# service + [TAB]describe service('ntpd') do# be_enabled + [TAB]it { should be_enabled }# be_enabled_with_level + [TAB]it { should be_enabled.with_level(3) }# be_running + [TAB]it { should be_running }# be_monitored_by + [TAB]it { should be_monitored_by('monit') }end# be_running_under_supervisor + [TAB]describe service('ntpd') doit { should be_running.under('supervisor') }enddescribe service('DNS Client') do# be_installed + [TAB] (Only supported in Windows)it { should be_installed }# have_start_mode + [TAB] (Only supported in Windows)it { should have_start_mode('Manual') }endend# http://serverspec.org/resource_types.html#userdescribe 'User resource type' do# user + [TAB]describe user('root') do# exists + [TAB]it { should exist }# belong_to_group + [TAB]it { should belong_to_group 'root' }# have_uid + [TAB]it { should have_uid 0 }# have_home_directory + [TAB]it { should have_home_directory '/root' }# have_login_shellit { should have_login_shell '/bin/bash' }# have_authorized_keyit { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' }endend# http://serverspec.org/resource_types.html#windows_featuredescribe 'Windows Feature resource type' do# windows_feature + [TAB]describe windows_feature('Minesweeper') doit { be_installed }enddescribe windows_feature('Web-Webserver') do# be_installed_by + [TAB]it { should be_installed.by('powershell') }endend# http://serverspec.org/resource_types.html#windows_registry_keydescribe 'Windows Registry Key resource type' do# windows_registry_key + [TAB]describe windows_registry_key('HKEY_USERS\S-1-5-21\Test MyKey') do# exists + [TAB]it { should exist }# have_property + [TAB]it { should have_property('string value') }# have_property_type + [TAB]it { should have_property('binary value', :type_binary) }# have_value + [TAB]it { should have_value('test default data') }# have_property_value + [TAB]it { should have_property_value('binary value', :type_binary, 'dfa0f066') }endend# http://serverspec.org/resource_types.html#yumrepodescribe 'Yumrepo resource type' do# yumrepo + [TAB]describe yumrepo('epel') do# exists + [TAB]it { should exist }# be_enabled + [TAB]it { should be_enabled }endend# http://serverspec.org/resource_types.html#zfsdescribe 'ZFS resource type' do# zfs + [TAB]describe zfs('rpool') do# exists + [TAB]it { should exist }# zfs_have_property + [TAB]it { should have_property 'mountpoint' => '/rpool', 'compression' => 'off' }endend
© 2014 - 2016 Tomohiro TAIRA.
This project is licensed under the MIT license. See LICENSE for details.
Good catch. Let us know what about this package looks wrong to you, and we'll investigate right away.