kitchen-ansible 0.0.16 → 0.0.17

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: 222d1ee98effa69d0d9992fe20f9c9511b4c9ff1
4
- data.tar.gz: 55f68c2848abc4233e8acd74fa784c5372557026
3
+ metadata.gz: 7e743c9802fe1bd941d329f712d7e7f8ddbb9d6c
4
+ data.tar.gz: a8191edb41ddd5114262b301f397c149cff74a21
5
5
  SHA512:
6
- metadata.gz: 6622698240ee163482c9a45fca1f7cb8d020e3874e487620925e943ca3a76aac7e5799bcd862d11e23597144526bc8b7d1fa057221e54ec6c1534524d72595ea
7
- data.tar.gz: a48e95524e38f482f008df670c15585509bdc8432a7a2b85644a586b10d141be27040a862cc3d0610c356542e77293b554202d6de06ffab0597e8a9fdfba3dde
6
+ metadata.gz: 4987150939c35f900f03d315fba877e5cfa930bb4c2a2f5e57e4887d3e00a74bed4876bbc5a881cc951c3b119b38075e543aaa2108350a28b58bc2b0f31acf21
7
+ data.tar.gz: a28d0b4f9c54f216113eb1a3af8948a1b5aa6af13533a04db01854377151272e659858b4bef72403cac98d9939fb25ca36210de861fe80606e72ccbc7ecfc66f
@@ -30,5 +30,6 @@ EOF
30
30
 
31
31
  s.add_development_dependency 'rspec'
32
32
  s.add_development_dependency 'pry'
33
+ s.add_development_dependency 'rake'
33
34
  s.add_runtime_dependency 'librarian-ansible'
34
35
  end
@@ -1,5 +1,5 @@
1
1
  module Kitchen
2
2
  module Ansible
3
- VERSION = "0.0.16"
3
+ VERSION = "0.0.17"
4
4
  end
5
5
  end
@@ -0,0 +1,139 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Michael Heap (<m@michaelheap.com>)
4
+ #
5
+ # Copyright (C) 2015 Michael Heap
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
+
20
+ require 'json'
21
+
22
+ module Kitchen
23
+
24
+ module Provisioner
25
+
26
+ module Ansible
27
+ #
28
+ # Ansible Playbook provisioner.
29
+ #
30
+ class Config
31
+ include Kitchen::Configurable
32
+
33
+ attr_reader :instance
34
+
35
+ default_config :ansible_verbose, false
36
+ default_config :require_ansible_omnibus, false
37
+ default_config :ansible_omnibus_url, nil
38
+ default_config :ansible_omnibus_remote_path, '/opt/ansible'
39
+ default_config :ansible_version, nil
40
+ default_config :require_ansible_repo, true
41
+ default_config :extra_vars, {}
42
+ default_config :tags, []
43
+ default_config :ansible_apt_repo, "ppa:ansible/ansible"
44
+ default_config :ansible_yum_repo, "https://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm"
45
+ default_config :chef_bootstrap_url, "https://www.getchef.com/chef/install.sh"
46
+ default_config :require_chef_for_busser, false
47
+ default_config :require_ruby_for_busser, true
48
+ default_config :requirements_path, false
49
+ default_config :ansible_verbose, false
50
+ default_config :ansible_verbosity, 1
51
+ default_config :ansible_check, false
52
+ default_config :ansible_diff, false
53
+ default_config :ansible_platform, ''
54
+ default_config :update_package_repos, true
55
+
56
+ default_config :playbook do |provisioner|
57
+ provisioner.calculate_path('default.yml', :file) or
58
+ 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"
59
+ end
60
+
61
+ default_config :roles_path do |provisioner|
62
+ provisioner.calculate_path('roles') or
63
+ raise 'No roles_path detected. Please specify one in .kitchen.yml'
64
+ end
65
+
66
+ default_config :group_vars_path do |provisioner|
67
+ provisioner.calculate_path('group_vars', :directory)
68
+ end
69
+
70
+ default_config :additional_copy_path do |provisioner|
71
+ provisioner.calculate_path('additional_copy', :directory)
72
+ end
73
+
74
+ default_config :host_vars_path do |provisioner|
75
+ provisioner.calculate_path('host_vars', :directory)
76
+ end
77
+
78
+ default_config :modules_path do |provisioner|
79
+ provisioner.calculate_path('modules', :directory)
80
+ end
81
+
82
+ default_config :ansiblefile_path do |provisioner|
83
+ provisioner.calculate_path('Ansiblefile', :file)
84
+ end
85
+
86
+ default_config :filter_plugins_path do |provisioner|
87
+ provisioner.calculate_path('filter_plugins', :directory)
88
+ end
89
+
90
+ default_config :ansible_vault_password_file do |provisioner|
91
+ provisioner.calculate_path('ansible-vault-password', :file)
92
+ end
93
+
94
+ def initialize(config = {})
95
+ init_config(config)
96
+ end
97
+
98
+ def set_instance(instance)
99
+ @instance = instance
100
+ end
101
+
102
+ def []=(attr, val)
103
+ config[attr] = val
104
+ end
105
+
106
+ def [](attr)
107
+ config[attr]
108
+ end
109
+
110
+ def key?(k)
111
+ return config.key?(k)
112
+ end
113
+
114
+ def calculate_path(path, type = :directory)
115
+
116
+ if not instance
117
+ raise "Please ensure that an instance is provided before calling calculate_path"
118
+ end
119
+
120
+ base = config[:test_base_path]
121
+ candidates = []
122
+ candidates << File.join(base, instance.suite.name, 'ansible', path)
123
+ candidates << File.join(base, instance.suite.name, path)
124
+ candidates << File.join(base, path)
125
+ candidates << File.join(Dir.pwd, path)
126
+ candidates << File.join(Dir.pwd) if path == 'roles'
127
+
128
+ candidates.find do |c|
129
+ type == :directory ? File.directory?(c) : File.file?(c)
130
+ end
131
+ end
132
+
133
+
134
+ end
135
+
136
+ end
137
+ end
138
+
139
+ end
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'json'
24
24
  require 'kitchen/provisioner/base'
25
+ require 'kitchen/provisioner/ansible/config'
25
26
  require 'kitchen/provisioner/ansible/librarian'
26
27
 
27
28
  module Kitchen
@@ -40,63 +41,16 @@ module Kitchen
40
41
  class AnsiblePlaybook < Base
41
42
  attr_accessor :tmp_dir
42
43
 
43
- default_config :require_ansible_omnibus, false
44
- default_config :ansible_omnibus_url, nil
45
- default_config :ansible_omnibus_remote_path, '/opt/ansible'
46
- default_config :ansible_version, nil
47
- default_config :require_ansible_repo, true
48
- default_config :extra_vars, {}
49
- default_config :tags, []
50
- default_config :ansible_apt_repo, "ppa:ansible/ansible"
51
- default_config :ansible_yum_repo, "https://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm"
52
- default_config :chef_bootstrap_url, "https://www.getchef.com/chef/install.sh"
53
-
54
- default_config :playbook do |provisioner|
55
- provisioner.calculate_path('default.yml', :file) or
56
- 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"
44
+ def initialize(provisioner_config)
45
+ config = Kitchen::Provisioner::Ansible::Config.new(provisioner_config)
46
+ super(config)
57
47
  end
58
48
 
59
- default_config :roles_path do |provisioner|
60
- provisioner.calculate_path('roles') or
61
- raise 'No roles_path detected. Please specify one in .kitchen.yml'
49
+ def finalize_config!(instance)
50
+ config.set_instance(instance)
51
+ super(instance)
62
52
  end
63
53
 
64
- default_config :group_vars_path do |provisioner|
65
- provisioner.calculate_path('group_vars', :directory)
66
- end
67
-
68
- default_config :additional_copy_path do |provisioner|
69
- provisioner.calculate_path('additional_copy', :directory)
70
- end
71
-
72
- default_config :host_vars_path do |provisioner|
73
- provisioner.calculate_path('host_vars', :directory)
74
- end
75
-
76
- default_config :modules_path do |provisioner|
77
- provisioner.calculate_path('modules', :directory)
78
- end
79
-
80
- default_config :ansiblefile_path do |provisioner|
81
- provisioner.calculate_path('Ansiblefile', :file)
82
- end
83
-
84
- default_config :filter_plugins_path do |provisioner|
85
- provisioner.calculate_path('filter_plugins', :directory)
86
- end
87
-
88
- default_config :ansible_vault_password_file do |provisioner|
89
- provisioner.calculate_path('ansible-vault-password', :file)
90
- end
91
-
92
- default_config :requirements_path, false
93
- default_config :ansible_verbose, false
94
- default_config :ansible_verbosity, 1
95
- default_config :ansible_check, false
96
- default_config :ansible_diff, false
97
- default_config :ansible_platform, ''
98
- default_config :update_package_repos, true
99
-
100
54
  def verbosity_level(level = 1)
101
55
  level = level.to_sym if level.is_a? String
102
56
  log_levels = { :info => 1, :warn => 2, :debug => 3, :trace => 4 }
@@ -111,21 +65,6 @@ module Kitchen
111
65
  end
112
66
  end
113
67
 
114
- def calculate_path(path, type = :directory)
115
- base = config[:test_base_path]
116
- candidates = []
117
- candidates << File.join(base, instance.suite.name, 'ansible', path)
118
- candidates << File.join(base, instance.suite.name, path)
119
- candidates << File.join(base, path)
120
- candidates << File.join(Dir.pwd, path)
121
- candidates << File.join(Dir.pwd) if path == 'roles'
122
-
123
- debug("Calculating path for #{path}, candidates are: #{candidates.to_s}")
124
- candidates.find do |c|
125
- type == :directory ? File.directory?(c) : File.file?(c)
126
- end
127
- end
128
-
129
68
  def install_command
130
69
  return unless config[:require_ansible_omnibus] or config[:require_ansible_repo]
131
70
  if config[:require_ansible_omnibus]
@@ -143,7 +82,7 @@ module Kitchen
143
82
  do_download #{config[:ansible_omnibus_url]} /tmp/ansible_install.sh
144
83
  #{sudo('sh')} /tmp/ansible_install.sh #{version}
145
84
  fi
146
- #{install_busser}
85
+ #{install_busser_prereqs}
147
86
  INSTALL
148
87
  else
149
88
  case ansible_platform
@@ -158,7 +97,7 @@ module Kitchen
158
97
  export DEBIAN_FRONTEND=noninteractive
159
98
  ## 13.10, 14.04 include add-apt-repository in software-properties-common
160
99
  #{sudo('apt-get')} -y install software-properties-common
161
- ## 10.04, 12.04 include add-apt-repository in
100
+ ## 10.04, 12.04 include add-apt-repository in
162
101
  #{sudo('apt-get')} -y install python-software-properties
163
102
  # #{sudo('wget')} #{ansible_apt_repo}
164
103
  # #{sudo('dpkg')} -i #{ansible_apt_repo_file}
@@ -175,7 +114,7 @@ module Kitchen
175
114
  ## This test works on ubuntu to test if ansible repo has been installed via rquillo ppa repo
176
115
  ## if [ $(apt-cache madison ansible | grep -c rquillo ) -gt 0 ]; then echo 'success'; else echo 'fail'; fi
177
116
  fi
178
- #{install_busser}
117
+ #{install_busser_prereqs}
179
118
  INSTALL
180
119
  when "redhat", "centos", "fedora"
181
120
  info("Installing ansible on #{ansible_platform}")
@@ -183,9 +122,9 @@ module Kitchen
183
122
  if [ ! $(which ansible) ]; then
184
123
  #{sudo('rpm')} -ivh #{ansible_yum_repo}
185
124
  #{update_packages_redhat_cmd}
186
- #{sudo('yum')} -y install ansible#{ansible_redhat_version} libselinux-python
125
+ #{sudo('yum')} -y install ansible#{ansible_redhat_version} libselinux-python git
187
126
  fi
188
- #{install_busser}
127
+ #{install_busser_prereqs}
189
128
  INSTALL
190
129
  else
191
130
  info("Installing ansible, will try to determine platform os")
@@ -194,16 +133,16 @@ module Kitchen
194
133
  if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then
195
134
  #{sudo('rpm')} -ivh #{ansible_yum_repo}
196
135
  #{update_packages_redhat_cmd}
197
- #{sudo('yum')} -y install ansible#{ansible_redhat_version} libselinux-python
136
+ #{sudo('yum')} -y install ansible#{ansible_redhat_version} libselinux-python git
198
137
  else
199
138
  #{update_packages_debian_cmd}
200
139
  ## Install apt-utils to silence debconf warning: http://serverfault.com/q/358943/77156
201
- #{sudo('apt-get')} -y install apt-utils
140
+ #{sudo('apt-get')} -y install apt-utils git
202
141
  ## Fix debconf tty warning messages
203
142
  export DEBIAN_FRONTEND=noninteractive
204
143
  ## 13.10, 14.04 include add-apt-repository in software-properties-common
205
144
  #{sudo('apt-get')} -y install software-properties-common
206
- ## 10.04, 12.04 include add-apt-repository in
145
+ ## 10.04, 12.04 include add-apt-repository in
207
146
  #{sudo('apt-get')} -y install python-software-properties
208
147
  # #{sudo('wget')} #{ansible_apt_repo}
209
148
  # #{sudo('dpkg')} -i #{ansible_apt_repo_file}
@@ -221,13 +160,13 @@ module Kitchen
221
160
  ## if [ $(apt-cache madison ansible | grep -c rquillo ) -gt 0 ]; then echo 'success'; else echo 'fail'; fi
222
161
  fi
223
162
  fi
224
- #{install_busser}
163
+ #{install_busser_prereqs}
225
164
  INSTALL
226
165
  end
227
166
  end
228
167
  end
229
168
 
230
- def install_busser
169
+ def install_busser_prereqs
231
170
  install = ''
232
171
  install << <<-INSTALL
233
172
  #{Util.shell_helpers}
@@ -238,12 +177,42 @@ module Kitchen
238
177
  #{sudo('ln')} -s $L /usr/bin/ruby
239
178
  fi
240
179
  INSTALL
241
- if chef_url then
180
+
181
+ if require_ruby_for_busser
182
+ install << <<-INSTALL
183
+ if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then
184
+ rhelversion=$(cat /etc/redhat-release | grep 'release 6')
185
+ # For CentOS6/RHEL6 install ruby from SCL
186
+ if [ -n "$rhelversion" ]; then
187
+ if [ ! -d "/opt/rh/ruby193" ]; then
188
+ echo "-----> Installing ruby SCL in CentOS6/RHEL6 to install busser to run tests"
189
+ #{sudo('yum')} install -y centos-release-SCL
190
+ #{sudo('yum')} install -y ruby193
191
+ #{sudo('yum')} install -y ruby193-ruby-devel
192
+ echo "-----> Enabling ruby193"
193
+ source /opt/rh/ruby193/enable
194
+ echo "/opt/rh/ruby193/root/usr/lib64" | sudo tee -a /etc/ld.so.conf
195
+ sudo ldconfig
196
+ sudo ln -s /opt/rh/ruby193/root/usr/bin/ruby /usr/bin/ruby
197
+ sudo ln -s /opt/rh/ruby193/root/usr/bin/gem /usr/bin/gem
198
+ fi
199
+ else
200
+ if [ ! $(which ruby) ]; then
201
+ #{update_packages_redhat_cmd}
202
+ #{sudo('yum')} -y install ruby ruby-devel
203
+ fi
204
+ fi
205
+ else
206
+ if [ ! $(which ruby) ]; then
207
+ #{update_packages_debian_cmd}
208
+ #{sudo('apt-get')} -y install ruby1.9.1 ruby1.9.1-dev
209
+ fi
210
+ fi
211
+ INSTALL
212
+
213
+ elsif require_chef_for_busser && chef_url then
242
214
  install << <<-INSTALL
243
215
  # install chef omnibus so that busser works as this is needed to run tests :(
244
- # TODO: work out how to install enough ruby
245
- # and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
246
- # whole chef client
247
216
  if [ ! -d "/opt/chef" ]
248
217
  then
249
218
  echo "-----> Installing Chef Omnibus to install busser to run tests"
@@ -409,9 +378,9 @@ module Kitchen
409
378
  end
410
379
 
411
380
  def host_vars
412
- config[:host_vars_path].to_s
381
+ config[:host_vars_path].to_s
413
382
  end
414
-
383
+
415
384
  def filter_plugins
416
385
  config[:filter_plugins_path].to_s
417
386
  end
@@ -495,7 +464,15 @@ module Kitchen
495
464
  def chef_url
496
465
  config[:chef_bootstrap_url]
497
466
  end
498
-
467
+
468
+ def require_ruby_for_busser
469
+ config[:require_ruby_for_busser]
470
+ end
471
+
472
+ def require_chef_for_busser
473
+ config[:require_chef_for_busser]
474
+ end
475
+
499
476
  def prepare_roles
500
477
  info('Preparing roles')
501
478
  debug("Using roles from #{roles}")
@@ -505,7 +482,7 @@ module Kitchen
505
482
  if galaxy_requirements
506
483
  FileUtils.cp(galaxy_requirements, File.join(sandbox_path, galaxy_requirements))
507
484
  end
508
-
485
+
509
486
  # Detect whether we are running tests on a role
510
487
  # If so, make sure to copy into VM so dir structure is like: /tmp/kitchen/roles/role_name
511
488
 
@@ -540,7 +517,7 @@ module Kitchen
540
517
 
541
518
 
542
519
  # localhost ansible_connection=local
543
- # [example_servers]
520
+ # [example_servers]
544
521
  # localhost
545
522
  def prepare_hosts
546
523
  info('Preparing hosts file')
@@ -6,29 +6,30 @@ key | default value | Notes
6
6
  ansible_version | "latest"| desired version, affects apt installs
7
7
  ansible_platform | naively tries to determine | OS platform of server
8
8
  require_ansible_repo | true | Set if using a ansible install from yum or apt repo
9
- ansible_apt_repo | "ppa:ansible/ansible" | apt repo
10
- ansible_yum_repo | "https://download.fedoraproject.org | yum repo
11
- | /pub/epel/6/i386/epel-release-6-8.noarch.rpm" |
12
- require_ansible_omnibus | false | Set if using omnibus ansible install
13
- ansible_omnibus_url | | omnibus ansible install location.
14
- ansible_omnibus_remote_path | "/opt/ansible" | Server Installation location of an omnibus ansible install.
9
+ ansible_apt_repo | "ppa:ansible/ansible" | apt repo. see https://launchpad.net /~ansible/+archive/ubuntu/ansible or rquillo/ansible
10
+ ansible_yum_repo | https://download.fedoraproject.org /pub/epel/6/i386/epel-release-6-8.noarch.rpm | yum repo
15
11
  roles_path | roles | ansible repo roles directory
16
12
  group_vars_path | group_vars | ansible repo group_vars directory
17
13
  host_vars_path | host_vars | ansible repo hosts directory
18
14
  filter_plugins | filter_plugins | ansible repo filter_plugins directory
19
15
  additional_copy_path | | arbitrary array of files and directories to copy into test environment, relative to CWD. (eg, vars or included playbooks)
20
16
  extra_vars | Hash.new | Hash to set the extra_vars passed to ansibile-playbook command
21
- playbook | 'site.yml' | playbook for ansible-playbook to run
17
+ playbook | 'default.yml' | playbook for ansible-playbook to run
22
18
  modules_path | | ansible repo manifests directory
23
19
  ansible_verbose| false| Extra information logging
24
20
  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`.
25
21
  ansible_check| false| Sets the `--check` flag when running Ansible
26
22
  ansible_diff| false| Sets the `--diff` flag when running Ansible
27
23
  update_package_repos| true| update OS repository metadata
28
- chef_bootstrap_url |"https://www.getchef.com/chef/install.sh"| the chef (needed for busser to run tests) NOTE: kitchen 1.4 only requires ruby to run busser so this is not required.
24
+ require_ruby_for_busser|true|install ruby to run busser for tests
29
25
  ansiblefile_path | | Path to Ansiblefile
30
26
  requirements_path | | Path to ansible-galaxy requirements
31
27
  ansible_vault_password_file| | Path of Ansible Vault Password File
28
+ require_ansible_omnibus | false | Set if using omnibus ansible install
29
+ ansible_omnibus_url | | omnibus ansible install location.
30
+ ansible_omnibus_remote_path | "/opt/ansible" | Server Installation location of an omnibus ansible install.
31
+ require_chef_for_busser|false|install chef to run busser for tests. NOTE: kitchen 1.4 only requires ruby to run busser so this is not required.
32
+ chef_bootstrap_url |https://www.getchef.com /chef/install.sh| the chef install
32
33
 
33
34
  ## Configuring Provisioner Options
34
35
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-ansible
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neill Turner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-19 00:00:00.000000000 Z
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: librarian-ansible
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -84,6 +98,7 @@ files:
84
98
  - README.md
85
99
  - kitchen-ansible.gemspec
86
100
  - lib/kitchen-ansible/version.rb
101
+ - lib/kitchen/provisioner/ansible/config.rb
87
102
  - lib/kitchen/provisioner/ansible/librarian.rb
88
103
  - lib/kitchen/provisioner/ansible_playbook.rb
89
104
  - provisioner_options.md
@@ -107,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
122
  version: '0'
108
123
  requirements: []
109
124
  rubyforge_project: "[none]"
110
- rubygems_version: 2.2.2
125
+ rubygems_version: 2.2.3
111
126
  signing_key:
112
127
  specification_version: 4
113
128
  summary: ansible provisioner for test-kitchen