With Serverspec, you can write RSpec tests for checking your servers are configured correctly.
$ gem search serverspec or $ gem search --remote serverspec or $ gem search serverspec -p http://192.168.0.10:9999
$ gem install serverspec -p http://192.168.0.10:9999
$ gem search rake or $ gem search --remote rake or $ gem search --remote rake -p http://192.168.0.10:9999
$ gem install rake or $ gem install --remote rake or $ gem install --remote rake -p http://192.168.0.10:9999
$ ssh-keygen -t rsa -C "test" $ ls id_rsa id_rsa.pub
“SUDO_PASSWORD = xxxxx ” or “ASK_SUDO_PASSWORD = 1”
user01 ALL=(ALL) ALL
user01 ALL=(ALL) NOPASSWD:ALL
$ serverspec-init Select OS type: 1) UN*X 2) Windows Select number: 1 Select a backend type: 1) SSH 2) Exec (local) Select number: 1 Vagrant instance y/n: n Input target host name: www.example.com + spec/ + spec/www.example.com/ + spec/www.example.com/sample_spec.rb + spec/spec_helper.rb + Rakefile
$ rake -T
$ rake spec:www.example.com
$ rspec spec/server1/httpd_spec.rb
$ rake spec:www.example.com ASK_SUDO_PASSWORD=1 Enter sudo password:
| php_spec.rb | |
| ruby_spec.rb |
| nginx_spec.rb | |
| apache-httpd_spec.rb | |
| mariadb_spec.rb | |
| zabbix-agent_spec.rb |
# Is there the file?
describe file('/etc/passwd') do
it { should be_file }
end
# Is there the Directory ?
describe file('/var/log/httpd') do
it { should be_directory }
end
describe command('ls -al /') do
its(:stdout) { should match /bin/ }
end
describe command('ls /foo') do
its(:stderr) { should match /No such file or directory/ }
end
describe command('ls /foo') do
its(:exit_status) { should eq 0 }
end
case check_centos_version
when '5.4'
describe file('/etc/ldap.conf') do
do_some_tests
end
when '6.2'
describe file('/etc/pam_ldap.conf') do
do_some_tests
end
else
puts "Error: Couldn't execute tests. Unknown OS."
exit 1
end