Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/volanja/ansible-sample-tdd
Test Driven Development for Ansible by ServerSpec. It's Sample
https://github.com/volanja/ansible-sample-tdd
Last synced: 3 months ago
JSON representation
Test Driven Development for Ansible by ServerSpec. It's Sample
- Host: GitHub
- URL: https://github.com/volanja/ansible-sample-tdd
- Owner: volanja
- Created: 2013-12-17T16:08:40.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2019-07-07T14:34:20.000Z (over 5 years ago)
- Last Synced: 2024-07-20T03:48:12.753Z (4 months ago)
- Language: Ruby
- Size: 28.3 KB
- Stars: 94
- Watchers: 11
- Forks: 14
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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.
- [Rubygems - ansible_spec](http://rubygems.org/gems/ansible_spec)
- [Github - ansible_spec](https://github.com/volanja/ansible_spec)# Environment
```
$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]$ gem list (needs)
ansible_spec (0.3)
ansible-vault (0.2.1)
serverspec (2.41.3)
specinfra (2.75.1)
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](https://github.com/volanja/ansible_spec#change-ansiblespecv0013)
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.```.ansiblespec
---
-
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]```hosts
[server]
192.168.100.203# 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``````site.yml
- 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
```