kitchen-ansible 0.49.0 → 0.52.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +270 -270
- data/kitchen-ansible.gemspec +34 -35
- data/lib/kitchen-ansible/version.rb +6 -6
- data/lib/kitchen/provisioner/ansible/config.rb +206 -197
- data/lib/kitchen/provisioner/ansible/librarian.rb +78 -78
- data/lib/kitchen/provisioner/ansible/os.rb +84 -84
- data/lib/kitchen/provisioner/ansible/os/alpine.rb +42 -42
- data/lib/kitchen/provisioner/ansible/os/amazon.rb +42 -42
- data/lib/kitchen/provisioner/ansible/os/darwin.rb +37 -37
- data/lib/kitchen/provisioner/ansible/os/debian.rb +77 -75
- data/lib/kitchen/provisioner/ansible/os/fedora.rb +66 -60
- data/lib/kitchen/provisioner/ansible/os/freebsd.rb +34 -34
- data/lib/kitchen/provisioner/ansible/os/openbsd.rb +36 -36
- data/lib/kitchen/provisioner/ansible/os/redhat.rb +86 -80
- data/lib/kitchen/provisioner/ansible/os/suse.rb +44 -44
- data/lib/kitchen/provisioner/ansible_playbook.rb +1292 -1239
- data/provisioner_options.md +290 -268
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcf3c0b3410c365569e9b26c6e5266f1b3217a7af788440c9bc67770578d029f
|
4
|
+
data.tar.gz: e34eb4cbb1f2f5281f3ca066e73d7a72e50bc315856b9bb5837d74b0cc6fe9b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5859df7d528ca944d8f2547aef1ca0a0d6aa9cbc8efa0cb0a6e545fa531d84dbe9b87819b72fff5d0554b437a2564ff1d173578b2d0602639baf8d445424ca89
|
7
|
+
data.tar.gz: 8280cd6d6edf1fd87f67233c72548920971a6ed74939785e29e26a9b9488a438011c065e69a0669db226dd14834be1f0cbba0ed1c2ab7488b3883cc6ba27ef7e
|
data/README.md
CHANGED
@@ -1,270 +1,270 @@
|
|
1
|
-
# kitchen-ansible
|
2
|
-
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/kitchen-ansible.svg)](http://badge.fury.io/rb/kitchen-ansible)
|
4
|
-
[![Gem Downloads](http://ruby-gem-downloads-badge.herokuapp.com/kitchen-ansible?type=total&color=brightgreen)](https://rubygems.org/gems/kitchen-ansible)
|
5
|
-
[![Build Status](https://travis-ci.org/neillturner/kitchen-ansible.png)](https://travis-ci.org/neillturner/kitchen-ansible)
|
6
|
-
|
7
|
-
A Test Kitchen Provisioner for Ansible.
|
8
|
-
|
9
|
-
The provisioner works by passing the Ansible repository based on attributes in `.kitchen.yml` & calling `ansible-playbook`.
|
10
|
-
|
11
|
-
It installs Ansible on the server and runs `ansible-playbook` using host localhost.
|
12
|
-
|
13
|
-
It has been tested against the Ubuntu 12.04/14.04/16.04, Centos 6/7 and Debian 6/7/8 boxes running in vagrant/virtualbox.
|
14
|
-
|
15
|
-
## Requirements
|
16
|
-
- [Test Kitchen](https://github.com/test-kitchen/test-kitchen).
|
17
|
-
- a driver box without a Chef installation so Ansible can be installed.
|
18
|
-
|
19
|
-
## Installation & Setup
|
20
|
-
|
21
|
-
1. install the latest Ruby on your workstation (for windows see https://rubyinstaller.org/downloads/)
|
22
|
-
|
23
|
-
2. If using Ruby version less than 2.3 first install earlier version of test-kitchen
|
24
|
-
```
|
25
|
-
gem install test-kitchen -v 1.16.0
|
26
|
-
```
|
27
|
-
3. Install the `kitchen-ansible` gem in your system, along with [kitchen-vagrant](https://github.com/test-kitchen/kitchen-vagrant) or [kitchen-docker](https://github.com/test-kitchen/kitchen-docker) or any other suitable driver or the exec driver to run from your workstation:
|
28
|
-
|
29
|
-
```
|
30
|
-
gem install kitchen-ansible
|
31
|
-
gem install kitchen-vagrant
|
32
|
-
```
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
## Resources
|
37
|
-
* https://blog.superk.org/home/ansible-role-development
|
38
|
-
* https://alexharv074.github.io/2016/05/25/testing-an-ansible-role-using-test-kitchen.html
|
39
|
-
* https://alexharv074.github.io/2016/06/13/integration-testing-using-ansible-and-test-kitchen.html
|
40
|
-
* https://github.com/MattHodge/ansible-testkitchen-windows
|
41
|
-
* https://readme.fr/continuous-integration-for-ansible/
|
42
|
-
* https://dantehranian.wordpress.com/2015/06/18/testing-ansible-roles-with-test-kitchen
|
43
|
-
* http://www.slideshare.net/MartinEtmajer/testing-ansible-roles-with-test-kitchen-serverspec-and-rspec-48185017
|
44
|
-
* http://blog.el-chavez.me/2016/02/16/ansible-galaxy-test-kitchen
|
45
|
-
* https://werner-dijkerman.nl/2015/08/20/using-test-kitchen-with-docker-and-serverspec-to-test-ansible-roles
|
46
|
-
* https://books.google.co.uk/books?id=D-wmDQAAQBAJ&pg=PA129&lpg
|
47
|
-
|
48
|
-
## Example .kitchen.yml file
|
49
|
-
|
50
|
-
Based on the [Tomcat Standalone](https://github.com/ansible/ansible-examples/tree/master/tomcat-standalone) example:
|
51
|
-
|
52
|
-
```yaml
|
53
|
-
---
|
54
|
-
driver:
|
55
|
-
name: vagrant
|
56
|
-
|
57
|
-
provisioner:
|
58
|
-
name: ansible_playbook
|
59
|
-
roles_path: roles
|
60
|
-
hosts: tomcat-servers
|
61
|
-
require_ansible_repo: true
|
62
|
-
ansible_verbose: true
|
63
|
-
ansible_version: latest
|
64
|
-
require_chef_for_busser: false
|
65
|
-
additional_ssh_private_keys:
|
66
|
-
- /mykey/id_rsa
|
67
|
-
|
68
|
-
platforms:
|
69
|
-
- name: nocm_centos-6.5
|
70
|
-
driver_plugin: vagrant
|
71
|
-
driver_config:
|
72
|
-
box: nocm_centos-6.5
|
73
|
-
box_url: http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box
|
74
|
-
network:
|
75
|
-
- ['forwarded_port', {guest: 8080, host: 8080}]
|
76
|
-
- ['private_network', {ip: '192.168.33.11'}]
|
77
|
-
```
|
78
|
-
|
79
|
-
See example [https://github.com/neillturner/ansible_repo](https://github.com/neillturner/ansible_repo)
|
80
|
-
|
81
|
-
## Windows Support
|
82
|
-
|
83
|
-
Windows is supported by creating a linux server to run Ansible with software required to support winrm. Then the winrm connection is used to configure the windows server.
|
84
|
-
|
85
|
-
In `.kitchen.yml` set:
|
86
|
-
|
87
|
-
```yaml
|
88
|
-
ansible_connection: winrm
|
89
|
-
require_windows_support: true
|
90
|
-
require_chef_for_busser: false
|
91
|
-
```
|
92
|
-
|
93
|
-
See the [Ansible Windows repo](https://github.com/neillturner/ansible_windows_repo) example.
|
94
|
-
|
95
|
-
## Test Kitchen Exec Driver
|
96
|
-
|
97
|
-
By using the test-kitchen exec driver ansible can be driven from your workstation. This provides similar functionality to [kitchen-ansiblepush](https://github.com/ahelal/kitchen-ansiblepush). Remote servers, as specified in the ansible inventory, can be built with ansible automatically installed and run from your workstation.
|
98
|
-
|
99
|
-
See example [https://github.com/neillturner/ansible_exec_repo](https://github.com/neillturner/ansible_exec_repo)
|
100
|
-
|
101
|
-
## Ansible AWX
|
102
|
-
|
103
|
-
Kitchen ansible supports installing and using the open source version of Ansible Tower [Ansible AWX](https://github.com/ansible/awx) on a Centos 7. In future it will support the tower-cli for testing.
|
104
|
-
|
105
|
-
See example [https://github.com/neillturner/ansible_awx_repo](https://github.com/neillturner/ansible_awx_repo)
|
106
|
-
|
107
|
-
## Using Roles from Ansible Galaxy
|
108
|
-
|
109
|
-
Roles can be used from the Ansible Galaxy using two methods:
|
110
|
-
|
111
|
-
1. Specify a `requirements.yml` file in your Ansible repository. For more details see [here](http://docs.ansible.com/ansible/galaxy.html).
|
112
|
-
|
113
|
-
2. Use `librarian-ansible` by creating an `Ansiblefile` in the top level of the repository and `kitchen-ansible` will automatically call `librarian-ansible` during convergence. For a description of setting up an `Ansiblefile` see [here](https://werner-dijkerman.nl/2015/08/15/using-librarian-ansible-to-install-ansible-roles-from-gitlab/).
|
114
|
-
|
115
|
-
## Tips
|
116
|
-
|
117
|
-
To use a single ~/.kitchen/config.yml file with multiple reposities by setting the WORKSPACE environment variable:
|
118
|
-
|
119
|
-
```yaml
|
120
|
-
role_path: <%= ENV['WORKSPACE'] %>/roles
|
121
|
-
```
|
122
|
-
|
123
|
-
You can easily skip previous instructions and jump directly to the broken statement you just fixed by passing an environment variable. Add the following to your `.kitchen.yml`:
|
124
|
-
|
125
|
-
```yaml
|
126
|
-
provisioner:
|
127
|
-
name: ansible_playbook
|
128
|
-
ansible_extra_flags: <%= ENV['ANSIBLE_EXTRA_FLAGS'] %>
|
129
|
-
```
|
130
|
-
|
131
|
-
Then run:
|
132
|
-
|
133
|
-
```
|
134
|
-
$ ANSIBLE_EXTRA_FLAGS='--start-at-task="myrole | name of last working instruction"' kitchen converge
|
135
|
-
```
|
136
|
-
|
137
|
-
You save a lot of time not running working instructions.
|
138
|
-
|
139
|
-
|
140
|
-
## Ruby install to run Serverspec verify
|
141
|
-
|
142
|
-
By default test-kitchen installs Chef to get a Ruby version suitable to run Serverspec in the `verify` step.
|
143
|
-
kitchen-verifier-serverspec installs its own ruby version so chef or ruby is not required to verify with serverspec :
|
144
|
-
|
145
|
-
```yaml
|
146
|
-
require_chef_for_busser: false
|
147
|
-
```
|
148
|
-
And set the verifier section:
|
149
|
-
```yaml
|
150
|
-
verifier:
|
151
|
-
name: serverspec
|
152
|
-
sudo_path: true
|
153
|
-
|
154
|
-
suites:
|
155
|
-
- name: ansible
|
156
|
-
driver_config:
|
157
|
-
hostname: '54.229.34.169'
|
158
|
-
verifier:
|
159
|
-
patterns:
|
160
|
-
- roles/tomcat/spec/tomcat_spec.rb
|
161
|
-
bundler_path: '/usr/local/bin'
|
162
|
-
rspec_path: '/usr/local/bin'
|
163
|
-
env_vars:
|
164
|
-
TARGET_HOST: 54.229.104.40
|
165
|
-
LOGIN_USER: centos
|
166
|
-
SUDO: true
|
167
|
-
SSH_KEY: spec/test.pem
|
168
|
-
```
|
169
|
-
|
170
|
-
Please see the [Provisioner Options](https://github.com/neillturner/kitchen-ansible/blob/master/provisioner_options.md) for a complete listing.
|
171
|
-
|
172
|
-
## Test-Kitchen Ansiblespec
|
173
|
-
|
174
|
-
By using kitchen-verifier-serverspec and the Runner ansiblespec_runner tests can be run against multiple servers with multiple roles in the ansiblespec format.
|
175
|
-
|
176
|
-
Serverspec uses ssh to communicate with the server to be tested and reads the Ansible playbook and inventory files to determine the hosts to test and the roles for each host.
|
177
|
-
|
178
|
-
See example [https://github.com/neillturner/ansible_ansiblespec_repo](https://github.com/neillturner/ansible_ansiblespec_repo)
|
179
|
-
|
180
|
-
### Example usage to create Tomcat servers:
|
181
|
-
|
182
|
-
![test-kitchen, Ansible and ansiblespec](https://github.com/neillturner/ansible_repo/blob/master/kitchen-ansible.png "test-kitchen, ansible and ansiblespec")
|
183
|
-
|
184
|
-
See [ansible-sample-tdd](https://github.com/volanja/ansible-sample-tdd).
|
185
|
-
|
186
|
-
### Usage
|
187
|
-
|
188
|
-
#### Directory
|
189
|
-
|
190
|
-
In the Ansible repository specify:
|
191
|
-
|
192
|
-
* spec files with the roles.
|
193
|
-
* spec_helper in the spec folder (with code as below).
|
194
|
-
|
195
|
-
```
|
196
|
-
.
|
197
|
-
+-- roles
|
198
|
-
¦ +-- mariadb
|
199
|
-
¦ ¦ +-- spec
|
200
|
-
¦ ¦ ¦ +-- mariadb_spec.rb
|
201
|
-
¦ ¦ +-- tasks
|
202
|
-
¦ ¦ ¦ +-- main.yml
|
203
|
-
¦ ¦ +-- templates
|
204
|
-
¦ ¦ +-- mariadb.repo
|
205
|
-
¦ +-- nginx
|
206
|
-
¦ +-- handlers
|
207
|
-
¦ ¦ +-- main.yml
|
208
|
-
¦ +-- spec
|
209
|
-
¦ ¦ +-- nginx_spec.rb
|
210
|
-
¦ +-- tasks
|
211
|
-
¦ ¦ +-- main.yml
|
212
|
-
¦ +-- templates
|
213
|
-
¦ ¦ +-- nginx.repo
|
214
|
-
¦ +-- vars
|
215
|
-
¦ +-- main.yml
|
216
|
-
+-- spec
|
217
|
-
+-- spec_helper.rb
|
218
|
-
+-- my_private_key.pem
|
219
|
-
```
|
220
|
-
|
221
|
-
|
222
|
-
#### spec_helper
|
223
|
-
|
224
|
-
```ruby
|
225
|
-
require 'rubygems'
|
226
|
-
require 'bundler/setup'
|
227
|
-
|
228
|
-
require 'serverspec'
|
229
|
-
require 'pathname'
|
230
|
-
require 'net/ssh'
|
231
|
-
|
232
|
-
RSpec.configure do |config|
|
233
|
-
set :host, ENV['TARGET_HOST']
|
234
|
-
# ssh options at http://net-ssh.github.io/ssh/v1/chapter-2.html
|
235
|
-
# ssh via password
|
236
|
-
set :ssh_options, :user => ENV['LOGIN_USER'], :paranoid => false, :verbose => :error, :password => ENV['LOGIN_PASSWORD'] if ENV['LOGIN_PASSWORD']
|
237
|
-
# ssh via ssh key
|
238
|
-
set :ssh_options, :user => ENV['LOGIN_USER'], :paranoid => false, :verbose => :error, :host_key => 'ssh-rsa', :keys => [ ENV['SSH_KEY'] ] if ENV['SSH_KEY']
|
239
|
-
set :backend, :ssh
|
240
|
-
set :request_pty, true
|
241
|
-
end
|
242
|
-
```
|
243
|
-
|
244
|
-
See [kitchen-verifier-serverspec](https://github.com/neillturner/kitchen-verifier-serverspec).
|
245
|
-
|
246
|
-
## Alternative Virtualization/Cloud providers for Vagrant
|
247
|
-
This could be adapted to use alternative virtualization/cloud providers such as Openstack/AWS/VMware Fusion according to whatever is supported by Vagrant.
|
248
|
-
```yaml
|
249
|
-
platforms:
|
250
|
-
- name: ubuntu-12.04
|
251
|
-
driver_config:
|
252
|
-
provider: aws
|
253
|
-
box: my_base_box
|
254
|
-
# username is based on what is configured in your box/ami
|
255
|
-
username: ubuntu
|
256
|
-
customize:
|
257
|
-
access_key_id: 'AKKJHG659868LHGLH'
|
258
|
-
secret_access_key: 'G8t7o+6HLG876JGF/58'
|
259
|
-
ami: ami-7865ab765d
|
260
|
-
instance_type: t2.micro
|
261
|
-
# more customisation can go here, based on what the vagrant provider supports
|
262
|
-
#security-groups: []
|
263
|
-
```
|
264
|
-
|
265
|
-
## Notes
|
266
|
-
|
267
|
-
* The `default` in all of the above is the name of the test suite defined in the `suites` section of your `.kitchen.yml`, so if you have more than one suite of tests or change the name, you'll need to adapt the example accordingly.
|
268
|
-
* Serverspec test files *must* be named `_spec.rb`
|
269
|
-
* Since I'm using Vagrant, my `box` definitions refer to Vagrant boxes, either standard, published boxes available from [Atlas](http://atlas.hashicorp.com/boxes) or custom-created boxes (perhaps using [Packer](http://packer.io) and [bento](https://github.com/chef/bento), in which case you'll need to provide the URL in `box_url`.
|
270
|
-
|
1
|
+
# kitchen-ansible
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/kitchen-ansible.svg)](http://badge.fury.io/rb/kitchen-ansible)
|
4
|
+
[![Gem Downloads](http://ruby-gem-downloads-badge.herokuapp.com/kitchen-ansible?type=total&color=brightgreen)](https://rubygems.org/gems/kitchen-ansible)
|
5
|
+
[![Build Status](https://travis-ci.org/neillturner/kitchen-ansible.png)](https://travis-ci.org/neillturner/kitchen-ansible)
|
6
|
+
|
7
|
+
A Test Kitchen Provisioner for Ansible.
|
8
|
+
|
9
|
+
The provisioner works by passing the Ansible repository based on attributes in `.kitchen.yml` & calling `ansible-playbook`.
|
10
|
+
|
11
|
+
It installs Ansible on the server and runs `ansible-playbook` using host localhost.
|
12
|
+
|
13
|
+
It has been tested against the Ubuntu 12.04/14.04/16.04, Centos 6/7 and Debian 6/7/8 boxes running in vagrant/virtualbox.
|
14
|
+
|
15
|
+
## Requirements
|
16
|
+
- [Test Kitchen](https://github.com/test-kitchen/test-kitchen).
|
17
|
+
- a driver box without a Chef installation so Ansible can be installed.
|
18
|
+
|
19
|
+
## Installation & Setup
|
20
|
+
|
21
|
+
1. install the latest Ruby on your workstation (for windows see https://rubyinstaller.org/downloads/)
|
22
|
+
|
23
|
+
2. If using Ruby version less than 2.3 first install earlier version of test-kitchen
|
24
|
+
```
|
25
|
+
gem install test-kitchen -v 1.16.0
|
26
|
+
```
|
27
|
+
3. Install the `kitchen-ansible` gem in your system, along with [kitchen-vagrant](https://github.com/test-kitchen/kitchen-vagrant) or [kitchen-docker](https://github.com/test-kitchen/kitchen-docker) or any other suitable driver or the exec driver to run from your workstation:
|
28
|
+
|
29
|
+
```
|
30
|
+
gem install kitchen-ansible
|
31
|
+
gem install kitchen-vagrant
|
32
|
+
```
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
## Resources
|
37
|
+
* https://blog.superk.org/home/ansible-role-development
|
38
|
+
* https://alexharv074.github.io/2016/05/25/testing-an-ansible-role-using-test-kitchen.html
|
39
|
+
* https://alexharv074.github.io/2016/06/13/integration-testing-using-ansible-and-test-kitchen.html
|
40
|
+
* https://github.com/MattHodge/ansible-testkitchen-windows
|
41
|
+
* https://readme.fr/continuous-integration-for-ansible/
|
42
|
+
* https://dantehranian.wordpress.com/2015/06/18/testing-ansible-roles-with-test-kitchen
|
43
|
+
* http://www.slideshare.net/MartinEtmajer/testing-ansible-roles-with-test-kitchen-serverspec-and-rspec-48185017
|
44
|
+
* http://blog.el-chavez.me/2016/02/16/ansible-galaxy-test-kitchen
|
45
|
+
* https://werner-dijkerman.nl/2015/08/20/using-test-kitchen-with-docker-and-serverspec-to-test-ansible-roles
|
46
|
+
* https://books.google.co.uk/books?id=D-wmDQAAQBAJ&pg=PA129&lpg
|
47
|
+
|
48
|
+
## Example .kitchen.yml file
|
49
|
+
|
50
|
+
Based on the [Tomcat Standalone](https://github.com/ansible/ansible-examples/tree/master/tomcat-standalone) example:
|
51
|
+
|
52
|
+
```yaml
|
53
|
+
---
|
54
|
+
driver:
|
55
|
+
name: vagrant
|
56
|
+
|
57
|
+
provisioner:
|
58
|
+
name: ansible_playbook
|
59
|
+
roles_path: roles
|
60
|
+
hosts: tomcat-servers
|
61
|
+
require_ansible_repo: true
|
62
|
+
ansible_verbose: true
|
63
|
+
ansible_version: latest
|
64
|
+
require_chef_for_busser: false
|
65
|
+
additional_ssh_private_keys:
|
66
|
+
- /mykey/id_rsa
|
67
|
+
|
68
|
+
platforms:
|
69
|
+
- name: nocm_centos-6.5
|
70
|
+
driver_plugin: vagrant
|
71
|
+
driver_config:
|
72
|
+
box: nocm_centos-6.5
|
73
|
+
box_url: http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box
|
74
|
+
network:
|
75
|
+
- ['forwarded_port', {guest: 8080, host: 8080}]
|
76
|
+
- ['private_network', {ip: '192.168.33.11'}]
|
77
|
+
```
|
78
|
+
|
79
|
+
See example [https://github.com/neillturner/ansible_repo](https://github.com/neillturner/ansible_repo)
|
80
|
+
|
81
|
+
## Windows Support
|
82
|
+
|
83
|
+
Windows is supported by creating a linux server to run Ansible with software required to support winrm. Then the winrm connection is used to configure the windows server.
|
84
|
+
|
85
|
+
In `.kitchen.yml` set:
|
86
|
+
|
87
|
+
```yaml
|
88
|
+
ansible_connection: winrm
|
89
|
+
require_windows_support: true
|
90
|
+
require_chef_for_busser: false
|
91
|
+
```
|
92
|
+
|
93
|
+
See the [Ansible Windows repo](https://github.com/neillturner/ansible_windows_repo) example.
|
94
|
+
|
95
|
+
## Test Kitchen Exec Driver
|
96
|
+
|
97
|
+
By using the test-kitchen exec driver ansible can be driven from your workstation. This provides similar functionality to [kitchen-ansiblepush](https://github.com/ahelal/kitchen-ansiblepush). Remote servers, as specified in the ansible inventory, can be built with ansible automatically installed and run from your workstation.
|
98
|
+
|
99
|
+
See example [https://github.com/neillturner/ansible_exec_repo](https://github.com/neillturner/ansible_exec_repo)
|
100
|
+
|
101
|
+
## Ansible AWX
|
102
|
+
|
103
|
+
Kitchen ansible supports installing and using the open source version of Ansible Tower [Ansible AWX](https://github.com/ansible/awx) on a Centos 7. In future it will support the tower-cli for testing.
|
104
|
+
|
105
|
+
See example [https://github.com/neillturner/ansible_awx_repo](https://github.com/neillturner/ansible_awx_repo)
|
106
|
+
|
107
|
+
## Using Roles from Ansible Galaxy
|
108
|
+
|
109
|
+
Roles can be used from the Ansible Galaxy using two methods:
|
110
|
+
|
111
|
+
1. Specify a `requirements.yml` file in your Ansible repository. For more details see [here](http://docs.ansible.com/ansible/galaxy.html).
|
112
|
+
|
113
|
+
2. Use `librarian-ansible` by creating an `Ansiblefile` in the top level of the repository and `kitchen-ansible` will automatically call `librarian-ansible` during convergence. For a description of setting up an `Ansiblefile` see [here](https://werner-dijkerman.nl/2015/08/15/using-librarian-ansible-to-install-ansible-roles-from-gitlab/).
|
114
|
+
|
115
|
+
## Tips
|
116
|
+
|
117
|
+
To use a single ~/.kitchen/config.yml file with multiple reposities by setting the WORKSPACE environment variable:
|
118
|
+
|
119
|
+
```yaml
|
120
|
+
role_path: <%= ENV['WORKSPACE'] %>/roles
|
121
|
+
```
|
122
|
+
|
123
|
+
You can easily skip previous instructions and jump directly to the broken statement you just fixed by passing an environment variable. Add the following to your `.kitchen.yml`:
|
124
|
+
|
125
|
+
```yaml
|
126
|
+
provisioner:
|
127
|
+
name: ansible_playbook
|
128
|
+
ansible_extra_flags: <%= ENV['ANSIBLE_EXTRA_FLAGS'] %>
|
129
|
+
```
|
130
|
+
|
131
|
+
Then run:
|
132
|
+
|
133
|
+
```
|
134
|
+
$ ANSIBLE_EXTRA_FLAGS='--start-at-task="myrole | name of last working instruction"' kitchen converge
|
135
|
+
```
|
136
|
+
|
137
|
+
You save a lot of time not running working instructions.
|
138
|
+
|
139
|
+
|
140
|
+
## Ruby install to run Serverspec verify
|
141
|
+
|
142
|
+
By default test-kitchen installs Chef to get a Ruby version suitable to run Serverspec in the `verify` step.
|
143
|
+
kitchen-verifier-serverspec installs its own ruby version so chef or ruby is not required to verify with serverspec :
|
144
|
+
|
145
|
+
```yaml
|
146
|
+
require_chef_for_busser: false
|
147
|
+
```
|
148
|
+
And set the verifier section:
|
149
|
+
```yaml
|
150
|
+
verifier:
|
151
|
+
name: serverspec
|
152
|
+
sudo_path: true
|
153
|
+
|
154
|
+
suites:
|
155
|
+
- name: ansible
|
156
|
+
driver_config:
|
157
|
+
hostname: '54.229.34.169'
|
158
|
+
verifier:
|
159
|
+
patterns:
|
160
|
+
- roles/tomcat/spec/tomcat_spec.rb
|
161
|
+
bundler_path: '/usr/local/bin'
|
162
|
+
rspec_path: '/usr/local/bin'
|
163
|
+
env_vars:
|
164
|
+
TARGET_HOST: 54.229.104.40
|
165
|
+
LOGIN_USER: centos
|
166
|
+
SUDO: true
|
167
|
+
SSH_KEY: spec/test.pem
|
168
|
+
```
|
169
|
+
|
170
|
+
Please see the [Provisioner Options](https://github.com/neillturner/kitchen-ansible/blob/master/provisioner_options.md) for a complete listing.
|
171
|
+
|
172
|
+
## Test-Kitchen Ansiblespec
|
173
|
+
|
174
|
+
By using kitchen-verifier-serverspec and the Runner ansiblespec_runner tests can be run against multiple servers with multiple roles in the ansiblespec format.
|
175
|
+
|
176
|
+
Serverspec uses ssh to communicate with the server to be tested and reads the Ansible playbook and inventory files to determine the hosts to test and the roles for each host.
|
177
|
+
|
178
|
+
See example [https://github.com/neillturner/ansible_ansiblespec_repo](https://github.com/neillturner/ansible_ansiblespec_repo)
|
179
|
+
|
180
|
+
### Example usage to create Tomcat servers:
|
181
|
+
|
182
|
+
![test-kitchen, Ansible and ansiblespec](https://github.com/neillturner/ansible_repo/blob/master/kitchen-ansible.png "test-kitchen, ansible and ansiblespec")
|
183
|
+
|
184
|
+
See [ansible-sample-tdd](https://github.com/volanja/ansible-sample-tdd).
|
185
|
+
|
186
|
+
### Usage
|
187
|
+
|
188
|
+
#### Directory
|
189
|
+
|
190
|
+
In the Ansible repository specify:
|
191
|
+
|
192
|
+
* spec files with the roles.
|
193
|
+
* spec_helper in the spec folder (with code as below).
|
194
|
+
|
195
|
+
```
|
196
|
+
.
|
197
|
+
+-- roles
|
198
|
+
¦ +-- mariadb
|
199
|
+
¦ ¦ +-- spec
|
200
|
+
¦ ¦ ¦ +-- mariadb_spec.rb
|
201
|
+
¦ ¦ +-- tasks
|
202
|
+
¦ ¦ ¦ +-- main.yml
|
203
|
+
¦ ¦ +-- templates
|
204
|
+
¦ ¦ +-- mariadb.repo
|
205
|
+
¦ +-- nginx
|
206
|
+
¦ +-- handlers
|
207
|
+
¦ ¦ +-- main.yml
|
208
|
+
¦ +-- spec
|
209
|
+
¦ ¦ +-- nginx_spec.rb
|
210
|
+
¦ +-- tasks
|
211
|
+
¦ ¦ +-- main.yml
|
212
|
+
¦ +-- templates
|
213
|
+
¦ ¦ +-- nginx.repo
|
214
|
+
¦ +-- vars
|
215
|
+
¦ +-- main.yml
|
216
|
+
+-- spec
|
217
|
+
+-- spec_helper.rb
|
218
|
+
+-- my_private_key.pem
|
219
|
+
```
|
220
|
+
|
221
|
+
|
222
|
+
#### spec_helper
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
require 'rubygems'
|
226
|
+
require 'bundler/setup'
|
227
|
+
|
228
|
+
require 'serverspec'
|
229
|
+
require 'pathname'
|
230
|
+
require 'net/ssh'
|
231
|
+
|
232
|
+
RSpec.configure do |config|
|
233
|
+
set :host, ENV['TARGET_HOST']
|
234
|
+
# ssh options at http://net-ssh.github.io/ssh/v1/chapter-2.html
|
235
|
+
# ssh via password
|
236
|
+
set :ssh_options, :user => ENV['LOGIN_USER'], :paranoid => false, :verbose => :error, :password => ENV['LOGIN_PASSWORD'] if ENV['LOGIN_PASSWORD']
|
237
|
+
# ssh via ssh key
|
238
|
+
set :ssh_options, :user => ENV['LOGIN_USER'], :paranoid => false, :verbose => :error, :host_key => 'ssh-rsa', :keys => [ ENV['SSH_KEY'] ] if ENV['SSH_KEY']
|
239
|
+
set :backend, :ssh
|
240
|
+
set :request_pty, true
|
241
|
+
end
|
242
|
+
```
|
243
|
+
|
244
|
+
See [kitchen-verifier-serverspec](https://github.com/neillturner/kitchen-verifier-serverspec).
|
245
|
+
|
246
|
+
## Alternative Virtualization/Cloud providers for Vagrant
|
247
|
+
This could be adapted to use alternative virtualization/cloud providers such as Openstack/AWS/VMware Fusion according to whatever is supported by Vagrant.
|
248
|
+
```yaml
|
249
|
+
platforms:
|
250
|
+
- name: ubuntu-12.04
|
251
|
+
driver_config:
|
252
|
+
provider: aws
|
253
|
+
box: my_base_box
|
254
|
+
# username is based on what is configured in your box/ami
|
255
|
+
username: ubuntu
|
256
|
+
customize:
|
257
|
+
access_key_id: 'AKKJHG659868LHGLH'
|
258
|
+
secret_access_key: 'G8t7o+6HLG876JGF/58'
|
259
|
+
ami: ami-7865ab765d
|
260
|
+
instance_type: t2.micro
|
261
|
+
# more customisation can go here, based on what the vagrant provider supports
|
262
|
+
#security-groups: []
|
263
|
+
```
|
264
|
+
|
265
|
+
## Notes
|
266
|
+
|
267
|
+
* The `default` in all of the above is the name of the test suite defined in the `suites` section of your `.kitchen.yml`, so if you have more than one suite of tests or change the name, you'll need to adapt the example accordingly.
|
268
|
+
* Serverspec test files *must* be named `_spec.rb`
|
269
|
+
* Since I'm using Vagrant, my `box` definitions refer to Vagrant boxes, either standard, published boxes available from [Atlas](http://atlas.hashicorp.com/boxes) or custom-created boxes (perhaps using [Packer](http://packer.io) and [bento](https://github.com/chef/bento), in which case you'll need to provide the URL in `box_url`.
|
270
|
+
|