AnsibleSpec
This gem is Ansible Config Parser for Serverspec.
Serverspec RakeTask uses Ansible Config(InventoryFile and Playbook).
Support Run Multi Role and Multi Host of Ansible.
This gem created template file until v0.0.1.4,
But it was modularized on v0.1. Because module is easy to unit-test and Rakefile is simple.
If you want old release that can create template, use gem install ansible_spec -v 0.0.1.4
But I can't support(Bug fix, Add feature) old release.
New feature at v0.1
- Support Serverspec v2
- Simplification Rakefile and Modularization. Because of Improvement of testability.
- Support InventoryParameters
- ansible_ssh_port
- ansible_ssh_user
- ansible_ssh_host
- ansible_ssh_private_key_file
- Support hostlist expressions
- Support DynamicInventory
Installation
install it yourself as:
$ gem install ansible_spec
Usage
Create Rakafile & spec/spec_helper.rb
$ ansiblespec-init
create spec
create spec/spec_helper.rb
create Rakefile
create .ansiblespec
VersionUp from v0.0.1.4 to v0.1
$ rm Rakefile
$ rm spec/spec_helper.md
$ ansiblespec-init
Change .ansiblespec(v0.0.1.3)
If .ansiblespec
is exist, use variables(playbook and inventory).
So, If you don't use site.yml
and hosts
, you change this file.
If .ansiblespec
not found, use site.yml
as playbook and hosts
as inventory.
---
-
playbook: site.yml
inventory: hosts
Create Ansible Directory
sample is here
.
├── .ansiblespec #Create file (use Serverspec). read above section.
├── README.md
├── hosts #use Ansible and Serverspec if .ansiblespec is not exist.
├── site.yml #use Ansible and Serverspec if .ansiblespec is not exist.
├── nginx.yml #(comment-out) incluted by site.yml
├── roles
│ └── nginx
│ ├── handlers
│ │ └── main.yml
│ ├── spec #use Serverspec
│ │ └── nginx_spec.rb
│ ├── tasks
│ │ └── main.yml
│ ├── templates
│ │ └── nginx.repo
│ └── vars
│ └── main.yml
├── Rakefile #Create file (use Serverspec)
└── spec #Create file (use Serverspec)
└── spec_helper.rb
Serverspec with Ansible
Serverspec use Ansible file. (Rakefile understand Notation of Ansible.)
- Inventory file Inventory file can sue this:
- InventoryParameters
- ansible_ssh_port
- ansible_ssh_user
- ansible_ssh_private_key
- ansible_ssh_host
- define hosts as expressions.
host-[1:3]
would expand intohost-1
,host-2
,host-3
- Group Children
- DynamicInventory
[server]
# skip line(comment)
# normal
192.168.0.1
# use port 5309
192.168.0.3:5309
# use port 22
192.168.0.2 ansible_ssh_port=22
# use Private-key ~/.ssh/id_rsa
192.168.0.4 ansible_ssh_private_key_file=~/.ssh/id_rsa
# use user `git`
192.168.0.5 ansible_ssh_user=git
# use port 5555 & host 192.168.1.50
jumper ansible_ssh_port=5555 ansible_ssh_host=192.168.1.50
[web]
# www1.example.com to www99.example.com
www[1:99].example.com
# www01.example.com to www99.example.com
www[01:99].example.com
[databases]
# db-a.example.com to db-z.example.com
db-[a:z].example.com
# db-A.example.com to db-Z.example.com
db-[A:Z].example.com
# Multi Group. use server & databases
[parent:children]
server
databases
or DynamicInventory(need execute permission)
```example that DynamicInventory
!/bin/bash
echo '{"hosts": ["host1.example.com", "host2.example.com"],"vars":{"a": true}}'
* playbook
playbook can use `include`
```site.yml
- name: Ansible-Sample-TDD
hosts: server
user: root
roles:
- nginx
- name: Ansible-Sample-TDD2
hosts: parent
user: root
roles:
- nginx
Run Test(Sample)
$ rake -T
rake serverspec:Ansible-Sample-TDD # Run serverspec for Ansible-Sample-TDD
rake serverspec:Ansible-Sample-TDD2 # Run serverspec for Ansible-Sample-TDD2
$ rake serverspec:Ansible-Sample-TDD
Run serverspec for Ansible-Sample-TDD to 192.168.0.103
/Users/Adr/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec roles/mariadb/spec/mariadb_spec.rb roles/nginx/spec/nginx_spec.rb
...........
Finished in 0.34306 seconds
11 examples, 0 failures
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request