kitchen-ansible 0.0.33 → 0.0.34

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b4d280df66920431cf01969f165457c8e884fc2
4
- data.tar.gz: a9a62abb6f496d3d862f0a30776f4642ed739822
3
+ metadata.gz: 383772e19dae10c7d068e546b69d07d6953ee1a2
4
+ data.tar.gz: 7a40e84ce0e131f6cb6bfefa4798ebea0a5ec637
5
5
  SHA512:
6
- metadata.gz: e2c4d149b73a3959c182003b11cf28414f05f3fdad19d92d46876cbcf161142ae05b14a2dc5f5a2486995fc6dc73759a0dd7ed4a553dc82331aa6512acf62990
7
- data.tar.gz: eda4854cba439e31bbbe4c6bdb388088343ca62970950123e0843e2ed1a87d31b469cffd4a36750f46c6bd7bca7c7fc09a7c396b86fdaa8a29a3098232f1e86d
6
+ metadata.gz: f20a609cbc3b8032e0d04717b8ce2eb87fc341d354db705f16252105ba992cb86c2f71c87b94908f4db3e6d7d3d729878569f6684d7ac6cb2d494b05c1193172
7
+ data.tar.gz: 50dbedb9520c1527a94341eecd0f20ffa19417e00b563d98fdec33ded9312a866cd4260e04b561573bc19e8bb02e04a380305731221220c7f6bd44807fdd4153
data/README.md CHANGED
@@ -4,25 +4,29 @@
4
4
  [![Gem Downloads](http://ruby-gem-downloads-badge.herokuapp.com/kitchen-ansible?type=total&color=brightgreen)](https://rubygems.org/gems/kitchen-ansible)
5
5
  [![Build Status](https://travis-ci.org/neillturner/kitchen-ansible.png)](https://travis-ci.org/neillturner/kitchen-ansible)
6
6
 
7
- A Test Kitchen Provisioner for Ansible
7
+ A Test Kitchen Provisioner for Ansible.
8
8
 
9
9
  The provisioner works by passing the ansible repository based on attributes in `.kitchen.yml` & calling `ansible-playbook`.
10
10
 
11
11
  It installs Ansible on the server and runs `ansible-playbook` using host localhost.
12
12
 
13
- Has been tested against the Ubuntu 12.04 and Centos 6.5 boxes running in vagrant/virtualbox.
13
+ It has been tested against the Ubuntu 12.04, Ubuntu 14.04, Centos 6.5 and Debian 6/7/8 boxes running in vagrant/virtualbox.
14
14
 
15
15
  ## Requirements
16
- You'll need a driver box without a chef installation so ansible can be installed.
16
+ - [test-kitchen](https://github.com/test-kitchen/test-kitchen)
17
+ - a driver box without a chef installation so ansible can be installed.
17
18
 
18
19
  ## Installation & Setup
19
- You'll need the test-kitchen & kitchen-ansible gems installed in your system, along with [kitchen-vagrant](https://github.com/test-kitchen/kitchen-vagrant) or some other suitable driver for test-kitchen.
20
+ Install the kitchen-ansible gem in your system, along with [kitchen-vagrant](https://github.com/test-kitchen/kitchen-vagrant) or some other suitable driver for test-kitchen:
20
21
 
21
- Please see the Provisioner Options (https://github.com/neillturner/kitchen-ansible/blob/master/provisioner_options.md).
22
+ ```
23
+ gem install kitchen-ansible
24
+ gem install kitchen-vagrant
25
+ ```
22
26
 
23
27
  ## Example kitchen.yml file
24
28
 
25
- based on the example ansible setup for tomcat at https://github.com/ansible/ansible-examples/tree/master/tomcat-standalone
29
+ Based on the example ansible setup for tomcat at https://github.com/ansible/ansible-examples/tree/master/tomcat-standalone
26
30
 
27
31
  ```yaml
28
32
  ---
@@ -35,7 +39,7 @@ provisioner:
35
39
  hosts: tomcat-servers
36
40
  require_ansible_repo: true
37
41
  ansible_verbose: true
38
- ansible_version: 1.6.2-1.el6
42
+ ansible_version: latest
39
43
  extra_vars:
40
44
  a: b
41
45
 
@@ -48,188 +52,164 @@ platforms:
48
52
  network:
49
53
  - ['forwarded_port', {guest: 8080, host: 8080}]
50
54
  - [ 'private_network', { ip: '192.168.33.11' } ]
51
-
52
- verifier:
53
- ruby_bindir: '/usr/bin'
54
55
  ```
55
- **NOTE:** With Test-Kitchen 1.4 you no longer need chef install to run the tests. You just need ruby installed version 1.9 or higher and also add to the `.kitchen.yml` file
56
56
 
57
- ```yaml
58
- provisioner:
59
- name: ansible_playbook
60
- hosts: test-kitchen
61
- require_chef_for_busser: false
62
- require_ruby_for_busser: true
57
+ ## Ruby install to run serverspec verify
58
+
59
+ By default test-kitchen installs chef to get a ruby version sutable for run serverspec in the Verify step.
63
60
 
61
+ Instead ruby can just be installed by specifing the provisioner option:
62
+ ```
63
+ require_ruby_for_busser false
64
+ ```
65
+ And set the verifer section:
66
+ ```
64
67
  verifier:
68
+ name: Busser
69
+ plugin:
70
+ - Ansiblespec
65
71
  ruby_bindir: '/usr/bin'
66
72
  ```
67
- where `/usr/bin` is the location of the ruby command.
68
-
69
-
70
- ## Test-Kitchen Serverspec
71
-
72
- To run the verify step with the test-kitchen serverspec setup your ansible repository as follows:
73
-
74
- NOTE: See https://github.com/delphix/ansible-package-caching-proxy for an example.
73
+ and create a Gemfile to add additionl ruby gems in directory test/integration/default/ansiblespec
74
+ ```
75
+ source 'https://rubygems.org'
75
76
 
76
- In the root directory for your Ansible role:
77
+ gem 'rake'
78
+ ```
77
79
 
78
- Create a `.kitchen.yml`, much like one the described above:
80
+ Please see the [Provisioner Options](https://github.com/neillturner/kitchen-ansible/blob/master/provisioner_options.md) for a complete listing.
79
81
 
80
- ```yaml
81
- ---
82
- driver:
83
- name: vagrant
84
82
 
85
- provisioner:
86
- name: ansible_playbook
87
- playbook: default.yml
88
- ansible_yum_repo: "https://download.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm"
89
- ansible_verbose: true
90
- ansible_verbosity: 3
91
- hosts: all
83
+ ## Test-Kitchen Ansiblespec
92
84
 
93
- platforms:
94
- - name: ubuntu-12.04
95
- driver_config:
96
- box: ubuntu/precise32
97
- - name: centos-7
98
- driver_config:
99
- box: chef/centos-7.0
85
+ This can run tests against multiple servers with multiple roles in any of three formats:
100
86
 
101
- verifier:
102
- ruby_bindir: '/usr/bin'
87
+ * ansiblespec - tests are specified with the roles in the ansible repository. (default)
88
+ * serverspec - tests are in test-kitchen serverspec format
89
+ * spec - tests are stored in the spec directory with a directory for each role.
103
90
 
104
- suites:
105
- - name: default
106
- ```
91
+ 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.
107
92
 
108
- Then for serverspec:
93
+ - Set pattern: 'serverspec' in the config.yml file (see below) to perform tests in test-kitchen serverspec format.
94
+ (See https://github.com/delphix/ansible-package-caching-proxy for an example of using test-kitchen serverspec).
95
+ - Set pattern: 'spec' in the config.yml file (see below) to perform tests in for roles specified in the spec directory.
96
+ - By default pattern: ansiblespec is set. See example [https://github.com/neillturner/ansible_repo](https://github.com/neillturner/ansible_repo)
109
97
 
110
- ```bash
111
- mkdir -p test/integration/default/serverspec/localhost
112
- echo "require 'serverspec'" >> test/integration/default/serverspec/spec_helper.rb
113
- echo "set :backend, :exec" >> test/integration/default/serverspec/spec_helper.rb
114
- ```
115
98
 
116
- Create a basic playbook `test/integration/default.yml` so that kitchen can use your role (this should include any dependencies for your role):
99
+ ### Example usage to create tomcat servers:
117
100
 
118
- ```yaml
119
- ---
120
- - name: wrapper playbook for kitchen testing "my_role"
121
- hosts: localhost
122
- roles:
123
- - my_role
124
101
  ```
102
+ TOMCAT SERVERS
103
+ TEST KITCHEN ANSIBLE AND SERVERSPEC
104
+ WORKSTATION SERVER +------------------------+
105
+ +-----------------------+ | +---------+ |
106
+ | | | |Tomcat | |
107
+ +-------------------+ | +----------------> | | |
108
+ | | | | | | +---------+ |
109
+ | Workstation | | | | +-------> |
110
+ | test-kitchen | | | | | | |
111
+ | kitchen-ansible| | | | | | |
112
+ | | create| | | | +------------------------+
113
+ | CREATE +---------------> install | | |
114
+ | | server| and run | | |
115
+ | CONVERGE+-------------------->ANSIBLE +---+ | | +------------------------+
116
+ | | | +--------------------> +----------+ |
117
+ | | | install and run | | | |Tomcat | |
118
+ | VERIFY+------------------>Busser-ansiblespec +-------+ | | | |
119
+ +-------------------+ | + | | | +----------+ |
120
+ | +--->ServerSpec +---------------> |
121
+ | | | |
122
+ +-----------------------+ | |
123
+ +------------------------+
124
+
125
+
126
+ * All connections over SSH
125
127
 
126
- Create your serverspec tests in `test/integration/default/serverspec/localhost/my_roles_spec.rb`:
127
-
128
- ```ruby
129
- require 'spec_helper'
130
-
131
- if os[:family] == 'ubuntu'
132
- describe '/etc/lsb-release' do
133
- it "exists" do
134
- expect(file('/etc/lsb-release')).to be_file
135
- end
136
- end
137
- end
138
-
139
- if os[:family] == 'redhat'
140
- describe '/etc/redhat-release' do
141
- it "exists" do
142
- expect(file('/etc/redhat-release')).to be_file
143
- end
144
- end
145
- end
146
128
  ```
147
129
 
148
- ## Test-Kitchen Ansiblespec
130
+ See [ansible-sample-tdd](https://github.com/volanja/ansible-sample-tdd)
149
131
 
150
- test-kitchen normally uses tests setup in `test/integration/....` directory. Ansiblespec format puts the tests with the
151
- roles in the ansible repository and the spec helper is specified in the ansible repository under the spec directory.
132
+ ### Usage
152
133
 
153
- To implement this with test-kitchen setup the ansible repository with:
134
+ #### Directory
154
135
 
155
- * the spec files with the roles.
136
+ In the ansible repository specify:
156
137
 
157
- * the spec_helper in the spec folder.
158
-
159
- * a dummy `test/integration/<suite>/ansiblespec/localhost/<suite>_spec.rb` containing just a dummy comment.
160
-
161
- See example [https://github.com/neillturner/ansible_repo](https://github.com/neillturner/ansible_repo)
138
+ * spec files with the roles.
139
+ * spec_helper in the spec folder (with code as below).
140
+ * test/integration/<suite>/ansiblespec containing config.yml and ssh private keys to access the servers.
162
141
 
163
142
  ```
164
143
  .
165
144
  +-- roles
166
- ��� +-- mariadb
167
- ��� ��� +-- spec
168
- ��� ��� ��� +-- mariadb_spec.rb
169
- ��� ��� +-- tasks
170
- ��� ��� ��� +-- main.yml
171
- ��� ��� +-- templates
172
- ��� ��� +-- mariadb.repo
173
- ��� +-- nginx
174
- ��� +-- handlers
175
- ��� ��� +-- main.yml
176
- ��� +-- spec
177
- ��� ��� +-- nginx_spec.rb
178
- ��� +-- tasks
179
- ��� ��� +-- main.yml
180
- ��� +-- templates
181
- ��� ��� +-- nginx.repo
182
- ��� +-- vars
183
- ��� +-- main.yml
145
+ ¦   +-- mariadb
146
+ ¦   ¦   +-- spec
147
+ ¦   ¦   ¦   +-- mariadb_spec.rb
148
+ ¦   ¦   +-- tasks
149
+ ¦   ¦   ¦   +-- main.yml
150
+ ¦   ¦   +-- templates
151
+ ¦   ¦   +-- mariadb.repo
152
+ ¦   +-- nginx
153
+ ¦   +-- handlers
154
+ ¦   ¦   +-- main.yml
155
+ ¦   +-- spec
156
+ ¦   ¦   +-- nginx_spec.rb
157
+ ¦   +-- tasks
158
+ ¦   ¦   +-- main.yml
159
+ ¦   +-- templates
160
+ ¦   ¦   +-- nginx.repo
161
+ ¦   +-- vars
162
+ ¦   +-- main.yml
184
163
  +-- spec
185
164
  +-- spec_helper.rb
165
+ +-- my_private_key.pem
186
166
  +-- test
187
167
  +-- integration
188
168
  +-- default # name of test-kitchen suite
189
169
  +-- ansiblespec
190
- +-- localhost
191
- +-- default_spec.rb # <suite>_spec.rb
170
+ +-- config.yml
171
+
192
172
  ```
193
173
 
194
- In the root directory for your Ansible role create a `.kitchen.yml`, the same as for test-kitchen serverspec above.
195
174
 
196
- When test-kitchen runs the verify step will
197
- * detect the dummy `/test/integration/<suite>/ansiblespec` directory
198
- * install the busser-ansiblespec plugin instead of the normal busser-serverspec plugin
199
- * serverspec will be called using the ansiblespec conventions.
200
- * tests will run against all the roles in the playbook.
175
+ #### spec_helper
201
176
 
202
- See [busser-ansiblespec](https://github.com/neillturner/busser-ansiblespec)
177
+ ```
178
+ require 'rubygems'
179
+ require 'bundler/setup'
180
+
181
+ require 'serverspec'
182
+ require 'pathname'
183
+ require 'net/ssh'
184
+
185
+ RSpec.configure do |config|
186
+ set :host, ENV['TARGET_HOST']
187
+ # ssh via password
188
+ set :ssh_options, :user => 'root', :password => ENV['LOGIN_PASSWORD'] if ENV['LOGIN_PASSWORD']
189
+ # ssh via ssh key
190
+ set :ssh_options, :user => 'root', :host_key => 'ssh-rsa', :keys => [ ENV['SSH_KEY'] ] if ENV['SSH_KEY']
191
+ set :backend, :ssh
192
+ set :request_pty, true
193
+ end
194
+ ```
203
195
 
196
+ #### config.yml
204
197
 
205
- ## Testing multiple playbooks
206
- To test different playbooks in different suites you can easily overwrite the provisioner settings in each suite seperately.
207
- ```yaml
198
+ This goes in directory test/integration/default/ansiblespec where default is the name of test-kitchen suite.
199
+
200
+ ```
208
201
  ---
209
- driver:
210
- name: vagrant
202
+ -
203
+ playbook: default.yml
204
+ inventory: hosts
205
+ kitchen_path: '/tmp/kitchen'
206
+ pattern: 'ansiblespec' # or spec or serverspec
207
+ ssh_key: 'spec/my_private_key.pem'
208
+ login_password: 'myrootpassword'
209
+ ```
211
210
 
212
- provisioner:
213
- name: ansible_playbook
211
+ See [busser-ansiblespec](https://github.com/neillturner/busser-ansiblespec)
214
212
 
215
- platforms:
216
- - name: ubuntu-12.04
217
- driver_config:
218
- box: ubuntu/precise32
219
- - name: centos-7
220
- driver_config:
221
- box: chef/centos-7.0
222
-
223
- suites:
224
- - name: database
225
- provisioner:
226
- playbook: postgres.yml
227
- hosts: database
228
- - name: application
229
- provisioner:
230
- playbook: web_app.yml
231
- hosts: web_application
232
- ```
233
213
  ## Alternative Virtualization/Cloud providers for Vagrant
234
214
  This could be adapted to use alternative virtualization/cloud providers such as Openstack/AWS/VMware Fusion according to whatever is supported by Vagrant.
235
215
  ```yaml
@@ -249,9 +229,9 @@ platforms:
249
229
  #security-groups: []
250
230
  ```
251
231
 
252
- *Notes*
232
+ ## Notes
253
233
 
254
- * 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 suite of tests or change the name, you'll need to adapt my example accordingly.
234
+ * 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 suite of tests or change the name, you'll need to adapt the example accordingly.
255
235
  * serverspec test files *must* be named `_spec.rb`
256
236
  * Since I'm using Vagrant, my `box` definitions refer to Vagrant boxes, either standard, published boxes available from <http://atlas.hashicorp.com/boxes> or custom-created boxes (perhaps using [Packer][packer] and [bento][bento]), in which case you'll need to provide the url in `box_url`.
257
237
 
@@ -263,7 +243,7 @@ platforms:
263
243
  ## Tips
264
244
 
265
245
  You can easily skip previous instructions and jump directly to the broken statement you just fixed by passing
266
- an environment variable. Add folloing to your .kitchen.yml
246
+ an environment variable. Add the following to your `.kitchen.yml`:
267
247
 
268
248
  ```yaml
269
249
  provisioner:
@@ -271,8 +251,8 @@ provisioner:
271
251
  ansible_extra_flags: <%= ENV['ANSIBLE_EXTRA_FLAGS'] %>
272
252
  ```
273
253
 
274
- run:
254
+ Then run:
275
255
 
276
256
  `ANSIBLE_EXTRA_FLAGS='--start-at-task="myrole | name of last working instruction"' kitchen converge`
277
257
 
278
- You save a LOT of time not running working instructions.
258
+ You save a lot of time not running working instructions.
@@ -1,17 +1,17 @@
1
1
  # encoding: utf-8
2
2
 
3
- $:.unshift File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
4
  require 'kitchen-ansible/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "kitchen-ansible"
8
- s.license = "Apache-2.0"
7
+ s.name = 'kitchen-ansible'
8
+ s.license = 'Apache-2.0'
9
9
  s.version = Kitchen::Ansible::VERSION
10
- s.authors = ["Neill Turner"]
11
- s.email = ["neillwturner@gmail.com"]
12
- s.homepage = "https://github.com/neillturner/kitchen-ansible"
13
- s.summary = "ansible provisioner for test-kitchen"
14
- candidates = Dir.glob("{lib}/**/*") + ['README.md', 'provisioner_options.md', 'kitchen-ansible.gemspec']
10
+ s.authors = ['Neill Turner']
11
+ s.email = ['neillwturner@gmail.com']
12
+ s.homepage = 'https://github.com/neillturner/kitchen-ansible'
13
+ s.summary = 'ansible provisioner for test-kitchen'
14
+ candidates = Dir.glob('{lib}/**/*') + ['README.md', 'provisioner_options.md', 'kitchen-ansible.gemspec']
15
15
  s.files = candidates.sort
16
16
  s.platform = Gem::Platform::RUBY
17
17
  s.require_paths = ['lib']
@@ -1,5 +1,6 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  module Kitchen
2
3
  module Ansible
3
- VERSION = "0.0.33"
4
+ VERSION = '0.0.34'
4
5
  end
5
6
  end
@@ -20,9 +20,7 @@
20
20
  require 'json'
21
21
 
22
22
  module Kitchen
23
-
24
23
  module Provisioner
25
-
26
24
  module Ansible
27
25
  #
28
26
  # Ansible Playbook provisioner.
@@ -30,6 +28,7 @@ module Kitchen
30
28
  class Config
31
29
  include Kitchen::Configurable
32
30
 
31
+ attr_writer :instance
33
32
  attr_reader :instance
34
33
 
35
34
  default_config :ansible_sudo, true
@@ -42,11 +41,11 @@ module Kitchen
42
41
  default_config :enable_yum_epel, false
43
42
  default_config :extra_vars, {}
44
43
  default_config :tags, []
45
- default_config :ansible_apt_repo, "ppa:ansible/ansible"
46
- default_config :ansible_yum_repo, "https://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm"
47
- default_config :ansible_sles_repo, "http://download.opensuse.org/repositories/systemsmanagement/SLE_12/systemsmanagement.repo"
48
- default_config :python_sles_repo, "http://download.opensuse.org/repositories/devel:/languages:/python/SLE_12/devel:languages:python.repo"
49
- default_config :chef_bootstrap_url, "https://www.getchef.com/chef/install.sh"
44
+ default_config :ansible_apt_repo, 'ppa:ansible/ansible'
45
+ default_config :ansible_yum_repo, 'https://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm'
46
+ default_config :ansible_sles_repo, 'http://download.opensuse.org/repositories/systemsmanagement/SLE_12/systemsmanagement.repo'
47
+ default_config :python_sles_repo, 'http://download.opensuse.org/repositories/devel:/languages:/python/SLE_12/devel:languages:python.repo'
48
+ default_config :chef_bootstrap_url, 'https://www.getchef.com/chef/install.sh'
50
49
  # Until we can truly make busser work without /opt/chef/embedded/bin/gem being installed, we still need Chef Omnibus
51
50
  # (Reference: https://github.com/neillturner/kitchen-ansible/issues/66 )
52
51
  default_config :require_chef_for_busser, true
@@ -65,15 +64,18 @@ module Kitchen
65
64
  default_config :https_proxy, nil
66
65
  default_config :no_proxy, nil
67
66
  default_config :ansible_playbook_command, nil
67
+ default_config :ansible_host_key_checking, false
68
+ default_config :set_private_key_permissions, false
69
+ default_config :idempotency_test, nil
68
70
 
69
71
  default_config :playbook do |provisioner|
70
- provisioner.calculate_path('default.yml', :file) or
71
- raise "No playbook found or specified! Please either set a playbook in your .kitchen.yml config, or create a default wrapper playbook for your role in test/integration/playbooks/default.yml or test/integration/default.yml"
72
+ provisioner.calculate_path('default.yml', :file) ||
73
+ fail('No playbook found or specified! Please either set a playbook in your .kitchen.yml config, or create a default wrapper playbook for your role in test/integration/playbooks/default.yml or test/integration/default.yml')
72
74
  end
73
75
 
74
76
  default_config :roles_path do |provisioner|
75
- provisioner.calculate_path('roles') or
76
- raise 'No roles_path detected. Please specify one in .kitchen.yml'
77
+ provisioner.calculate_path('roles') ||
78
+ fail('No roles_path detected. Please specify one in .kitchen.yml')
77
79
  end
78
80
 
79
81
  default_config :group_vars_path do |provisioner|
@@ -124,10 +126,6 @@ module Kitchen
124
126
  init_config(config)
125
127
  end
126
128
 
127
- def set_instance(instance)
128
- @instance = instance
129
- end
130
-
131
129
  def []=(attr, val)
132
130
  config[attr] = val
133
131
  end
@@ -137,7 +135,7 @@ module Kitchen
137
135
  end
138
136
 
139
137
  def key?(k)
140
- return config.key?(k)
138
+ config.key?(k)
141
139
  end
142
140
 
143
141
  def keys
@@ -145,9 +143,8 @@ module Kitchen
145
143
  end
146
144
 
147
145
  def calculate_path(path, type = :directory)
148
-
149
- if not instance
150
- raise "Please ensure that an instance is provided before calling calculate_path"
146
+ unless instance
147
+ fail 'Please ensure that an instance is provided before calling calculate_path'
151
148
  end
152
149
 
153
150
  base = config[:test_base_path]
@@ -162,11 +159,7 @@ module Kitchen
162
159
  type == :directory ? File.directory?(c) : File.file?(c)
163
160
  end
164
161
  end
165
-
166
-
167
162
  end
168
-
169
163
  end
170
164
  end
171
-
172
165
  end