2

I'm using kitchen and ansible to test-drive server configurations. Every example I can find has a .kitchen.yml file in the same folder as the ansible role. I would like to execute multiple tests but there doesn't seem to be an in-built way of doing this - kitchen test expects a single .kitchen.yml file in the folder it's run in (along with the serverspec ruby spec files and a default.yml file that wraps the actual role) e.g.

roles
 - role_1
    - tasks
        mail.yml
    - test/integration/default/serverspec/localhost
        role_spec.rb
    default.yml
    .kitchen.yml

I would rather separate out the files used for testing from the files used to configure the servers and to that end I have created a suite per role and specified the provisioner playbook in the suite config:

suites:
  - name: role_1
    provisioner:
      playbook: test/integration/role_1/default.yml
  - name: role_2
    provisioner:
      playbook: test/integration/role_2/default.yml

My *_spec.rb files then have to be in a folder named test/integration/role_1/serverspec

This also allows me to run multiple role tests via a single kitchen test but I'm not sure if this is the way to be going. If I had a playbook that had multiple roles, I can't see how I can re-use the *_spec.rb files.

How is this meant to be done?

Kev
  • 118,037
  • 53
  • 300
  • 385
blank
  • 17,852
  • 20
  • 105
  • 159

2 Answers2

2

This now available with the latest busser-ansiblespec see:

https://github.com/neillturner/busser-ansiblespec

https://github.com/neillturner/ansible_repo

https://github.com/neillturner/kitchen-ansible

neill
  • 165
  • 1
  • 1
  • 6
  • You should include the key parts from the links and just use the links as references. –  Dec 18 '15 at 17:52
1

What I do with my Ansible roles is the following. My .kitchen.yml file in the "root" of the role:

---
driver:
  name: docker
  provision_command: sed -i '/tsflags=nodocs/d' /etc/yum.conf

provisioner:
  name: ansible_playbook
  ansible_yum_repo: "http://mirror.logol.ru/epel/6/x86_64/epel-release-6-8.noarch.rpm"
  hosts: localhost
  requirements_path: requirements.yml

platforms:
  - name: centos-6.6

verifier:
  ruby_bindir: '/usr/bin' 

suites:
  - name: zabbix-server-mysql
    playbook: zabbix-server-mysql.yml
    provisioner:
        name: ansible_playbook
        playbook: test/integration/zabbix-server-mysql.yml
  - name: zabbix-server-pgsql
    provisioner:
        name: ansible_playbook
        playbook: test/integration/zabbix-server-pgsql.yml

In the "test/integration" directory I have the following setup:

./zabbix-server-mysql/serverspec/localhost/ansible-zabbix-server_spec.rb
./zabbix-server-mysql/serverspec/spec_helper.rb
./zabbix-server-mysql.yml
./zabbix-server-pgsql/serverspec/localhost/ansible-zabbix-server_spec.rb
./zabbix-server-pgsql/serverspec/spec_helper.rb
./zabbix-server-pgsql.yml

The zabbix-server-pgsql.yml and zabbix-server-mysql.yml files are the playbooks that is calling the role itself, like this:


- hosts: localhost
  roles:
    - role: geerlingguy.mysql
    - role: ansible-zabbix-server
      zabbix_url: zabbix.example.com
      zabbix_version: 2.4
      database_type: mysql
      database_type_long: mysql

Hope this helps you.

I don't know how to reuse the _spec.rb files, so I can't give an answer on that one. (Do want to know the answer, so I'll bookmark this page ;-))

Kind regards,

Werner