A Busser runner plugin for Ansible.
By default this enables testing using the ansiblespec format. The serverspec tests are specified with the roles in the ansible repository.
- Multiple hosts and multiple roles can be tested.
- It also supports storing the spec tests in the spec directory and in test-kitchen style test/integration directory.
- Serverspec using ssh to communicate with the server to be tested.
- It reads the ansible playbook and inventory files to determine the hosts to test and the roles for each host.
In the ansible repository specify:
-
spec files with the roles.
-
spec_helper in the spec folder (with code as below).
-
test/integration//ansiblespec containing config.yml and ssh private keys to access the servers.
See example https://github.com/neillturner/ansible_repo
.
+-- roles
¦ +-- mariadb
¦ ¦ +-- spec
¦ ¦ ¦ +-- mariadb_spec.rb
¦ ¦ +-- tasks
¦ ¦ ¦ +-- main.yml
¦ ¦ +-- templates
¦ ¦ +-- mariadb.repo
¦ +-- nginx
¦ +-- handlers
¦ ¦ +-- main.yml
¦ +-- spec
¦ ¦ +-- nginx_spec.rb
¦ +-- tasks
¦ ¦ +-- main.yml
¦ +-- templates
¦ ¦ +-- nginx.repo
¦ +-- vars
¦ +-- main.yml
+-- spec
+-- spec_helper.rb
+-- my_private_key.pem
+-- test
+-- integration
+-- default # name of test-kitchen suite
+-- ansiblespec
+-- config.yml
require 'rubygems'
require 'bundler/setup'
require 'serverspec'
require 'pathname'
require 'net/ssh'
RSpec.configure do |config|
set :host, ENV['TARGET_HOST']
# ssh options at http://net-ssh.github.io/ssh/v1/chapter-2.html
# https://net-ssh.github.io/ssh/v2/api/classes/Net/SSH/Config.html
# change user from root if using ubuntu, vagrant etc
# ssh via password
set :ssh_options, :user => ENV['LOGIN_USER'], :paranoid => false, :verbose => :error, :password => ENV['LOGIN_PASSWORD'] if ENV['LOGIN_PASSWORD']
# ssh via ssh key
set :ssh_options, :user => ENV['LOGIN_USER'], :paranoid => false, :verbose => :error, :host_key => 'ssh-rsa', :keys => [ ENV['SSH_KEY'] ] if ENV['SSH_KEY']
set :backend, :ssh
set :request_pty, true
end
This goes in directory test/integration/default/ansiblespec where default is the name of test-kitchen suite
---
-
playbook: default.yml
inventory: hosts
kitchen_path: '/tmp/kitchen'
pattern: 'ansiblespec' # or spec or serverspec
user: root
ssh_key: 'spec/my_private_key.pem'
login_password: 'myrootpassword'
To add additionl ruby gems create a Gemfile in directory test/integration/default/ansiblespec
source 'https://rubygems.org'
gem 'rake'
gem 'busser-ansiblespec', '<=0.6.5'
- Source hosted at GitHub
- Report issues/questions/feature requests on GitHub Issues
Pull requests are very welcome! Make sure your patches are well tested. Ideally create a topic branch for every separate change you make. For example:
- Fork the repo
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Original busser-serverspec created and maintained by HIGUCHI Daisuke ([email protected])
modified by Neill Turner ([email protected])
Apache 2.0 (see LICENSE)