Coder Social home page Coder Social logo

ansible-sample-tdd's Introduction

ansible-sample-tdd

Test Driven Development for Ansible by ServerSpec. It's Sample

ServerSpec is a test framework based on Ruby.

NOTICE
If you want to use these specfiles on other project,
Please install ansible_spec ruby-gem to parse Ansible playbook & inventory files.

Environment

$ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin11.4.2]

$ gem list (needs)
ansible_spec (0.2.6)
serverspec (2.23.1)
specinfra (2.43.4)
hostlist_expression (0.2.1)

Important( from v0.1)

this sample use (Rubygem) ansible_spec

gem install ansible_spec

Directory

.
├── .ansiblespec                 #Create file (use Serverspec)
├── README.md
├── hosts                        #use Ansible and Serverspec if `.ansiblespec` do not exist.
├── exec_hosts.sh                #Dynamic Inventory sample. if you use DynamicInventory, change `.ansiblespec`
├── site.yml                     #use Ansible and Serverspec if `.ansiblespec` do not exist.
├── nginx.yml                    #(comment-out) included by site.yml
├── roles
│   ├── mariadb
│   │   ├── spec
│   │   │   └── mariadb_spec.rb
│   │   ├── tasks
│   │   │   └── main.yml
│   │   └── templates
│   │       └── mariadb.repo
│   └── nginx
│       ├── handlers
│       │   └── main.yml
│       ├── spec                 #use Serverspec
│       │   └── nginx_spec.rb
│       ├── tasks
│       │   └── main.yml
│       ├── templates
│       │   └── nginx.repo
│       └── vars
│           └── main.yml
├── Rakefile                     #use Serverspec
└── spec                         #use Serverspec 
    └── spec_helper.rb

Change .ansiblespec(v0.0.1.3)

read this section If .ansiblespec exist, use variables(playbook and inventory).
So, If you don't use site.yml and hosts, you need to change this file.
If .ansiblespec is not found, use site.yml as playbook and hosts as inventory.

--- 
- 
  playbook: site.yml
  inventory: hosts

Run Playbook

Please change the target IP address of server -> hosts (default is 192.168.0.103 and 104)

$ ansible-playbook site.yml -i hosts

#Test

Serverspec with Ansible

Serverspec use this file. (Rakefile understand the syntax of Ansible.)

  • hosts
    hosts can use [group_name]
[server]
192.168.0.103

# under sample

#192.168.0.103:22
#192.168.0.103 ansible_ssh_port=22
#192.168.0.103 ansible_ssh_private_key_file=~/.ssh/id_rsa
#test ansible_ssh_host=192.168.0.103
#192.168.0.103 ansible_ssh_user=root
#jumper ansible_ssh_port=22 ansible_ssh_host=192.168.0.103

#[sample]
#(comment) www1.example.com to www99.example.com
#www[1:99].example.com

#(comment)  www01.example.com to www99.example.com
#www[01:99].example.com

#(comment)  db-a.example.com to db-z.example.com
#db-[a:z].example.com

#(comment)  db-A.example.com to db-Z.example.com
#db-[A:Z].example.com

#[databases]
#192.168.0.103

#(comment)  Multi Group. use server & databases
#[group:children]
#sample
#databases
  • site.yml
    site.yml can use include
- name: Ansible-Sample-TDD
  hosts: server
  user: root
  roles:
    - nginx
    - mariadb

Run Test

$ rake -T
rake serverspec:Ansible-Sample-TDD  # Run serverspec for Ansible-Sample-TDD / Run serverspec for Ansible-Sample-TDD 

$ rake serverspec:Ansible-Sample-TDD
Run serverspec for Ansible-Sample-TDD to 192.168.0.103
/Users/Adr/.rvm/rubies/ruby-1.9.2-p320/bin/ruby -S rspec roles/mariadb/spec/mariadb_spec.rb roles/nginx/spec/nginx_spec.rb
...........

Finished in 0.40289 seconds
11 examples, 0 failures
Run serverspec for Ansible-Sample-TDD to 192.168.0.104
/Users/Adr/.rvm/rubies/ruby-1.9.2-p320/bin/ruby -S rspec roles/mariadb/spec/mariadb_spec.rb roles/nginx/spec/nginx_spec.rb
...........

Finished in 0.4004 seconds
11 examples, 0 failures

ansible-sample-tdd's People

Contributors

mscherer avatar okamototk avatar volanja avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.