kitchen-ansiblepush 0.3.11 → 0.4.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 +68 -1
- data/bin/kitchen-ansible-inventory +1 -1
- data/lib/kitchen/provisioner/ansible_push.rb +98 -143
- data/lib/kitchen-ansible/chef_installation.rb +16 -0
- data/lib/kitchen-ansible/util_inventory.rb +26 -0
- data/lib/kitchen-ansible/version.rb +1 -1
- metadata +4 -3
- data/lib/kitchen-ansible/util-inventory.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0547589c17d78e5d24ceeb92a062a44397a73f5
|
4
|
+
data.tar.gz: 778c772b723538a3c42d97f7acff1ff1fa97bf0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47e15370cfa899c16bd097d8916353522ab87298f543e64bf39d82a2b8ccd294b50f191421ba8d9c4c2ddb305a41b14cf45dfdb11287ae7b0a0170cad7b52110
|
7
|
+
data.tar.gz: 7a3b3686587cf196df57d014779734bd85e10301f8010d622cb57feba7f9093e257dfe24f65f946ada5e46a244fdf1c6812b6eb0361c32f2ca86bbb7013a4315
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# kitchen-ansiblepush
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/kitchen-ansiblepush.svg)](https://badge.fury.io/rb/kitchen-ansiblepush)
|
3
|
+
[![Gem Downloads](http://ruby-gem-downloads-badge.herokuapp.com/kitchen-ansiblepush?type=total&color=brightgreen)](https://rubygems.org/gems/kitchen-ansiblepush)
|
4
|
+
[![Build Status](https://travis-ci.org/ahelal/kitchen-ansiblepush.svg?branch=master)](https://travis-ci.org/ahelal/kitchen-ansiblepush)
|
3
5
|
|
4
6
|
A test-kitchen plugin that adds the support for ansible in push mode
|
5
7
|
|
@@ -21,6 +23,18 @@ gem build kitchen-ansiblepush.gemspec
|
|
21
23
|
gem install kitchen-ansiblepush-<version>.gem
|
22
24
|
```
|
23
25
|
|
26
|
+
### Use Bundler
|
27
|
+
My prefered method is use Gemfile
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
source "https://rubygems.org"
|
31
|
+
group :development do
|
32
|
+
gem 'test-kitchen'
|
33
|
+
gem 'kitchen-vagrant' # for example
|
34
|
+
gem 'kitchen-ansiblepush'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
24
38
|
## kitchen.yml Options
|
25
39
|
```yaml
|
26
40
|
provisioner :
|
@@ -51,15 +65,68 @@ provisioner :
|
|
51
65
|
host_key_checking : false
|
52
66
|
generate_inv : true
|
53
67
|
use_instance_name : false # use short (platform) instead of instance name by default
|
54
|
-
|
68
|
+
idempotency_test : False
|
55
69
|
```
|
56
70
|
## idempotency test
|
57
71
|
If you want to check your code is idempotent you can use the idempotency_test. Essentially, this will run Ansible twice and check nothing changed in the next run. If something changed it will list the tasks. Note: If your using Ansible callback in your config this might conflict.
|
58
72
|
```yaml
|
59
73
|
idempotency_test: True
|
74
|
+
fail_non_idempotent: True
|
60
75
|
```
|
61
76
|
|
62
77
|
If your running ansible V2 you need to white list the callback ``` callback_whitelist = changes``` in **ansible.cfg**
|
78
|
+
You can also choose to not to fail if idempotency test fails.
|
79
|
+
|
80
|
+
## Ansible version
|
81
|
+
Since ansiblepush uses the host to run Ansible. you can simply specify the path of your ansible-playbook executable in your .kitchen.yml
|
82
|
+
```yaml
|
83
|
+
ansible_playbook_bin : /path/to/ansible-playbook
|
84
|
+
```
|
85
|
+
|
86
|
+
You can use venv and install multi version of ansible or if you prefer you can use an automated installer [ansible-setup](https://github.com/AutomationWIthAnsible/ansible-setup) you can install multi version of ansible.
|
87
|
+
For further example you can check a matrix test [ansible-usermanage](https://github.com/AutomationWithAnsible/ansible-usermanage/blob/master/.kitchen.yml)
|
88
|
+
|
89
|
+
## Disable chef installation
|
90
|
+
By default chef is installed and serverspec stuff. if you dont want to install
|
91
|
+
```yaml
|
92
|
+
chef_bootstrap_url: nil
|
93
|
+
```
|
94
|
+
|
95
|
+
## Pattern of usage
|
96
|
+
You can use ansible push with different pattern. I will list some of the ways that I use it, But by no means they are the only patterns.
|
97
|
+
### Roles
|
98
|
+
|
99
|
+
I define my Gemfile in the role. I then run ```bundle install``` and commit my *Gemfile.lock* I also ignore ```.kitchen```
|
100
|
+
|
101
|
+
A typical structure of an ansible role
|
102
|
+
```yaml
|
103
|
+
defaults
|
104
|
+
handlers
|
105
|
+
meta
|
106
|
+
tasks
|
107
|
+
templates
|
108
|
+
vars
|
109
|
+
Gemfile
|
110
|
+
Gemfile.lock
|
111
|
+
.gitingore
|
112
|
+
tests
|
113
|
+
\_ ansible.cfg
|
114
|
+
\_ integration
|
115
|
+
\_ server
|
116
|
+
\_ server.yml # my play that will test something
|
117
|
+
\_ serverspec
|
118
|
+
\_ worker
|
119
|
+
\_ worker.yml # my play that will test something
|
120
|
+
\_ serverspec
|
121
|
+
|
122
|
+
```
|
123
|
+
|
124
|
+
## Real example usages
|
125
|
+
- https://github.com/hellofresh/ansible-deployment
|
126
|
+
- https://github.com/AutomationWithAnsible/ansible-usermanage
|
127
|
+
- https://github.com/ahelal/ansible-concourse
|
128
|
+
- https://github.com/danrue/ansible-variables
|
129
|
+
- https://github.com/knakayama/kitchen-ansiblepush-demo
|
63
130
|
|
64
131
|
## TODO
|
65
132
|
- Enable envirionment var ANSIBLE_CALLBACK_WHITELIST="changes" before call
|
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'open3'
|
2
2
|
require 'kitchen'
|
3
3
|
require 'kitchen/provisioner/base'
|
4
|
-
require 'kitchen-ansible/
|
4
|
+
require 'kitchen-ansible/util_inventory.rb'
|
5
|
+
require 'kitchen-ansible/chef_installation.rb'
|
5
6
|
require 'json'
|
6
7
|
require 'securerandom'
|
7
8
|
|
8
9
|
module Kitchen
|
9
|
-
|
10
10
|
class Busser
|
11
11
|
def non_suite_dirs
|
12
|
-
%w{data}
|
12
|
+
%w({data})
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
module Provisioner
|
17
17
|
class AnsiblePush < Base
|
18
18
|
kitchen_provisioner_api_version 2
|
19
|
-
default_config :ansible_playbook_bin,
|
19
|
+
default_config :ansible_playbook_bin, 'ansible-playbook'
|
20
20
|
default_config :ansible_config, nil
|
21
21
|
default_config :verbose, nil
|
22
22
|
default_config :diff, nil
|
@@ -36,32 +36,26 @@ module Kitchen
|
|
36
36
|
default_config :mygroup, nil
|
37
37
|
default_config :playbook, nil
|
38
38
|
default_config :generate_inv, true
|
39
|
-
default_config :generate_inv_path,
|
39
|
+
default_config :generate_inv_path, '`which kitchen-ansible-inventory`'
|
40
40
|
default_config :raw_arguments, nil
|
41
41
|
default_config :idempotency_test, false
|
42
42
|
default_config :fail_non_idempotent, true
|
43
43
|
default_config :use_instance_name, false
|
44
44
|
|
45
45
|
# For tests disable if not needed
|
46
|
-
default_config :chef_bootstrap_url,
|
47
|
-
|
48
|
-
default_config :support_older_version, false
|
46
|
+
default_config :chef_bootstrap_url, 'https://omnitruck.chef.io/install.sh'
|
49
47
|
|
50
48
|
# Validates the config and returns it. Has side-effect of
|
51
49
|
# possibly setting @extra_vars which doesn't seem to be used
|
52
50
|
def conf
|
53
51
|
return @validated_config if defined? @validated_config
|
54
52
|
|
55
|
-
|
56
|
-
raise 'No playbook defined. Please specify one in .kitchen.yml'
|
57
|
-
end
|
53
|
+
raise 'No playbook defined. Please specify one in .kitchen.yml' unless config[:playbook]
|
58
54
|
|
59
|
-
|
60
|
-
raise "playbook '%s' could not be found. Please check path" % config[:playbook]
|
61
|
-
end
|
55
|
+
raise "playbook '#{config[:playbook]}' could not be found. Please check path" unless File.exist?(config[:playbook])
|
62
56
|
|
63
|
-
if config[:vault_password_file]
|
64
|
-
raise "Vault password '
|
57
|
+
if config[:vault_password_file] && !File.exist?(config[:vault_password_file])
|
58
|
+
raise "Vault password '#{config[:vault_password_file]}' could not be found. Please check path"
|
65
59
|
end
|
66
60
|
|
67
61
|
# Validate that extra_vars is either a hash, or a path to an existing file
|
@@ -73,49 +67,45 @@ module Kitchen
|
|
73
67
|
extra_vars_path = match_data[1].to_s
|
74
68
|
expanded_path = Pathname.new(extra_vars_path).expand_path(Dir.pwd)
|
75
69
|
extra_vars_is_valid = expanded_path.exist?
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|
80
|
-
if !extra_vars_is_valid
|
81
|
-
raise "ansible extra_vars is in valid type: %s value: %s" % [config[:extra_vars].class.to_s, config[:extra_vars].to_s]
|
70
|
+
|
71
|
+
@extra_vars = '@' + extra_vars_path if extra_vars_is_valid
|
82
72
|
end
|
73
|
+
|
74
|
+
raise 'ansible extra_vars is in valid type: %s value: %s' % [config[:extra_vars].class.to_s, config[:extra_vars].to_s] unless extra_vars_is_valid
|
83
75
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
76
|
+
info('Ansible push config validated')
|
77
|
+
|
87
78
|
@validated_config = config
|
88
79
|
end
|
89
80
|
|
90
81
|
def machine_name
|
91
82
|
return @machine_name if defined? @machine_name
|
92
|
-
|
93
|
-
@machine_name = instance.name.gsub(/[<>]/, '').split("-").drop(1).join("-")
|
94
|
-
else
|
83
|
+
if config[:use_instance_name]
|
95
84
|
@machine_name = instance.name.gsub(/[<>]/, '')
|
85
|
+
else
|
86
|
+
@machine_name = instance.name.gsub(/[<>]/, '').split('-').drop(1).join('-')
|
96
87
|
end
|
97
|
-
debug(
|
88
|
+
debug('machine_name=' + @machine_name.to_s)
|
98
89
|
@machine_name
|
99
90
|
end
|
100
91
|
|
101
92
|
def options
|
102
93
|
return @options if defined? @options
|
103
94
|
options = []
|
104
|
-
options << "--extra-vars='#{
|
105
|
-
options <<
|
95
|
+
options << "--extra-vars='#{extra_vars_argument}'" if conf[:extra_vars]
|
96
|
+
options << '--sudo' if conf[:sudo]
|
106
97
|
options << "--sudo-user=#{conf[:sudo_user]}" if conf[:sudo_user]
|
107
|
-
options << "--user=#{conf[:remote_user]}" if
|
98
|
+
options << "--user=#{conf[:remote_user]}" if remote_user
|
108
99
|
options << "--private-key=#{conf[:private_key]}" if conf[:private_key]
|
109
|
-
options <<
|
110
|
-
options <<
|
111
|
-
options <<
|
112
|
-
options <<
|
100
|
+
options << verbosity_argument.to_s if conf[:verbose]
|
101
|
+
options << '--diff' if conf[:diff]
|
102
|
+
options << '--ask-sudo-pass' if conf[:ask_sudo_pass]
|
103
|
+
options << '--ask-vault-pass' if conf[:ask_vault_pass]
|
113
104
|
options << "--vault-password-file=#{conf[:vault_password_file]}" if conf[:vault_password_file]
|
114
|
-
options <<
|
115
|
-
options <<
|
105
|
+
options << '--tags=%s' % as_list_argument(conf[:tags]) if conf[:tags]
|
106
|
+
options << '--skip-tags=%s' % as_list_argument(conf[:skip_tags]) if conf[:skip_tags]
|
116
107
|
options << "--start-at-task=#{conf[:start_at_task]}" if conf[:start_at_task]
|
117
108
|
options << "--inventory-file=#{conf[:generate_inv_path]}" if conf[:generate_inv]
|
118
|
-
##options << "--inventory-file=#{ssh_inv}," if ssh_inv
|
119
109
|
|
120
110
|
# By default we limit by the current machine,
|
121
111
|
if conf[:limit]
|
@@ -124,7 +114,7 @@ module Kitchen
|
|
124
114
|
options << "--limit=#{machine_name}"
|
125
115
|
end
|
126
116
|
|
127
|
-
#Add raw argument as final thing
|
117
|
+
# Add raw argument as final thing
|
128
118
|
options << conf[:raw_arguments] if conf[:raw_arguments]
|
129
119
|
@options = options
|
130
120
|
end
|
@@ -132,87 +122,48 @@ module Kitchen
|
|
132
122
|
def command
|
133
123
|
return @command if defined? @command
|
134
124
|
@command = [conf[:ansible_playbook_bin]]
|
135
|
-
@command =
|
136
|
-
debug(
|
125
|
+
@command = (@command << options << conf[:playbook]).flatten.join(' ')
|
126
|
+
debug('Ansible push command= %s' % @command)
|
137
127
|
@command
|
138
128
|
end
|
139
129
|
|
140
130
|
def command_env
|
141
131
|
return @command_env if defined? @command_env
|
142
132
|
@command_env = {
|
143
|
-
|
144
|
-
|
145
|
-
|
133
|
+
'PYTHONUNBUFFERED' => '1', # Ensure Ansible output isn't buffered
|
134
|
+
'ANSIBLE_FORCE_COLOR' => 'true',
|
135
|
+
'ANSIBLE_HOST_KEY_CHECKING' => conf[:host_key_checking].to_s
|
146
136
|
}
|
147
|
-
@command_env[
|
137
|
+
@command_env['ANSIBLE_CONFIG'] = conf[:ansible_config] if conf[:ansible_config]
|
148
138
|
@command_env
|
149
139
|
end
|
150
140
|
|
151
141
|
def prepare_command
|
152
142
|
prepare_inventory if conf[:generate_inv]
|
153
|
-
# Place holder so a string is returned. This will execute true on remote host
|
154
|
-
|
143
|
+
# Place holder so a string is returned. This will execute true on remote host
|
144
|
+
'true'
|
155
145
|
end
|
156
146
|
|
157
147
|
def install_command
|
158
148
|
# Must install chef for busser and serverspec to work :(
|
159
|
-
info(
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
149
|
+
info('*************** AnsiblePush install_command ***************')
|
150
|
+
# Test if ansible-playbook is installed and give a meaningful
|
151
|
+
# error message
|
152
|
+
version_check = command + ' --version'
|
153
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(command_env, version_check)
|
154
|
+
exit_status = wait_thr.value
|
155
|
+
|
156
|
+
raise "%s returned a non zero '%s'" % [version_check, exit_status] unless exit_status.success?
|
166
157
|
|
167
|
-
omnibus_download_dir = conf[:omnibus_cachier] ?
|
168
|
-
|
158
|
+
omnibus_download_dir = conf[:omnibus_cachier] ? '/tmp/vagrant-cache/omnibus_chef' : '/tmp'
|
159
|
+
chef_installation(conf[:chef_bootstrap_url], omnibus_download_dir, nil)
|
160
|
+
end
|
169
161
|
|
162
|
+
def chef_installation(chef_url, omnibus_download_dir, transport)
|
170
163
|
if chef_url
|
171
164
|
scripts = []
|
172
|
-
|
173
165
|
scripts << Util.shell_helpers
|
174
|
-
|
175
|
-
scripts << <<-INSTALL
|
176
|
-
if [ ! -d "/opt/chef" ]
|
177
|
-
then
|
178
|
-
echo "-----> Installing Chef Omnibus needed by busser and serverspec"
|
179
|
-
mkdir -p #{omnibus_download_dir}
|
180
|
-
if [ ! -x #{omnibus_download_dir}/install.sh ]
|
181
|
-
then
|
182
|
-
do_download #{chef_url} #{omnibus_download_dir}/install.sh
|
183
|
-
fi
|
184
|
-
|
185
|
-
sudo sh #{omnibus_download_dir}/install.sh -d #{omnibus_download_dir}
|
186
|
-
echo "-----> End Installing Chef Omnibus"
|
187
|
-
fi
|
188
|
-
INSTALL
|
189
|
-
|
190
|
-
if (older_version) and(version_string.split('.').map{|s|s.to_i} <=> [1, 6, 0]) < 0
|
191
|
-
info("Ansible Version < 1.6.0")
|
192
|
-
scripts << <<-INSTALL
|
193
|
-
# Older versions of ansible do not set up python-apt or
|
194
|
-
# python-pycurl by default on Ubuntu
|
195
|
-
# https://github.com/ansible/ansible/issues/4079
|
196
|
-
# https://github.com/ansible/ansible/issues/6910
|
197
|
-
echo "-----> Installing python-apt, python-pycurl if needed"
|
198
|
-
/usr/bin/python -c "import apt, apt_pkg, pycurl" 2>&1 > /dev/null || \
|
199
|
-
{ [ -x /usr/bin/apt-get ] && \
|
200
|
-
sudo /usr/bin/apt-get update && \
|
201
|
-
sudo /usr/bin/apt-get install python-apt python-pycurl -y -q \
|
202
|
-
; }
|
203
|
-
echo "-----> End Installing python-apt, python-pycurl if needed"
|
204
|
-
INSTALL
|
205
|
-
end
|
206
|
-
|
207
|
-
scripts << <<-INSTALL
|
208
|
-
# Fix for https://github.com/test-kitchen/busser/issues/12
|
209
|
-
if [ -h /usr/bin/ruby ]; then
|
210
|
-
L=$(readlink -f /usr/bin/ruby)
|
211
|
-
sudo rm /usr/bin/ruby
|
212
|
-
sudo ln -s $L /usr/bin/ruby
|
213
|
-
fi
|
214
|
-
INSTALL
|
215
|
-
|
166
|
+
scripts << chef_installation_script(chef_url, omnibus_download_dir, transport)
|
216
167
|
<<-INSTALL
|
217
168
|
sh -c '#{scripts.join("\n")}'
|
218
169
|
INSTALL
|
@@ -220,21 +171,23 @@ module Kitchen
|
|
220
171
|
end
|
221
172
|
|
222
173
|
def run_command
|
223
|
-
info(
|
224
|
-
exec_ansible_command(command_env
|
174
|
+
info('*************** AnsiblePush run ***************')
|
175
|
+
exec_ansible_command(command_env, command, 'ansible-playbook')
|
225
176
|
# idempotency test
|
226
177
|
if conf[:idempotency_test]
|
227
|
-
info(
|
178
|
+
info('*************** idempotency test ***************')
|
228
179
|
file_path = "/tmp/kitchen_ansible_callback/#{SecureRandom.uuid}.changes"
|
229
|
-
exec_ansible_command(
|
230
|
-
|
231
|
-
|
232
|
-
|
180
|
+
exec_ansible_command(
|
181
|
+
command_env.merge(
|
182
|
+
'ANSIBLE_CALLBACK_PLUGINS' => "#{File.dirname(__FILE__)}/../../../callback/",
|
183
|
+
'PLUGIN_CHANGES_FILE' => file_path
|
184
|
+
), command, 'ansible-playbook'
|
185
|
+
)
|
233
186
|
# Check ansible callback if changes has occured in the second run
|
234
187
|
if File.file?(file_path)
|
235
188
|
task = 0
|
236
|
-
info(
|
237
|
-
File.open(file_path,
|
189
|
+
info('idempotency test [Failed]')
|
190
|
+
File.open(file_path, 'r') do |f|
|
238
191
|
f.each_line do |line|
|
239
192
|
task += 1
|
240
193
|
info(" #{task}> #{line.strip}")
|
@@ -243,67 +196,70 @@ module Kitchen
|
|
243
196
|
if conf[:fail_non_idempotent]
|
244
197
|
raise "idempotency test Failed. Number of non idempotent tasks: #{task}"
|
245
198
|
else
|
246
|
-
info(
|
199
|
+
info('Warning idempotency test [failed]')
|
247
200
|
end
|
248
201
|
else
|
249
|
-
info(
|
202
|
+
info('idempotency test [passed]')
|
250
203
|
end
|
251
204
|
end
|
252
|
-
info(
|
205
|
+
info('*************** AnsiblePush end run *******************')
|
253
206
|
debug("[#{name}] Converge completed (#{conf[:sleep]}s).")
|
254
|
-
# Place holder so a string is returned. This will execute true on remote host
|
255
|
-
|
207
|
+
# Place holder so a string is returned. This will execute true on remote host
|
208
|
+
'true'
|
256
209
|
end
|
257
210
|
|
258
211
|
protected
|
259
212
|
|
260
213
|
def exec_ansible_command(env, command, desc)
|
261
|
-
debug(
|
262
|
-
system(env,
|
214
|
+
debug('env=%s command=%s' % [env, command])
|
215
|
+
system(env, command.to_s)
|
263
216
|
exit_code = $?.exitstatus
|
264
217
|
debug("ansible-playbook exit code = #{exit_code}")
|
265
218
|
if exit_code.to_i != 0
|
266
|
-
raise
|
219
|
+
raise '%s returned a non zero \'%s\'. Please see the output above.' % [desc, exit_code.to_s]
|
267
220
|
end
|
268
221
|
end
|
269
222
|
|
270
223
|
def instance_connection_option
|
271
224
|
return @instance_connection_option if defined? @instance_connection_option
|
272
225
|
@instance_connection_option = instance.transport.instance_variable_get(:@connection_options)
|
273
|
-
debug(
|
226
|
+
debug('instance_connection_option=' + @instance_connection_option.to_s)
|
274
227
|
@instance_connection_option
|
275
228
|
end
|
276
229
|
|
277
230
|
def prepare_inventory
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
debug("hostname="
|
284
|
-
|
285
|
-
|
231
|
+
if instance_connection_option.nil?
|
232
|
+
hostname = machine_name
|
233
|
+
else
|
234
|
+
hostname = instance_connection_option[:hostname]
|
235
|
+
end
|
236
|
+
debug("hostname='#{hostname}")
|
237
|
+
# Generate hosts
|
238
|
+
hosts = generate_instance_inventory(machine_name, hostname, conf[:mygroup], instance_connection_option)
|
239
|
+
write_var_to_yaml("#{TEMP_INV_DIR}/ansiblepush_host_#{machine_name}.yml", hosts)
|
240
|
+
# Generate groups (if defined)
|
241
|
+
write_var_to_yaml(TEMP_GROUP_FILE, conf[:groups]) if conf[:groups]
|
286
242
|
end
|
287
243
|
|
288
|
-
def
|
289
|
-
if conf[:extra_vars].kind_of?(String)
|
244
|
+
def extra_vars_argument
|
245
|
+
if conf[:extra_vars].kind_of?(String) && conf[:extra_vars] =~ /^@.+$/
|
290
246
|
# A JSON or YAML file is referenced (requires Ansible 1.3+)
|
291
|
-
|
247
|
+
conf[:extra_vars]
|
292
248
|
else
|
293
|
-
|
294
|
-
|
295
|
-
|
249
|
+
# Expected to be a Hash after config validation. (extra_vars as
|
250
|
+
# JSON requires Ansible 1.2+, while YAML requires Ansible 1.3+)
|
251
|
+
conf[:extra_vars].to_json
|
296
252
|
end
|
297
253
|
end
|
298
254
|
|
299
|
-
def
|
255
|
+
def remote_user
|
300
256
|
if conf[:remote_user]
|
301
|
-
|
302
|
-
elsif !instance_connection_option
|
303
|
-
conf[:remote_user] = instance_connection_option
|
304
|
-
|
257
|
+
conf[:remote_user]
|
258
|
+
elsif !instance_connection_option.nil? && instance_connection_option[:username]
|
259
|
+
conf[:remote_user] = instance_connection_option[:username]
|
260
|
+
instance_connection_option[:username]
|
305
261
|
else
|
306
|
-
|
262
|
+
false
|
307
263
|
end
|
308
264
|
end
|
309
265
|
|
@@ -311,16 +267,15 @@ module Kitchen
|
|
311
267
|
v.kind_of?(Array) ? v.join(',') : v
|
312
268
|
end
|
313
269
|
|
314
|
-
def
|
270
|
+
def verbosity_argument
|
315
271
|
if conf[:verbose].to_s =~ /^v+$/
|
316
272
|
# ansible-playbook accepts "silly" arguments like '-vvvvv' as '-vvvv' for now
|
317
|
-
|
273
|
+
"-#{conf[:verbose]}"
|
318
274
|
else
|
319
|
-
|
320
|
-
|
275
|
+
# safe default, in case input strays
|
276
|
+
'-v'
|
321
277
|
end
|
322
278
|
end
|
323
|
-
|
324
279
|
end
|
325
280
|
end
|
326
281
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
def chef_installation_script(chef_url, omnibus_download_dir, transport)
|
3
|
+
<<-INSTALL
|
4
|
+
if [ ! -d "/opt/chef" ]
|
5
|
+
then
|
6
|
+
echo "-----> Installing Chef Omnibus needed by busser and serverspec"
|
7
|
+
mkdir -p #{omnibus_download_dir}
|
8
|
+
if [ ! -x #{omnibus_download_dir}/install.sh ]
|
9
|
+
then
|
10
|
+
do_download #{chef_url} #{omnibus_download_dir}/install.sh
|
11
|
+
fi
|
12
|
+
sudo sh #{omnibus_download_dir}/install.sh -d #{omnibus_download_dir}
|
13
|
+
echo "-----> End Installing Chef Omnibus"
|
14
|
+
fi
|
15
|
+
INSTALL
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
TEMP_INV_DIR = '.kitchen/ansiblepush'.freeze
|
3
|
+
TEMP_GROUP_FILE = "#{TEMP_INV_DIR}/ansiblepush_groups_inventory.yml".freeze
|
4
|
+
|
5
|
+
def write_var_to_yaml(yaml_file, hash_var)
|
6
|
+
Dir.mkdir TEMP_INV_DIR unless File.exist?(TEMP_INV_DIR)
|
7
|
+
File.open(yaml_file, 'w') do |file|
|
8
|
+
file.write hash_var.to_yaml
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_instance_inventory(name, host, mygroup, instance_connection_option)
|
13
|
+
unless instance_connection_option.nil?
|
14
|
+
port = instance_connection_option[:port]
|
15
|
+
keys = instance_connection_option[:keys]
|
16
|
+
user = instance_connection_option[:user]
|
17
|
+
end
|
18
|
+
|
19
|
+
temp_hash = {}
|
20
|
+
temp_hash['ansible_ssh_host'] = host
|
21
|
+
temp_hash['ansible_ssh_port'] = port if port
|
22
|
+
temp_hash['ansible_ssh_private_key_file'] = keys[0] if keys
|
23
|
+
temp_hash['ansible_ssh_user'] = user if user
|
24
|
+
temp_hash['mygroup'] = mygroup if mygroup
|
25
|
+
{ name => temp_hash }
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-ansiblepush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adham Helal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-kitchen
|
@@ -71,7 +71,8 @@ files:
|
|
71
71
|
- README.md
|
72
72
|
- callback/changes.py
|
73
73
|
- kitchen-ansiblepush.gemspec
|
74
|
-
- lib/kitchen-ansible/
|
74
|
+
- lib/kitchen-ansible/chef_installation.rb
|
75
|
+
- lib/kitchen-ansible/util_inventory.rb
|
75
76
|
- lib/kitchen-ansible/version.rb
|
76
77
|
- lib/kitchen/provisioner/ansible_push.rb
|
77
78
|
- bin/kitchen-ansible-inventory
|
@@ -1,33 +0,0 @@
|
|
1
|
-
TEMP_INV_DIR = ".kitchen/ansiblepush"
|
2
|
-
TEMP_GROUP_FILE = "#{TEMP_INV_DIR}/ansiblepush_groups_inventory.yml"
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def write_instance_inventory(name, host, mygroup, instance_connection_option)
|
7
|
-
Dir.mkdir TEMP_INV_DIR if !File.exist?(TEMP_INV_DIR)
|
8
|
-
|
9
|
-
unless instance_connection_option.nil?
|
10
|
-
port = instance_connection_option[:port]
|
11
|
-
keys = instance_connection_option[:keys]
|
12
|
-
user = instance_connection_option[:user]
|
13
|
-
end
|
14
|
-
|
15
|
-
temp_hash = Hash.new
|
16
|
-
temp_hash["ansible_ssh_host"] = host
|
17
|
-
temp_hash["ansible_ssh_port"] = port if port
|
18
|
-
temp_hash["ansible_ssh_private_key_file"] = keys[0] if keys
|
19
|
-
temp_hash["ansible_ssh_user"] = user if user
|
20
|
-
temp_hash["mygroup"] = mygroup if mygroup
|
21
|
-
|
22
|
-
host = { name => temp_hash }
|
23
|
-
File.open("%s/ansiblepush_host_%s.yml" % [TEMP_INV_DIR, name], "w") do |file|
|
24
|
-
file.write host.to_yaml
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def write_group_inventory(groups)
|
29
|
-
Dir.mkdir TEMP_INV_DIR if !File.exist?(TEMP_INV_DIR)
|
30
|
-
File.open(TEMP_GROUP_FILE, "w") do |file|
|
31
|
-
file.write groups.to_yaml
|
32
|
-
end
|
33
|
-
end
|