kitchen-ansible 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Kitchen
2
2
  module Ansible
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -50,7 +50,9 @@ module Kitchen
50
50
  default_config :ansible_yum_repo, "https://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm"
51
51
  default_config :chef_bootstrap_url, "https://www.getchef.com/chef/install.sh"
52
52
 
53
- default_config :playbook, 'site.yml'
53
+ default_config :playbook do |provisioner|
54
+ provisioner.calculate_path('site.yml', :file)
55
+ end
54
56
 
55
57
  default_config :roles_path do |provisioner|
56
58
  provisioner.calculate_path('roles') or
@@ -74,24 +76,39 @@ module Kitchen
74
76
  end
75
77
 
76
78
  default_config :ansible_verbose, false
77
- default_config :ansible_noop, false # what is ansible equivalent of dry_run????
79
+ default_config :ansible_verbosity, 1
80
+ default_config :ansible_noop, false # what is ansible equivalent of dry_run???? ##JMC: I think it's [--check mode](http://docs.ansible.com/playbooks_checkmode.html) TODO: Look into this...
78
81
  default_config :ansible_platform, ''
79
82
  default_config :update_package_repos, true
80
83
 
84
+ def verbosity_level(level = 1)
85
+ level = level.to_sym if level.is_a? String
86
+ log_levels = { :info => 1, :warn => 2, :debug => 3, :trace => 4 }
87
+ if level.is_a? Symbol and log_levels.include? level
88
+ # puts "Log Level is: #{log_levels[level]}"
89
+ log_levels[level]
90
+ elsif level.is_a? Integer and level > 0
91
+ # puts "Log Level is: #{level}"
92
+ level
93
+ else
94
+ raise 'Invalid ansible_verbosity setting. Valid values are: 1, 2, 3, 4 OR :info, :warn, :debug, :trace'
95
+ end
96
+ end
81
97
 
82
-
83
- # def calculate_path(path, type = :directory)
84
- # base = config[:test_base_path]
85
- # candidates = []
86
- # candidates << File.join(base, instance.suite.name, 'ansible', path)
87
- # candidates << File.join(base, instance.suite.name, path)
88
- # candidates << File.join(base, path)
89
- # candidates << File.join(Dir.pwd, path)
90
- #
91
- # candidates.find do |c|
92
- # type == :directory ? File.directory?(c) : File.file?(c)
93
- # end
94
- # end
98
+ def calculate_path(path, type = :directory)
99
+ base = config[:test_base_path]
100
+ candidates = []
101
+ candidates << File.join(base, instance.suite.name, 'ansible', path)
102
+ candidates << File.join(base, instance.suite.name, path)
103
+ candidates << File.join(base, path)
104
+ candidates << File.join(Dir.pwd, path)
105
+ candidates << File.join(Dir.pwd) if path == 'roles'
106
+
107
+ debug("Calculating path for #{path}, candidates are: #{candidates.to_s}")
108
+ candidates.find do |c|
109
+ type == :directory ? File.directory?(c) : File.file?(c)
110
+ end
111
+ end
95
112
 
96
113
  def install_command
97
114
  return unless config[:require_ansible_omnibus] or config[:require_ansible_repo]
@@ -118,14 +135,29 @@ module Kitchen
118
135
  info("Installing ansible on #{ansible_platform}")
119
136
  <<-INSTALL
120
137
  if [ ! $(which ansible) ]; then
138
+ ## Install apt-utils to silence debconf warning: http://serverfault.com/q/358943/77156
139
+ #{sudo('apt-get')} -y install apt-utils
140
+ ## Fix debconf tty warning messages
141
+ export DEBIAN_FRONTEND=noninteractive
142
+ ## 13.10, 14.04 include add-apt-repository in software-properties-common
143
+ #{sudo('apt-get')} -y install software-properties-common
144
+ ## 10.04, 12.04 include add-apt-repository in
145
+ #{sudo('apt-get')} -y install python-software-properties
121
146
  # #{sudo('wget')} #{ansible_apt_repo}
122
147
  # #{sudo('dpkg')} -i #{ansible_apt_repo_file}
148
+ # #{sudo('apt-get')} -y autoremove ## These autoremove/autoclean are sometimes useful but
149
+ # #{sudo('apt-get')} -y autoclean ## don't seem necessary for the Ubuntu OpsCode bento boxes that are not EOL by Canonical
123
150
  # #{update_packages_debian_cmd}
124
- # #{sudo('apt-get')} -y install ansible#{ansible_debian_version}
125
- #{sudo('add-apt-repository')} #{ansible_apt_repo}
126
- #{sudo('apt-get')} update
151
+ # #{sudo('apt-get')} -y --force-yes install ansible#{ansible_debian_version} python-selinux
152
+ ## 10.04 version of add-apt-repository doesn't accept --yes
153
+ ## later versions require interaction from user, so we must specify --yes
154
+ ## First try with -y flag, else if it fails, try without.
155
+ ## "add-apt-repository: error: no such option: -y" is returned but is ok to ignore, we just retry
156
+ #{sudo('add-apt-repository')} -y #{ansible_apt_repo} || #{sudo('add-apt-repository')} #{ansible_apt_repo}
157
+ #{sudo('apt-get')} update
127
158
  #{sudo('apt-get')} -y install ansible
128
-
159
+ ## This test works on ubuntu to test if ansible repo has been installed via rquillo ppa repo
160
+ ## if [ $(apt-cache madison ansible | grep -c rquillo ) -gt 0 ]; then echo 'success'; else echo 'fail'; fi
129
161
  fi
130
162
  #{install_busser}
131
163
  INSTALL
@@ -135,7 +167,7 @@ module Kitchen
135
167
  if [ ! $(which ansible) ]; then
136
168
  #{sudo('rpm')} -ivh #{ansible_yum_repo}
137
169
  #{update_packages_redhat_cmd}
138
- #{sudo('yum')} -y install ansible#{ansible_redhat_version}
170
+ #{sudo('yum')} -y install ansible#{ansible_redhat_version} libselinux-python
139
171
  fi
140
172
  #{install_busser}
141
173
  INSTALL
@@ -146,15 +178,31 @@ module Kitchen
146
178
  if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then
147
179
  #{sudo('rpm')} -ivh #{ansible_yum_repo}
148
180
  #{update_packages_redhat_cmd}
149
- #{sudo('yum')} -y install ansible#{ansible_redhat_version}
181
+ #{sudo('yum')} -y install ansible#{ansible_redhat_version} libselinux-python
150
182
  else
151
- # #{sudo('wget')} #{ansible_apt_repo}
152
- # #{sudo('dpkg')} -i #{ansible_apt_repo_file}
153
- # #{update_packages_debian_cmd}
154
- # #{sudo('apt-get')} -y install ansible#{ansible_debian_version}
155
- #{sudo('add-apt-repository')} #{ansible_apt_repo}
156
- #{sudo('apt-get')} update
157
- #{sudo('apt-get')} -y install ansible#{ansible_debian_version}
183
+ ## Install apt-utils to silence debconf warning: http://serverfault.com/q/358943/77156
184
+ #{sudo('apt-get')} -y install apt-utils
185
+ ## Fix debconf tty warning messages
186
+ export DEBIAN_FRONTEND=noninteractive
187
+ ## 13.10, 14.04 include add-apt-repository in software-properties-common
188
+ #{sudo('apt-get')} -y install software-properties-common
189
+ ## 10.04, 12.04 include add-apt-repository in
190
+ #{sudo('apt-get')} -y install python-software-properties
191
+ # #{sudo('wget')} #{ansible_apt_repo}
192
+ # #{sudo('dpkg')} -i #{ansible_apt_repo_file}
193
+ # #{sudo('apt-get')} -y autoremove ## These autoremove/autoclean are sometimes useful but
194
+ # #{sudo('apt-get')} -y autoclean ## don't seem necessary for the Ubuntu OpsCode bento boxes that are not EOL by Canonical
195
+ # #{update_packages_debian_cmd}
196
+ # #{sudo('apt-get')} -y --force-yes install ansible#{ansible_debian_version} python-selinux
197
+ ## 10.04 version of add-apt-repository doesn't accept --yes
198
+ ## later versions require interaction from user, so we must specify --yes
199
+ ## First try with -y flag, else if it fails, try without.
200
+ ## "add-apt-repository: error: no such option: -y" is returned but is ok to ignore, we just retry
201
+ #{sudo('add-apt-repository')} -y #{ansible_apt_repo} || #{sudo('add-apt-repository')} #{ansible_apt_repo}
202
+ #{sudo('apt-get')} update
203
+ #{sudo('apt-get')} -y install ansible
204
+ ## This test works on ubuntu to test if ansible repo has been installed via rquillo ppa repo
205
+ ## if [ $(apt-cache madison ansible | grep -c rquillo ) -gt 0 ]; then echo 'success'; else echo 'fail'; fi
158
206
  fi
159
207
  fi
160
208
  #{install_busser}
@@ -238,7 +286,7 @@ module Kitchen
238
286
  "-M #{File.join(config[:root_path], 'modules')}",
239
287
  ansible_verbose_flag,
240
288
  extra_vars,
241
- "#{File.join(config[:root_path], config[:playbook])}",
289
+ "#{File.join(config[:root_path], File.basename(config[:playbook]))}",
242
290
  ].join(" ")
243
291
  end
244
292
 
@@ -251,10 +299,22 @@ module Kitchen
251
299
  end
252
300
  end
253
301
 
254
- def tmpmodules_dir
302
+ def tmp_modules_dir
255
303
  File.join(sandbox_path, 'modules')
256
304
  end
257
305
 
306
+ def tmp_playbook_path
307
+ File.join(sandbox_path, File.basename(playbook))
308
+ end
309
+
310
+ def tmp_host_vars_dir
311
+ File.join(sandbox_path, 'host_vars')
312
+ end
313
+
314
+ def tmp_roles_dir
315
+ File.join(sandbox_path, 'roles')
316
+ end
317
+
258
318
  def ansiblefile
259
319
  config[:ansiblefile_path] or ''
260
320
  end
@@ -271,6 +331,10 @@ module Kitchen
271
331
  config[:roles_path]
272
332
  end
273
333
 
334
+ def role_name
335
+ File.basename(roles) == 'roles' ? '' : File.basename(roles)
336
+ end
337
+
274
338
  def modules
275
339
  config[:modules_path]
276
340
  end
@@ -292,7 +356,7 @@ module Kitchen
292
356
  end
293
357
 
294
358
  def ansible_verbose_flag
295
- config[:ansible_verbose] ? '-v' : nil
359
+ config[:ansible_verbose] ? '-' << ('v' * verbosity_level(config[:ansible_verbosity])) : nil
296
360
  end
297
361
 
298
362
  def ansible_platform
@@ -309,8 +373,8 @@ module Kitchen
309
373
 
310
374
  def extra_vars
311
375
  return nil if config[:extra_vars].none?
312
- bash_vars = config[:extra_vars].map { |k,v| "#{k}=#{v}" }.join(" ")
313
- bash_vars = "-e \"#{bash_vars}\""
376
+ bash_vars = JSON.dump(config[:extra_vars])
377
+ bash_vars = "-e '#{bash_vars}'"
314
378
  debug(bash_vars)
315
379
  bash_vars
316
380
  end
@@ -334,10 +398,12 @@ module Kitchen
334
398
  def prepare_roles
335
399
  info('Preparing roles')
336
400
  debug("Using roles from #{roles}")
401
+
402
+ # Detect whether we are running tests on a role
403
+ # If so, make sure to copy into VM so dir structure is like: /tmp/kitchen/roles/role_name
337
404
 
338
- tmp_roles_dir = File.join(sandbox_path, 'roles')
339
- FileUtils.mkdir_p(tmp_roles_dir)
340
- FileUtils.cp_r(Dir.glob("#{roles}/*"), tmp_roles_dir)
405
+ FileUtils.mkdir_p(File.join(tmp_roles_dir, role_name))
406
+ FileUtils.cp_r(Dir.glob("#{roles}/*"), File.join(tmp_roles_dir, role_name))
341
407
  end
342
408
 
343
409
  # /etc/ansible/ansible.cfg should contain
@@ -351,9 +417,9 @@ module Kitchen
351
417
  file.write("#no roles path specified\n")
352
418
  end
353
419
  else
354
- debug("Using role from #{roles}")
420
+ debug("Setting roles_path inside VM to #{File.join(config[:root_path], 'roles', role_name)}")
355
421
  File.open( ansible_config_file, "wb") do |file|
356
- file.write("[defaults]\nroles_path = #{File.join(config[:root_path], roles)}\n")
422
+ file.write("[defaults]\nroles_path = #{File.join(config[:root_path], 'roles', role_name)}\n")
357
423
  end
358
424
  end
359
425
  end
@@ -377,8 +443,8 @@ module Kitchen
377
443
 
378
444
  def prepare_playbook
379
445
  info('Preparing playbook')
380
- debug("Using playbook from #{playbook}")
381
- FileUtils.cp_r(playbook, File.join(sandbox_path, playbook))
446
+ debug("Copying playbook from #{playbook} to #{tmp_playbook_path}")
447
+ FileUtils.cp_r(playbook, tmp_playbook_path)
382
448
  end
383
449
 
384
450
 
@@ -398,7 +464,6 @@ module Kitchen
398
464
 
399
465
  def prepare_host_vars
400
466
  info('Preparing host_vars')
401
- tmp_host_vars_dir = File.join(sandbox_path, 'host_vars')
402
467
  FileUtils.mkdir_p(tmp_host_vars_dir)
403
468
 
404
469
  unless File.directory?(host_vars)
@@ -413,11 +478,11 @@ module Kitchen
413
478
  def prepare_modules
414
479
  info('Preparing modules')
415
480
 
416
- FileUtils.mkdir_p(tmpmodules_dir)
481
+ FileUtils.mkdir_p(tmp_modules_dir)
417
482
 
418
483
  if modules && File.directory?(modules)
419
484
  debug("Using modules from #{modules}")
420
- FileUtils.cp_r(Dir.glob("#{modules}/*"), tmpmodules_dir, remove_destination: true)
485
+ FileUtils.cp_r(Dir.glob("#{modules}/*"), tmp_modules_dir, remove_destination: true)
421
486
  else
422
487
  info 'nothing to do for modules'
423
488
  end
@@ -428,7 +493,7 @@ module Kitchen
428
493
 
429
494
  def resolve_with_librarian
430
495
  Kitchen.mutex.synchronize do
431
- Ansible::Librarian.new(ansiblefile, tmpmodules_dir, logger).resolve
496
+ Ansible::Librarian.new(ansiblefile, tmp_modules_dir, logger).resolve
432
497
  end
433
498
  end
434
499
  end
@@ -18,6 +18,7 @@ extra_vars | Hash.new | Hash to set the extra_vars passed to ansibile-playbook c
18
18
  playbook | 'site.yml' | playbook for ansible-playbook to run
19
19
  modules_path | | ansible repo manifests directory
20
20
  ansible_verbose| false| Extra information logging
21
+ ansible_verbosity| 1| Sets the verbosity flag appropriately (e.g.: `1 => '-v', 2 => '-vv', 3 => '-vvv" ...`) Valid values are one of: `1, 2, 3, 4` OR `:info, :warn, :debug, :trace`.
21
22
  update_package_repos| true| update OS repository metadata
22
23
  chef_bootstrap_url |"https://www.getchef.com/chef/install.sh"| the chef (needed for busser to run tests)
23
24
  ansiblefile_path | | Path to Aansiblefile
@@ -36,6 +37,7 @@ The provisioner can be configured globally or per suite, global settings act as
36
37
  hosts: tomcat-servers
37
38
  require_ansible_repo: true
38
39
  ansible_verbose: true
40
+ ansible_verbosity: 2
39
41
 
40
42
  platforms:
41
43
  - name: nocm_ubuntu-12.04
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-ansible
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Neill Turner
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-07-01 00:00:00.000000000 Z
12
+ date: 2014-10-06 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: ! '== DESCRIPTION:
14
15
 
@@ -34,29 +35,29 @@ files:
34
35
  - lib/kitchen-ansible/version.rb
35
36
  - lib/kitchen/provisioner/ansible/librarian.rb
36
37
  - lib/kitchen/provisioner/ansible_playbook.rb
37
- - lib/kitchen/provisioner/ansible_playbook_spec.rb
38
38
  - provisioner_options.md
39
39
  homepage: https://github.com/neillturner/kitchen-ansible
40
40
  licenses: []
41
- metadata: {}
42
41
  post_install_message:
43
42
  rdoc_options: []
44
43
  require_paths:
45
44
  - lib
46
45
  required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
47
  requirements:
48
48
  - - ! '>='
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
52
53
  requirements:
53
54
  - - ! '>='
54
55
  - !ruby/object:Gem::Version
55
56
  version: '0'
56
57
  requirements: []
57
58
  rubyforge_project: ! '[none]'
58
- rubygems_version: 2.3.0
59
+ rubygems_version: 1.8.24
59
60
  signing_key:
60
- specification_version: 4
61
+ specification_version: 3
61
62
  summary: ansible provisioner for test-kitchen
62
63
  test_files: []
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZDdjMTc4NWYzMTQ1ZjJiODIyY2UzNDhlMDZkNDc4MmUxNTdlMzQ1YQ==
5
- data.tar.gz: !binary |-
6
- OWU4MWIxODk3NTAzM2VjODA1NDg1MmNlMjZhZWE5MWQ2ZGM3MjcxZg==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- MjI1ZjhhNThiNmJhMjBhMmYyMWQ4NDg4MDlmODBmNWZjYzdlMDY4NjlkZDU2
10
- NzM5NDFiYzAxZTU4MjM5MmQ5NTA1YjZkMzg2OGZlYzcwODc3ZDk5NzA1OWY0
11
- OTZlMTBlMGM1ZTM0NjZmMDk4NDIxMDJjMzVhMTI2ODZmNDA2MzQ=
12
- data.tar.gz: !binary |-
13
- NzNmY2EzYzczOGY4MTlkZmU5OWFiNTcyNDM5OGIwNmRiZjQxMGYzY2QxMGMw
14
- NjRlMGY1YjQ3NjNmOGY4NWMzY2NiMGM0OTA3NmU5OTNhNjYxMjZjZWRiMDRj
15
- ZDEyMWU2N2E1YjgzMTllNzY4Nzg1ZWY1MzNmY2JhMjE0OTU3NDc=
@@ -1,33 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Neill Turner (<neillwturner@gmail.com>)
4
- #
5
- # Copyright (C) 2013,2014 Neill Turner
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
-
19
- require_relative '../../spec_helper'
20
- require 'kitchen'
21
-
22
- # Work around for lazy loading
23
- require 'kitchen/provisioner/ansible_playbook'
24
-
25
- describe Kitchen::Provisioner::AnsiblePlaybook do
26
- let(:provisioner) do
27
- Kitchen::Provisioner.for_plugin("ansible_playbook", {})
28
- end
29
-
30
- it "should give a sane run_command" do
31
- provisioner.run_command.must_match /ansible-playbook/
32
- end
33
- end