Merge pull request #275 from chef/alexpop/add_ansible_example

add kitchen-ansible inspec example
This commit is contained in:
Christoph Hartmann 2015-11-30 15:15:38 +01:00
commit 5cb8458799
6 changed files with 100 additions and 0 deletions

View file

@ -0,0 +1,25 @@
---
driver:
name: vagrant
provisioner:
hosts: webservers
name: ansible_playbook
# Use el7 epel repo instead of the default el6
ansible_yum_repo: "https://download.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm"
require_chef_for_busser: false
require_ruby_for_busser: false
ansible_verbosity: 2
ansible_verbose: true
# starting playbook is at: test/integration/default/default.yml
verifier:
name: inspec
platforms:
- name: centos-7.1
- name: ubuntu-12.04
- name: ubuntu-14.04
suites:
- name: default

View file

@ -0,0 +1,20 @@
# encoding: utf-8
source 'https://rubygems.org'
gem 'inspec', path: '../../.'
group :test do
gem 'bundler', '~> 1.5'
gem 'minitest', '~> 5.5'
gem 'rake', '~> 10'
gem 'rubocop', '~> 0.33.0'
gem 'simplecov', '~> 0.10'
end
group :integration do
gem 'test-kitchen', '~> 1.4'
gem 'kitchen-ansible'
gem 'kitchen-vagrant'
gem 'kitchen-inspec'
gem 'concurrent-ruby', '~> 0.9'
end

View file

@ -0,0 +1,6 @@
[nginx]
name=Nginx Repo
baseurl=http://nginx.org/packages/centos/7/x86_64
enabled=1
gpgcheck=1
gpgkey=http://nginx.org/keys/nginx_signing.key

View file

@ -0,0 +1,16 @@
---
- name: create nginx yum repo if OS family is RedHat
copy: src=nginx.repo dest=/etc/yum.repos.d/
owner=root group=root mode=0644
when: (ansible_os_family == "RedHat" and ansible_distribution_major_version == "7")
- name: ensure nginx is at the latest version if OS family is RedHat
yum: name=nginx state=latest
when: ansible_os_family == "RedHat"
- name: ensure nginx is at the latest version if OS family is Debian
apt: name=nginx state=latest
when: ansible_os_family == "Debian"
- name: ensure nginx is running (and enable it at boot)
service: name=nginx state=started enabled=yes

View file

@ -0,0 +1,5 @@
---
- name: wrapper playbook for kitchen testing
hosts: webservers
roles:
- kitchen-ansible

View file

@ -0,0 +1,28 @@
# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter
# use basic tests
describe package('nginx') do
it { should be_installed }
end
# extend tests with metadata
control '01' do
impact 0.7
title 'Verify nginx service'
desc 'Ensures nginx service is up and running'
describe service('nginx') do
it { should be_enabled }
it { should be_installed }
it { should be_running }
end
end
# implement os dependent tests
web_user = 'www-data'
web_user = 'nginx' if os[:family] == 'centos'
describe user(web_user) do
it { should exist }
end