Skip to content

Instantly share code, notes, and snippets.

@aderixon
Last active February 11, 2016 15:59
Show Gist options
  • Save aderixon/847013db052a4fdb552d to your computer and use it in GitHub Desktop.
Save aderixon/847013db052a4fdb552d to your computer and use it in GitHub Desktop.
---
# complete example
driver:
name: vagrant
vagrantfiles:
- test/vagrant-vbguest.rb
provision: true
provisioner:
name: ansible_playbook
roles_path: roles
hosts: test-kitchen
ansible_yum_repo: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
require_ansible_repo: true
ansible_verbose: true
require_chef_for_busser: false
require_ruby_for_busser: true
# additional Ansible dirs to copy to guest:
additional_code_path: ['vars']
platforms:
- name: centos6
driver_plugin: vagrant
driver_config:
box: centos/6
box_url: http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
network:
- ['forwarded_port', {guest: 80, host: 8881}]
provisioner:
ansible_yum_repo: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm"
- name: centos7
driver_plugin: vagrant
driver_config:
box: centos/7
box_url: https://atlas.hashicorp.com/centos/7
network:
- ['forwarded_port', {guest: 80, host: 8880}]
verifier:
ruby_bindir: '/usr/bin'
suites:
- name: httpd
provisioner:
playbook: test/integration/httpd/httpd.yml
- name: redis
provisioner:
playbook: test/integration/redis/redis.yml

Running Test Kitchen on CentOS guests

To get Test Kitchen running for Ansible testing against the official CentOS 7 box under Vagrant, I had to:

  • Install kitchen, kitchen-vagrant, kitchen-ansible gems.
  • Add a Gemfile to the serverspec to get 'rake' installed, as it isn't part of ruby in the default CentOS package:
source 'https://rubygems.org'
gem 'rake'
  • Avoid using leading zeros on file modes in the serverspec be_mode tests (use three digit modes instead).

To reduce run time, I also added a Vagrantfile stub to disable the auto-installation of the VirtualBox guest tools with the vbguest plugin (optional):

Vagrant.configure("2") do |config|
  config.vbguest.auto_update = false
end

...And in .kitchen.yml:

driver:
  name: vagrant
  vagrantfiles:
    - test/vagrant-vbguest.rb

Apart from that, this guide works pretty well for the setup.

For multiple test suites, the suite definition must contain a provisioner entry specifying the full path to the playbook from the top level (Ansible) directory; e.g. test/integration/playbook.yml.

When testing against multiple, different RHEL/CentOS releases, add a provisioner entry to each platform definition, containing an ansible_yum_repo value for the relevant epel-release URL (e.g. https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm). Note that for older EL6 guests, you will need to update the ca-certificates package before it will be able to download the EPEL RPM successfully; this can be done in a shell provisioner within the additional Vagrant file specified in the config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment