kitchen-ansible 0.45.4 → 0.45.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +232 -232
- data/kitchen-ansible.gemspec +39 -39
- data/lib/kitchen-ansible/version.rb +6 -6
- data/lib/kitchen/provisioner/ansible/config.rb +184 -178
- data/lib/kitchen/provisioner/ansible/librarian.rb +78 -78
- data/lib/kitchen/provisioner/ansible/os.rb +78 -72
- data/lib/kitchen/provisioner/ansible/os/alpine.rb +42 -0
- data/lib/kitchen/provisioner/ansible/os/amazon.rb +42 -42
- data/lib/kitchen/provisioner/ansible/os/darwin.rb +37 -0
- data/lib/kitchen/provisioner/ansible/os/debian.rb +69 -69
- data/lib/kitchen/provisioner/ansible/os/fedora.rb +60 -60
- data/lib/kitchen/provisioner/ansible/os/redhat.rb +70 -70
- data/lib/kitchen/provisioner/ansible/os/suse.rb +44 -44
- data/lib/kitchen/provisioner/ansible_playbook.rb +1090 -1073
- data/provisioner_options.md +129 -126
- metadata +18 -16
@@ -1,1073 +1,1090 @@
|
|
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
|
-
# See https://github.com/neillturner/kitchen-ansible/blob/master/provisioner_options.md
|
20
|
-
# for documentation configuration parameters with ansible_playbook provisioner.
|
21
|
-
#
|
22
|
-
|
23
|
-
require 'json'
|
24
|
-
require 'find'
|
25
|
-
require 'kitchen/provisioner/base'
|
26
|
-
require 'kitchen/provisioner/ansible/config'
|
27
|
-
require 'kitchen/provisioner/ansible/os'
|
28
|
-
require 'kitchen/provisioner/ansible/librarian'
|
29
|
-
|
30
|
-
module Kitchen
|
31
|
-
class Busser
|
32
|
-
def non_suite_dirs
|
33
|
-
%w(data)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
module Provisioner
|
38
|
-
#
|
39
|
-
# Ansible Playbook provisioner.
|
40
|
-
#
|
41
|
-
class AnsiblePlaybook < Base
|
42
|
-
attr_accessor :tmp_dir
|
43
|
-
|
44
|
-
def initialize(provisioner_config)
|
45
|
-
config = Kitchen::Provisioner::Ansible::Config.new(provisioner_config)
|
46
|
-
super(config)
|
47
|
-
|
48
|
-
@os = Kitchen::Provisioner::Ansible::Os.make(ansible_platform, config)
|
49
|
-
end
|
50
|
-
|
51
|
-
def finalize_config!(instance)
|
52
|
-
config.instance = instance
|
53
|
-
super(instance)
|
54
|
-
end
|
55
|
-
|
56
|
-
def verbosity_level(level = 1)
|
57
|
-
level = level.to_sym if level.is_a? String
|
58
|
-
log_levels = { info: 1, warn: 2, debug: 3, trace: 4 }
|
59
|
-
if level.is_a?(Symbol) && log_levels.include?(level)
|
60
|
-
# puts "Log Level is: #{log_levels[level]}"
|
61
|
-
log_levels[level]
|
62
|
-
elsif level.is_a?(Integer) && level > 0
|
63
|
-
# puts "Log Level is: #{level}"
|
64
|
-
level
|
65
|
-
else
|
66
|
-
fail 'Invalid ansible_verbosity setting. Valid values are: 1, 2, 3, 4 OR :info, :warn, :debug, :trace'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def install_command
|
71
|
-
if config[:require_ansible_omnibus]
|
72
|
-
cmd = install_omnibus_command
|
73
|
-
elsif config[:require_ansible_source]
|
74
|
-
info('Installing ansible from source')
|
75
|
-
cmd = install_ansible_from_source_command
|
76
|
-
elsif config[:require_pip]
|
77
|
-
info('Installing ansible through pip')
|
78
|
-
cmd = install_ansible_from_pip_command
|
79
|
-
elsif config[:require_ansible_repo]
|
80
|
-
if !@os.nil?
|
81
|
-
info("Installing ansible on #{@os.name}")
|
82
|
-
cmd = @os.install_command
|
83
|
-
else
|
84
|
-
info('Installing ansible, will try to determine platform os')
|
85
|
-
cmd = <<-INSTALL
|
86
|
-
|
87
|
-
if [ ! $(which ansible) ]; then
|
88
|
-
if [ -f /etc/fedora-release ]; then
|
89
|
-
#{Kitchen::Provisioner::Ansible::Os::Fedora.new('fedora', config).install_command}
|
90
|
-
elif [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then
|
91
|
-
if [ -z `grep -q 'Amazon Linux' /etc/system-release` ]; then
|
92
|
-
#{Kitchen::Provisioner::Ansible::Os::Redhat.new('redhat', config).install_command}
|
93
|
-
else
|
94
|
-
#{Kitchen::Provisioner::Ansible::Os::Amazon.new('amazon', config).install_command}
|
95
|
-
fi
|
96
|
-
elif [ -f /etc/SuSE-release ] || [ -f /etc/SUSE-brand ]; then
|
97
|
-
#{Kitchen::Provisioner::Ansible::Os::Suse.new('suse', config).install_command}
|
98
|
-
|
99
|
-
#{Kitchen::Provisioner::Ansible::Os::
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
install
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
if [ -
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
echo "----->
|
160
|
-
|
161
|
-
|
162
|
-
#{sudo_env('
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
#{
|
174
|
-
|
175
|
-
fi
|
176
|
-
|
177
|
-
#{
|
178
|
-
#{sudo_env('
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
#{
|
183
|
-
#
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
#
|
197
|
-
PACKAGES="ruby ruby-dev"
|
198
|
-
fi
|
199
|
-
fi
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
#
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
#
|
210
|
-
#
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
commands
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
if
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
end
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
end
|
326
|
-
|
327
|
-
if
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
cmd = "#{
|
360
|
-
cmd = "
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
cmd =
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
def
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
config[:
|
636
|
-
end
|
637
|
-
|
638
|
-
def
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
end
|
795
|
-
|
796
|
-
def
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
if
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
if
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
info('Preparing
|
887
|
-
|
888
|
-
if
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
info 'nothing to do for
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
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
|
+
# See https://github.com/neillturner/kitchen-ansible/blob/master/provisioner_options.md
|
20
|
+
# for documentation configuration parameters with ansible_playbook provisioner.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'json'
|
24
|
+
require 'find'
|
25
|
+
require 'kitchen/provisioner/base'
|
26
|
+
require 'kitchen/provisioner/ansible/config'
|
27
|
+
require 'kitchen/provisioner/ansible/os'
|
28
|
+
require 'kitchen/provisioner/ansible/librarian'
|
29
|
+
|
30
|
+
module Kitchen
|
31
|
+
class Busser
|
32
|
+
def non_suite_dirs
|
33
|
+
%w(data)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module Provisioner
|
38
|
+
#
|
39
|
+
# Ansible Playbook provisioner.
|
40
|
+
#
|
41
|
+
class AnsiblePlaybook < Base
|
42
|
+
attr_accessor :tmp_dir
|
43
|
+
|
44
|
+
def initialize(provisioner_config)
|
45
|
+
config = Kitchen::Provisioner::Ansible::Config.new(provisioner_config)
|
46
|
+
super(config)
|
47
|
+
|
48
|
+
@os = Kitchen::Provisioner::Ansible::Os.make(ansible_platform, config)
|
49
|
+
end
|
50
|
+
|
51
|
+
def finalize_config!(instance)
|
52
|
+
config.instance = instance
|
53
|
+
super(instance)
|
54
|
+
end
|
55
|
+
|
56
|
+
def verbosity_level(level = 1)
|
57
|
+
level = level.to_sym if level.is_a? String
|
58
|
+
log_levels = { info: 1, warn: 2, debug: 3, trace: 4 }
|
59
|
+
if level.is_a?(Symbol) && log_levels.include?(level)
|
60
|
+
# puts "Log Level is: #{log_levels[level]}"
|
61
|
+
log_levels[level]
|
62
|
+
elsif level.is_a?(Integer) && level > 0
|
63
|
+
# puts "Log Level is: #{level}"
|
64
|
+
level
|
65
|
+
else
|
66
|
+
fail 'Invalid ansible_verbosity setting. Valid values are: 1, 2, 3, 4 OR :info, :warn, :debug, :trace'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def install_command
|
71
|
+
if config[:require_ansible_omnibus]
|
72
|
+
cmd = install_omnibus_command
|
73
|
+
elsif config[:require_ansible_source]
|
74
|
+
info('Installing ansible from source')
|
75
|
+
cmd = install_ansible_from_source_command
|
76
|
+
elsif config[:require_pip]
|
77
|
+
info('Installing ansible through pip')
|
78
|
+
cmd = install_ansible_from_pip_command
|
79
|
+
elsif config[:require_ansible_repo]
|
80
|
+
if !@os.nil?
|
81
|
+
info("Installing ansible on #{@os.name}")
|
82
|
+
cmd = @os.install_command
|
83
|
+
else
|
84
|
+
info('Installing ansible, will try to determine platform os')
|
85
|
+
cmd = <<-INSTALL
|
86
|
+
|
87
|
+
if [ ! $(which ansible) ]; then
|
88
|
+
if [ -f /etc/fedora-release ]; then
|
89
|
+
#{Kitchen::Provisioner::Ansible::Os::Fedora.new('fedora', config).install_command}
|
90
|
+
elif [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then
|
91
|
+
if [ -z `grep -q 'Amazon Linux' /etc/system-release` ]; then
|
92
|
+
#{Kitchen::Provisioner::Ansible::Os::Redhat.new('redhat', config).install_command}
|
93
|
+
else
|
94
|
+
#{Kitchen::Provisioner::Ansible::Os::Amazon.new('amazon', config).install_command}
|
95
|
+
fi
|
96
|
+
elif [ -f /etc/SuSE-release ] || [ -f /etc/SUSE-brand ]; then
|
97
|
+
#{Kitchen::Provisioner::Ansible::Os::Suse.new('suse', config).install_command}
|
98
|
+
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
99
|
+
#{Kitchen::Provisioner::Ansible::Os::Darwin.new('darwin', config).install_command}
|
100
|
+
elif [ -f /etc/alpine-release ] || [ -d /etc/apk ]; then
|
101
|
+
#{Kitchen::Provisioner::Ansible::Os::Alpine.new('alpine', config).install_command}
|
102
|
+
else
|
103
|
+
#{Kitchen::Provisioner::Ansible::Os::Debian.new('debian', config).install_command}
|
104
|
+
fi
|
105
|
+
fi
|
106
|
+
INSTALL
|
107
|
+
end
|
108
|
+
else
|
109
|
+
return
|
110
|
+
end
|
111
|
+
result = cmd + install_windows_support + install_busser_prereqs
|
112
|
+
debug("Going to install ansible with: #{result}")
|
113
|
+
result
|
114
|
+
end
|
115
|
+
|
116
|
+
def install_windows_support
|
117
|
+
install = ''
|
118
|
+
if require_windows_support
|
119
|
+
install << <<-INSTALL
|
120
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then
|
121
|
+
#{sudo_env('yum')} -y install python-devel krb5-devel krb5-libs krb5-workstation gcc
|
122
|
+
else
|
123
|
+
if [ -f /etc/SuSE-release ] || [ -f /etc/SUSE-brand ]; then
|
124
|
+
#{sudo_env('zypper')} ar #{python_sles_repo}
|
125
|
+
#{sudo_env('zypper')} --non-interactive install python python-devel krb5-client pam_krb5
|
126
|
+
else
|
127
|
+
#{sudo_env('apt-get')} -y install python-dev libkrb5-dev build-essential
|
128
|
+
fi
|
129
|
+
fi
|
130
|
+
#{export_http_proxy}
|
131
|
+
#{sudo_env('easy_install')} pip
|
132
|
+
#{sudo_env('pip')} install pywinrm kerberos
|
133
|
+
INSTALL
|
134
|
+
end
|
135
|
+
install
|
136
|
+
end
|
137
|
+
|
138
|
+
def install_busser_prereqs
|
139
|
+
install = ''
|
140
|
+
install << <<-INSTALL
|
141
|
+
#{Util.shell_helpers}
|
142
|
+
# Fix for https://github.com/test-kitchen/busser/issues/12
|
143
|
+
if [ -h /usr/bin/ruby ]; then
|
144
|
+
L=$(readlink -f /usr/bin/ruby)
|
145
|
+
#{sudo_env('rm')} /usr/bin/ruby
|
146
|
+
#{sudo_env('ln')} -s $L /usr/bin/ruby
|
147
|
+
fi
|
148
|
+
INSTALL
|
149
|
+
|
150
|
+
if require_ruby_for_busser
|
151
|
+
install << <<-INSTALL
|
152
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then
|
153
|
+
if [ -z `grep -q 'Amazon Linux' /etc/system-release` ]; then
|
154
|
+
rhelversion6=$(cat /etc/redhat-release | grep 'release 6')
|
155
|
+
rhelversion7=$(cat /etc/redhat-release | grep 'release 7')
|
156
|
+
# For CentOS6/CentOS7/RHEL6/RHEL7 install ruby from SCL
|
157
|
+
if [ -n "$rhelversion6" ] || [ -n "$rhelversion7" ]; then
|
158
|
+
if [ ! -d "/opt/rh/ruby200" ]; then
|
159
|
+
echo "-----> Installing ruby200 SCL in CentOS6/CentOS7/RHEL6/RHEL7 to install busser to run tests"
|
160
|
+
#{sudo_env('yum')} install -y centos-release-scl
|
161
|
+
#{sudo_env('yum')} install -y ruby200
|
162
|
+
#{sudo_env('yum')} install -y ruby200-ruby-devel
|
163
|
+
echo "-----> Enabling ruby200"
|
164
|
+
source /opt/rh/ruby200/enable
|
165
|
+
echo "/opt/rh/ruby200/root/usr/lib64" | sudo tee -a /etc/ld.so.conf
|
166
|
+
#{sudo_env('ldconfig')}
|
167
|
+
#{sudo_env('ln')} -sf /opt/rh/ruby200/root/usr/bin/ruby /usr/bin/ruby
|
168
|
+
#{sudo_env('ln')} -sf /opt/rh/ruby200/root/usr/bin/gem /usr/bin/gem
|
169
|
+
fi
|
170
|
+
else
|
171
|
+
if [ ! $(which ruby) ]; then
|
172
|
+
#{update_packages_redhat_cmd}
|
173
|
+
#{sudo_env('yum')} -y install ruby ruby-devel
|
174
|
+
fi
|
175
|
+
fi
|
176
|
+
else
|
177
|
+
#{update_packages_redhat_cmd}
|
178
|
+
#{sudo_env('yum')} -y install ruby ruby-devel gcc
|
179
|
+
fi
|
180
|
+
elif [ -f /etc/SuSE-release ] || [ -f /etc/SUSE-brand ]; then
|
181
|
+
#{update_packages_suse_cmd}
|
182
|
+
#{sudo_env('zypper')} --non-interactive install ruby ruby-devel ca-certificates ca-certificates-cacert ca-certificates-mozilla
|
183
|
+
#{sudo_env('gem')} sources --add https://rubygems.org/
|
184
|
+
elif [ -f /etc/alpine-release ] || [ -d /etc/apk ]; then
|
185
|
+
#{update_packages_alpine_cmd}
|
186
|
+
#{sudo_env('apk')} add ruby ruby-dev ruby-io-console ca-certificates
|
187
|
+
else
|
188
|
+
if [ ! $(which ruby) ]; then
|
189
|
+
#{update_packages_debian_cmd}
|
190
|
+
# default package selection for Debian/Ubuntu machines
|
191
|
+
PACKAGES="ruby1.9.1 ruby1.9.1-dev"
|
192
|
+
if [ "$(lsb_release -si)" = "Debian" ]; then
|
193
|
+
debvers=$(sed 's/\\..*//' /etc/debian_version)
|
194
|
+
if [ $debvers -ge 8 ]; then
|
195
|
+
# this is jessie or better, where ruby1.9.1 is
|
196
|
+
# no longer in the repositories
|
197
|
+
PACKAGES="ruby ruby-dev ruby2.1 ruby2.1-dev"
|
198
|
+
fi
|
199
|
+
fi
|
200
|
+
if [ "$(lsb_release -si)" = "Ubuntu" ]; then
|
201
|
+
ubuntuvers=$(lsb_release -sr | tr -d .)
|
202
|
+
if [ $ubuntuvers -ge 1410 ]; then
|
203
|
+
# Default ruby is 2.x in utopic and newer
|
204
|
+
PACKAGES="ruby ruby-dev"
|
205
|
+
fi
|
206
|
+
fi
|
207
|
+
#{sudo_env('apt-get')} -y install $PACKAGES
|
208
|
+
if [ $debvers -eq 6 ]; then
|
209
|
+
# in squeeze we need to update alternatives
|
210
|
+
# for enable ruby1.9.1
|
211
|
+
ALTERNATIVES_STRING="--install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 10 --slave /usr/share/man/man1/ruby.1.gz ruby.1.gz /usr/share/man/man1/ruby1.9.1.1.gz --slave /usr/bin/erb erb /usr/bin/erb1.9.1 --slave /usr/bin/gem gem /usr/bin/gem1.9.1 --slave /usr/bin/irb irb /usr/bin/irb1.9.1 --slave /usr/bin/rake rake /usr/bin/rake1.9.1 --slave /usr/bin/rdoc rdoc /usr/bin/rdoc1.9.1 --slave /usr/bin/testrb testrb /usr/bin/testrb1.9.1 --slave /usr/share/man/man1/erb.1.gz erb.1.gz /usr/share/man/man1/erb1.9.1.1.gz --slave /usr/share/man/man1/gem.1.gz gem.1.gz /usr/share/man/man1/gem1.9.1.1.gz --slave /usr/share/man/man1/irb.1.gz irb.1.gz /usr/share/man/man1/irb1.9.1.1.gz --slave /usr/share/man/man1/rake.1.gz rake.1.gz /usr/share/man/man1/rake1.9.1.1.gz --slave /usr/share/man/man1/rdoc.1.gz rdoc.1.gz /usr/share/man/man1/rdoc1.9.1.1.gz --slave /usr/share/man/man1/testrb.1.gz testrb.1.gz /usr/share/man/man1/testrb1.9.1.1.gz"
|
212
|
+
#{sudo_env('update-alternatives')} $ALTERNATIVES_STRING
|
213
|
+
# need to update gem tool because gem 1.3.7 from ruby 1.9.1 is broken
|
214
|
+
#{sudo_env('gem')} install rubygems-update
|
215
|
+
#{sudo_env('/var/lib/gems/1.9.1/bin/update_rubygems')}
|
216
|
+
# clear local gem cache
|
217
|
+
#{sudo_env('rm')} -r /home/vagrant/.gem
|
218
|
+
fi
|
219
|
+
fi
|
220
|
+
fi
|
221
|
+
INSTALL
|
222
|
+
|
223
|
+
elsif require_chef_for_busser && chef_url
|
224
|
+
install << <<-INSTALL
|
225
|
+
# install chef omnibus so that busser works as this is needed to run tests :(
|
226
|
+
if [ ! -d "/opt/chef" ]
|
227
|
+
then
|
228
|
+
echo "-----> Installing Chef Omnibus to install busser to run tests"
|
229
|
+
#{export_http_proxy}
|
230
|
+
do_download #{chef_url} /tmp/install.sh
|
231
|
+
#{sudo_env('sh')} /tmp/install.sh
|
232
|
+
fi
|
233
|
+
INSTALL
|
234
|
+
end
|
235
|
+
|
236
|
+
install
|
237
|
+
end
|
238
|
+
|
239
|
+
def init_command
|
240
|
+
dirs = %w(modules roles group_vars host_vars)
|
241
|
+
.map { |dir| File.join(config[:root_path], dir) }.join(' ')
|
242
|
+
cmd = "#{sudo_env('rm')} -rf #{dirs};"
|
243
|
+
cmd += " mkdir -p #{config[:root_path]}"
|
244
|
+
debug(cmd)
|
245
|
+
cmd
|
246
|
+
end
|
247
|
+
|
248
|
+
def create_sandbox
|
249
|
+
super
|
250
|
+
debug("Creating local sandbox in #{sandbox_path}")
|
251
|
+
|
252
|
+
yield if block_given?
|
253
|
+
|
254
|
+
prepare_playbook
|
255
|
+
prepare_inventory
|
256
|
+
prepare_modules
|
257
|
+
prepare_roles
|
258
|
+
prepare_ansible_cfg
|
259
|
+
prepare_group_vars
|
260
|
+
prepare_additional_copy_path
|
261
|
+
prepare_host_vars
|
262
|
+
prepare_hosts
|
263
|
+
prepare_spec
|
264
|
+
prepare_library_plugins
|
265
|
+
prepare_callback_plugins
|
266
|
+
prepare_filter_plugins
|
267
|
+
prepare_lookup_plugins
|
268
|
+
prepare_ansible_vault_password_file
|
269
|
+
prepare_kerberos_conf_file
|
270
|
+
info('Finished Preparing files for transfer')
|
271
|
+
end
|
272
|
+
|
273
|
+
def cleanup_sandbox
|
274
|
+
return if sandbox_path.nil?
|
275
|
+
debug("Cleaning up local sandbox in #{sandbox_path}")
|
276
|
+
FileUtils.rmtree(sandbox_path)
|
277
|
+
end
|
278
|
+
|
279
|
+
def prepare_command
|
280
|
+
commands = []
|
281
|
+
|
282
|
+
# Prevent failure when ansible package installation doesn't contain /etc/ansible
|
283
|
+
commands << [
|
284
|
+
sudo_env("#{config[:shell_command]} -c '[ -d /etc/ansible ] || mkdir /etc/ansible'")
|
285
|
+
]
|
286
|
+
|
287
|
+
commands << [
|
288
|
+
sudo_env('cp'), File.join(config[:root_path], 'ansible.cfg'), '/etc/ansible'
|
289
|
+
].join(' ')
|
290
|
+
|
291
|
+
commands << [
|
292
|
+
sudo_env('cp -r'), File.join(config[:root_path], 'group_vars'), '/etc/ansible/.'
|
293
|
+
].join(' ')
|
294
|
+
|
295
|
+
commands << [
|
296
|
+
sudo_env('cp -r'), File.join(config[:root_path], 'host_vars'), '/etc/ansible/.'
|
297
|
+
].join(' ')
|
298
|
+
|
299
|
+
if config[:ssh_known_hosts]
|
300
|
+
config[:ssh_known_hosts].each do |host|
|
301
|
+
info("Add #{host} to ~/.ssh/known_hosts")
|
302
|
+
commands << "ssh-keyscan #{host} > ~/.ssh/known_hosts 2> /dev/null"
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
if ansible_inventory
|
307
|
+
if File.directory?(ansible_inventory)
|
308
|
+
Dir.foreach(ansible_inventory) do |f|
|
309
|
+
next if f == "." or f == ".."
|
310
|
+
contents = File.open("#{ansible_inventory}/#{f}", 'rb') { |g| g.read }
|
311
|
+
if contents.start_with?('#!')
|
312
|
+
commands << [
|
313
|
+
sudo_env('chmod +x'), File.join("#{config[:root_path]}/#{File.basename(ansible_inventory)}", File.basename(f))
|
314
|
+
].join(' ')
|
315
|
+
end
|
316
|
+
end
|
317
|
+
else
|
318
|
+
contents = File.open(ansible_inventory, 'rb') { |f| f.read }
|
319
|
+
if contents.start_with?('#!')
|
320
|
+
commands << [
|
321
|
+
sudo_env('chmod +x'), File.join(config[:root_path], File.basename(ansible_inventory))
|
322
|
+
].join(' ')
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
if galaxy_requirements
|
328
|
+
if config[:require_ansible_source]
|
329
|
+
commands << setup_ansible_env_from_source
|
330
|
+
end
|
331
|
+
commands << ansible_galaxy_command
|
332
|
+
end
|
333
|
+
|
334
|
+
if kerberos_conf_file
|
335
|
+
commands << [
|
336
|
+
sudo_env('cp -f'), File.join(config[:root_path], 'krb5.conf'), '/etc'
|
337
|
+
].join(' ')
|
338
|
+
end
|
339
|
+
|
340
|
+
command = commands.join(' && ')
|
341
|
+
debug(command)
|
342
|
+
command
|
343
|
+
end
|
344
|
+
|
345
|
+
def run_command
|
346
|
+
if !config[:ansible_playbook_command].nil?
|
347
|
+
return config[:ansible_playbook_command]
|
348
|
+
else
|
349
|
+
|
350
|
+
if config[:require_ansible_source] && !config[:ansible_binary_path]
|
351
|
+
# this is an ugly hack to get around the fact that extra vars uses ' and "
|
352
|
+
cmd = ansible_command("PATH=#{config[:root_path]}/ansible/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games PYTHONPATH=#{config[:root_path]}/ansible/lib MANPATH=#{config[:root_path]}/ansible/docs/man ansible-playbook")
|
353
|
+
elsif config[:ansible_binary_path]
|
354
|
+
cmd = ansible_command("#{config[:ansible_binary_path]}/ansible-playbook")
|
355
|
+
else
|
356
|
+
cmd = ansible_command('ansible-playbook')
|
357
|
+
end
|
358
|
+
|
359
|
+
cmd = "#{env_vars} #{cmd}" if !config[:env_vars].none?
|
360
|
+
cmd = "HTTPS_PROXY=#{https_proxy} #{cmd}" if https_proxy
|
361
|
+
cmd = "HTTP_PROXY=#{http_proxy} #{cmd}" if http_proxy
|
362
|
+
cmd = "NO_PROXY=#{no_proxy} #{cmd}" if no_proxy
|
363
|
+
cmd = "ANSIBLE_ROLES_PATH=#{ansible_roles_path} #{cmd}" if ansible_roles_path
|
364
|
+
cmd = "ANSIBLE_HOST_KEY_CHECKING=false #{cmd}" if !ansible_host_key_checking
|
365
|
+
|
366
|
+
cmd = "#{cd_ansible} #{cmd}" if !config[:ansible_sudo].nil? && !config[:ansible_sudo]
|
367
|
+
cmd = "#{copy_private_key_cmd} #{cmd}" if config[:private_key]
|
368
|
+
|
369
|
+
result = [
|
370
|
+
cmd,
|
371
|
+
ansible_inventory_flag,
|
372
|
+
ansible_limit_flag,
|
373
|
+
ansible_connection_flag,
|
374
|
+
"-M #{File.join(config[:root_path], 'modules')}",
|
375
|
+
ansible_verbose_flag,
|
376
|
+
ansible_check_flag,
|
377
|
+
ansible_diff_flag,
|
378
|
+
ansible_vault_flag,
|
379
|
+
private_key,
|
380
|
+
extra_vars,
|
381
|
+
tags,
|
382
|
+
ansible_extra_flags,
|
383
|
+
"#{File.join(config[:root_path], File.basename(config[:playbook]))}"
|
384
|
+
].join(' ')
|
385
|
+
debug("Going to invoke ansible-playbook with: #{result}")
|
386
|
+
if config[:idempotency_test]
|
387
|
+
result = "#{result} && (echo 'Going to invoke ansible-playbook second time:'; #{result} | tee /tmp/idempotency_test.txt; grep -q 'changed=0.*failed=0' /tmp/idempotency_test.txt && (echo 'Idempotence test: PASS' && exit 0) || (echo 'Idempotence test: FAIL' && exit 1))"
|
388
|
+
debug("Full cmd with idempotency test: #{result}")
|
389
|
+
end
|
390
|
+
|
391
|
+
result
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
def ansible_command(script)
|
396
|
+
if config[:ansible_sudo].nil? || config[:ansible_sudo] == true
|
397
|
+
s = https_proxy ? "https_proxy=#{https_proxy}" : nil
|
398
|
+
p = http_proxy ? "http_proxy=#{http_proxy}" : nil
|
399
|
+
n = no_proxy ? "no_proxy=#{no_proxy}" : nil
|
400
|
+
p || s || n ? " #{p} #{s} #{n} #{config[:sudo_command]} -s #{cd_ansible} #{script}" : "#{config[:sudo_command]} -s #{cd_ansible} #{script}"
|
401
|
+
else
|
402
|
+
return script
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
def ansible_galaxy_command
|
407
|
+
cmd = [
|
408
|
+
'ansible-galaxy', 'install', '--force',
|
409
|
+
'-p', File.join(config[:root_path], 'roles'),
|
410
|
+
'-r', File.join(config[:root_path], galaxy_requirements)
|
411
|
+
].join(' ')
|
412
|
+
cmd = "https_proxy=#{https_proxy} #{cmd}" if https_proxy
|
413
|
+
cmd = "http_proxy=#{http_proxy} #{cmd}" if http_proxy
|
414
|
+
cmd = "no_proxy=#{no_proxy} #{cmd}" if no_proxy
|
415
|
+
cmd
|
416
|
+
end
|
417
|
+
|
418
|
+
def cd_ansible
|
419
|
+
# this is not working so just return nil for now
|
420
|
+
# File.exist?('ansible.cfg') ? "cd #{config[:root_path]};" : nil
|
421
|
+
nil
|
422
|
+
end
|
423
|
+
|
424
|
+
protected
|
425
|
+
|
426
|
+
def load_needed_dependencies!
|
427
|
+
return unless File.exist?(ansiblefile)
|
428
|
+
|
429
|
+
debug("Ansiblefile found at #{ansiblefile}, loading Librarian-Ansible")
|
430
|
+
Ansible::Librarian.load!(logger)
|
431
|
+
end
|
432
|
+
|
433
|
+
def install_ansible_from_source_command
|
434
|
+
<<-INSTALL
|
435
|
+
if [ ! -d #{config[:root_path]}/ansible ]; then
|
436
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then
|
437
|
+
#{Kitchen::Provisioner::Ansible::Os::Redhat.new('redhat', config).install_epel_repo}
|
438
|
+
#{update_packages_redhat_cmd}
|
439
|
+
#{sudo_env('yum')} -y install libselinux-python python2-devel git python-setuptools python-setuptools-dev libffi-devel libssl-devel
|
440
|
+
else
|
441
|
+
if [ -f /etc/SUSE-brand ] || [ -f /etc/SuSE-release ]; then
|
442
|
+
#{sudo_env('zypper')} ar #{python_sles_repo}
|
443
|
+
#{update_packages_suse_cmd}
|
444
|
+
#{sudo_env('zypper')} --non-interactive install python python-devel git python-setuptools python-pip python-six libyaml-devel libffi-devel libopenssl-devel
|
445
|
+
else
|
446
|
+
#{update_packages_debian_cmd}
|
447
|
+
#{sudo_env('apt-get')} -y install git python python-setuptools build-essential python-dev libffi-dev libssl-dev
|
448
|
+
fi
|
449
|
+
fi
|
450
|
+
|
451
|
+
#{export_http_proxy}
|
452
|
+
git clone git://github.com/ansible/ansible.git --recursive #{config[:root_path]}/ansible #{install_source_rev}
|
453
|
+
#{sudo_env('easy_install')} pip
|
454
|
+
#{sudo_env('pip')} install -U setuptools
|
455
|
+
#{sudo_env('pip')} install six paramiko PyYAML Jinja2 httplib2
|
456
|
+
fi
|
457
|
+
INSTALL
|
458
|
+
end
|
459
|
+
|
460
|
+
def install_ansible_from_pip_command
|
461
|
+
ansible_version = ''
|
462
|
+
ansible_version = "==#{config[:ansible_version]}" unless config[:ansible_version] == 'latest'
|
463
|
+
|
464
|
+
<<-INSTALL
|
465
|
+
if [ ! -d #{config[:root_path]}/ansible ]; then
|
466
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then
|
467
|
+
#{Kitchen::Provisioner::Ansible::Os::Redhat.new('redhat', config).install_epel_repo}
|
468
|
+
#{update_packages_redhat_cmd}
|
469
|
+
#{sudo_env('yum')} -y install libselinux-python python2-devel git python-setuptools python-setuptools-dev libffi-devel openssl-devel gcc
|
470
|
+
else
|
471
|
+
if [ -f /etc/SUSE-brand ] || [ -f /etc/SuSE-release ]; then
|
472
|
+
#{sudo_env('zypper')} ar #{python_sles_repo}
|
473
|
+
#{update_packages_suse_cmd}
|
474
|
+
#{sudo_env('zypper')} --non-interactive install python python-devel git python-setuptools python-pip python-six libyaml-devel libffi-devel libopenssl-devel
|
475
|
+
else
|
476
|
+
#{update_packages_debian_cmd}
|
477
|
+
#{sudo_env('apt-get')} -y install git python python-setuptools build-essential python-dev libffi-dev libssl-dev
|
478
|
+
fi
|
479
|
+
fi
|
480
|
+
|
481
|
+
#{export_http_proxy}
|
482
|
+
#{sudo_env('easy_install')} pip
|
483
|
+
#{sudo_env('pip')} install -U setuptools
|
484
|
+
#{sudo_env('pip')} install ansible#{ansible_version}
|
485
|
+
fi
|
486
|
+
INSTALL
|
487
|
+
end
|
488
|
+
|
489
|
+
def install_omnibus_command
|
490
|
+
info('Installing ansible using ansible omnibus')
|
491
|
+
|
492
|
+
version = ''
|
493
|
+
version = "-v #{config[:ansible_version]}" unless config[:ansible_version].nil?
|
494
|
+
|
495
|
+
<<-INSTALL
|
496
|
+
#{Util.shell_helpers}
|
497
|
+
|
498
|
+
if [ ! -d "#{config[:ansible_omnibus_remote_path]}" ]; then
|
499
|
+
echo "-----> Installing Ansible Omnibus"
|
500
|
+
#{export_http_proxy}
|
501
|
+
do_download #{config[:ansible_omnibus_url]} /tmp/ansible_install.sh
|
502
|
+
#{sudo_env(config[:shell_command])} /tmp/ansible_install.sh #{version}
|
503
|
+
fi
|
504
|
+
INSTALL
|
505
|
+
end
|
506
|
+
|
507
|
+
def setup_ansible_env_from_source
|
508
|
+
"cd #{config[:root_path]}/ansible && source hacking/env-setup && cd ../"
|
509
|
+
end
|
510
|
+
|
511
|
+
def tmp_modules_dir
|
512
|
+
File.join(sandbox_path, 'modules')
|
513
|
+
end
|
514
|
+
|
515
|
+
def tmp_playbook_path
|
516
|
+
File.join(sandbox_path, File.basename(playbook))
|
517
|
+
end
|
518
|
+
|
519
|
+
def tmp_host_vars_dir
|
520
|
+
File.join(sandbox_path, 'host_vars')
|
521
|
+
end
|
522
|
+
|
523
|
+
def tmp_roles_dir
|
524
|
+
File.join(sandbox_path, 'roles')
|
525
|
+
end
|
526
|
+
|
527
|
+
def tmp_spec_dir
|
528
|
+
File.join(sandbox_path, 'spec')
|
529
|
+
end
|
530
|
+
|
531
|
+
def tmp_library_plugins_dir
|
532
|
+
File.join(sandbox_path, 'library')
|
533
|
+
end
|
534
|
+
|
535
|
+
def tmp_callback_plugins_dir
|
536
|
+
File.join(sandbox_path, 'callback_plugins')
|
537
|
+
end
|
538
|
+
|
539
|
+
def tmp_filter_plugins_dir
|
540
|
+
File.join(sandbox_path, 'filter_plugins')
|
541
|
+
end
|
542
|
+
|
543
|
+
def tmp_lookup_plugins_dir
|
544
|
+
File.join(sandbox_path, 'lookup_plugins')
|
545
|
+
end
|
546
|
+
|
547
|
+
def tmp_ansible_vault_password_file_path
|
548
|
+
File.join(sandbox_path, File.basename(ansible_vault_password_file).reverse.chomp('.').reverse)
|
549
|
+
end
|
550
|
+
|
551
|
+
def tmp_kerberos_conf_file_path
|
552
|
+
File.join(sandbox_path, 'krb5.conf')
|
553
|
+
end
|
554
|
+
|
555
|
+
def tmp_inventory_path
|
556
|
+
File.join(sandbox_path, File.basename(ansible_inventory))
|
557
|
+
end
|
558
|
+
|
559
|
+
def ansiblefile
|
560
|
+
config[:ansiblefile_path] || ''
|
561
|
+
end
|
562
|
+
|
563
|
+
def galaxy_requirements
|
564
|
+
config[:requirements_path] || nil
|
565
|
+
end
|
566
|
+
|
567
|
+
def env_vars
|
568
|
+
return nil if config[:env_vars].none?
|
569
|
+
config[:env_vars].map { |k, v| "#{k}=#{v}" }.join(' ')
|
570
|
+
end
|
571
|
+
|
572
|
+
def playbook
|
573
|
+
config[:playbook]
|
574
|
+
end
|
575
|
+
|
576
|
+
def hosts
|
577
|
+
config[:hosts]
|
578
|
+
end
|
579
|
+
|
580
|
+
def roles
|
581
|
+
config[:roles_path]
|
582
|
+
end
|
583
|
+
|
584
|
+
def role_name
|
585
|
+
if config[:role_name]
|
586
|
+
config[:role_name]
|
587
|
+
elsif File.basename(roles) == 'roles'
|
588
|
+
''
|
589
|
+
else
|
590
|
+
File.basename(roles)
|
591
|
+
end
|
592
|
+
end
|
593
|
+
|
594
|
+
def modules
|
595
|
+
config[:modules_path]
|
596
|
+
end
|
597
|
+
|
598
|
+
def spec
|
599
|
+
'spec'
|
600
|
+
end
|
601
|
+
|
602
|
+
def group_vars
|
603
|
+
config[:group_vars_path].to_s
|
604
|
+
end
|
605
|
+
|
606
|
+
def additional_copy
|
607
|
+
config[:additional_copy_path]
|
608
|
+
end
|
609
|
+
|
610
|
+
def ansible_cfg_path
|
611
|
+
config[:ansible_cfg_path]
|
612
|
+
end
|
613
|
+
|
614
|
+
def recursive_additional_copy
|
615
|
+
config[:recursive_additional_copy_path]
|
616
|
+
end
|
617
|
+
|
618
|
+
def host_vars
|
619
|
+
config[:host_vars_path].to_s
|
620
|
+
end
|
621
|
+
|
622
|
+
def library_plugins
|
623
|
+
config[:library_plugins_path].to_s
|
624
|
+
end
|
625
|
+
|
626
|
+
def callback_plugins
|
627
|
+
config[:callback_plugins_path].to_s
|
628
|
+
end
|
629
|
+
|
630
|
+
def filter_plugins
|
631
|
+
config[:filter_plugins_path].to_s
|
632
|
+
end
|
633
|
+
|
634
|
+
def lookup_plugins
|
635
|
+
config[:lookup_plugins_path].to_s
|
636
|
+
end
|
637
|
+
|
638
|
+
def ansible_vault_password_file
|
639
|
+
config[:ansible_vault_password_file]
|
640
|
+
end
|
641
|
+
|
642
|
+
def ansible_inventory
|
643
|
+
return nil if config[:ansible_inventory] == 'none'
|
644
|
+
config[:ansible_inventory] = config[:ansible_inventory_file] if config[:ansible_inventory].nil?
|
645
|
+
info('ansible_inventory_file parameter deprecated use ansible_inventory') if config[:ansible_inventory_file]
|
646
|
+
config[:ansible_inventory]
|
647
|
+
end
|
648
|
+
|
649
|
+
def ansible_debian_version
|
650
|
+
if @config[:ansible_version] == 'latest' || @config[:ansible_version] == nil
|
651
|
+
''
|
652
|
+
else
|
653
|
+
"=#{@config[:ansible_version]}"
|
654
|
+
end
|
655
|
+
end
|
656
|
+
|
657
|
+
def ansible_connection_flag
|
658
|
+
"-c #{config[:ansible_connection]}" if config[:ansible_connection] != 'none'
|
659
|
+
end
|
660
|
+
|
661
|
+
def ansible_verbose_flag
|
662
|
+
config[:ansible_verbose] ? '-' << ('v' * verbosity_level(config[:ansible_verbosity])) : nil
|
663
|
+
end
|
664
|
+
|
665
|
+
def ansible_check_flag
|
666
|
+
config[:ansible_check] ? '--check' : nil
|
667
|
+
end
|
668
|
+
|
669
|
+
def ansible_diff_flag
|
670
|
+
config[:ansible_diff] ? '--diff' : nil
|
671
|
+
end
|
672
|
+
|
673
|
+
def ansible_vault_flag
|
674
|
+
debug(config[:ansible_vault_password_file])
|
675
|
+
config[:ansible_vault_password_file] ? "--vault-password-file=#{File.join(config[:root_path], File.basename(config[:ansible_vault_password_file]).reverse.chomp('.').reverse)}" : nil
|
676
|
+
end
|
677
|
+
|
678
|
+
def ansible_inventory_flag
|
679
|
+
return nil if config[:ansible_inventory] == 'none'
|
680
|
+
ansible_inventory ? "-i #{File.join(config[:root_path], File.basename(ansible_inventory))}" : "-i #{File.join(config[:root_path], 'hosts')}"
|
681
|
+
end
|
682
|
+
|
683
|
+
def ansible_limit_flag
|
684
|
+
config[:ansible_limit] ? "-l #{config[:ansible_limit]}" : ""
|
685
|
+
end
|
686
|
+
|
687
|
+
def ansible_extra_flags
|
688
|
+
config[:ansible_extra_flags] || ''
|
689
|
+
end
|
690
|
+
|
691
|
+
def ansible_platform
|
692
|
+
config[:ansible_platform].to_s.downcase
|
693
|
+
end
|
694
|
+
|
695
|
+
def ansible_host_key_checking
|
696
|
+
config[:ansible_host_key_checking]
|
697
|
+
end
|
698
|
+
|
699
|
+
def private_key
|
700
|
+
if config[:private_key]
|
701
|
+
"--private-key #{private_key_file}"
|
702
|
+
end
|
703
|
+
end
|
704
|
+
|
705
|
+
def copy_private_key_cmd
|
706
|
+
if !config[:private_key].start_with?('/') && !config[:private_key].start_with?('~')
|
707
|
+
ssh_private_key = File.join('~/.ssh', File.basename(config[:private_key]))
|
708
|
+
tmp_private_key = File.join(config[:root_path], config[:private_key])
|
709
|
+
"rm -rf #{ssh_private_key}; cp #{tmp_private_key} #{ssh_private_key}; chmod 400 #{ssh_private_key};"
|
710
|
+
end
|
711
|
+
end
|
712
|
+
|
713
|
+
def private_key_file
|
714
|
+
if config[:private_key].start_with?('/') || config[:private_key].start_with?('~')
|
715
|
+
"#{config[:private_key]}"
|
716
|
+
elsif config[:private_key]
|
717
|
+
"#{File.join('~/.ssh', File.basename(config[:private_key]))}"
|
718
|
+
end
|
719
|
+
end
|
720
|
+
|
721
|
+
def update_packages_debian_cmd
|
722
|
+
Kitchen::Provisioner::Ansible::Os::Debian.new('debian', config).update_packages_command
|
723
|
+
end
|
724
|
+
|
725
|
+
def update_packages_suse_cmd
|
726
|
+
Kitchen::Provisioner::Ansible::Os::Suse.new('suse', config).update_packages_command
|
727
|
+
end
|
728
|
+
|
729
|
+
def update_packages_redhat_cmd
|
730
|
+
Kitchen::Provisioner::Ansible::Os::Redhat.new('redhat', config).update_packages_command
|
731
|
+
end
|
732
|
+
|
733
|
+
def update_packages_alpine_cmd
|
734
|
+
Kitchen::Provisioner::Ansible::Os::Alpine.new('alpine', config).update_packages_command
|
735
|
+
end
|
736
|
+
|
737
|
+
def python_sles_repo
|
738
|
+
config[:python_sles_repo]
|
739
|
+
end
|
740
|
+
|
741
|
+
def extra_vars
|
742
|
+
bash_vars = config[:extra_vars]
|
743
|
+
if config.key?(:attributes) && config[:attributes].key?(:extra_vars) && config[:attributes][:extra_vars].is_a?(Hash)
|
744
|
+
bash_vars = config[:attributes][:extra_vars]
|
745
|
+
end
|
746
|
+
|
747
|
+
return nil if bash_vars.none?
|
748
|
+
bash_vars = JSON.dump(bash_vars)
|
749
|
+
bash_vars = "-e '#{bash_vars}'"
|
750
|
+
debug(bash_vars)
|
751
|
+
bash_vars
|
752
|
+
end
|
753
|
+
|
754
|
+
def tags
|
755
|
+
bash_tags = config.key?(:attributes) && config[:attributes].key?(:tags) && config[:attributes][:tags].is_a?(Array) ? config[:attributes][:tags] : config[:tags]
|
756
|
+
return nil if bash_tags.empty?
|
757
|
+
|
758
|
+
bash_tags = bash_tags.join(',')
|
759
|
+
bash_tags = "-t '#{bash_tags}'"
|
760
|
+
debug(bash_tags)
|
761
|
+
bash_tags
|
762
|
+
end
|
763
|
+
|
764
|
+
def chef_url
|
765
|
+
config[:chef_bootstrap_url]
|
766
|
+
end
|
767
|
+
|
768
|
+
def require_ruby_for_busser
|
769
|
+
config[:require_ruby_for_busser]
|
770
|
+
end
|
771
|
+
|
772
|
+
def require_chef_for_busser
|
773
|
+
config[:require_chef_for_busser]
|
774
|
+
end
|
775
|
+
|
776
|
+
def require_windows_support
|
777
|
+
config[:require_windows_support]
|
778
|
+
end
|
779
|
+
|
780
|
+
def kerberos_conf_file
|
781
|
+
config[:kerberos_conf_file]
|
782
|
+
end
|
783
|
+
|
784
|
+
def install_source_rev
|
785
|
+
config[:ansible_source_rev] ? "--branch #{config[:ansible_source_rev]}" : nil
|
786
|
+
end
|
787
|
+
|
788
|
+
def http_proxy
|
789
|
+
config[:http_proxy]
|
790
|
+
end
|
791
|
+
|
792
|
+
def https_proxy
|
793
|
+
config[:https_proxy]
|
794
|
+
end
|
795
|
+
|
796
|
+
def no_proxy
|
797
|
+
config[:no_proxy]
|
798
|
+
end
|
799
|
+
|
800
|
+
def sudo_env(pm,home=false)
|
801
|
+
s = https_proxy ? "https_proxy=#{https_proxy}" : nil
|
802
|
+
p = http_proxy ? "http_proxy=#{http_proxy}" : nil
|
803
|
+
n = no_proxy ? "no_proxy=#{no_proxy}" : nil
|
804
|
+
if home
|
805
|
+
p || s || n ? "#{sudo_home('env')} #{p} #{s} #{n} #{pm}" : "#{sudo_home(pm)}"
|
806
|
+
else
|
807
|
+
p || s || n ? "#{sudo('env')} #{p} #{s} #{n} #{pm}" : "#{sudo(pm)}"
|
808
|
+
end
|
809
|
+
end
|
810
|
+
|
811
|
+
def export_http_proxy
|
812
|
+
cmd = ''
|
813
|
+
cmd = " HTTP_PROXY=#{http_proxy}" if http_proxy
|
814
|
+
cmd = "#{cmd} HTTPS_PROXY=#{https_proxy}" if https_proxy
|
815
|
+
cmd = "#{cmd} NO_PROXY=#{no_proxy}" if no_proxy
|
816
|
+
cmd = "export #{cmd}" if cmd != ''
|
817
|
+
cmd
|
818
|
+
end
|
819
|
+
|
820
|
+
def ansible_roles_path
|
821
|
+
roles_paths = []
|
822
|
+
roles_paths << File.join(config[:root_path], 'roles') unless config[:roles_path].nil?
|
823
|
+
if config[:additional_copy_role_path]
|
824
|
+
config[:additional_copy_role_path].each do |additional_role_path|
|
825
|
+
roles_paths << File.join(config[:root_path], File.basename(additional_role_path))
|
826
|
+
end
|
827
|
+
end
|
828
|
+
if roles_paths.empty?
|
829
|
+
info('No roles have been set.')
|
830
|
+
nil
|
831
|
+
else
|
832
|
+
debug("Setting roles_path inside VM to #{ roles_paths.join(':') }")
|
833
|
+
roles_paths.join(':')
|
834
|
+
end
|
835
|
+
end
|
836
|
+
|
837
|
+
def prepare_roles
|
838
|
+
info('Preparing roles')
|
839
|
+
debug("Using roles from #{roles}")
|
840
|
+
|
841
|
+
resolve_with_librarian if File.exist?(ansiblefile)
|
842
|
+
|
843
|
+
if galaxy_requirements
|
844
|
+
dest = File.join(sandbox_path, galaxy_requirements)
|
845
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
846
|
+
FileUtils.cp(galaxy_requirements, dest)
|
847
|
+
end
|
848
|
+
|
849
|
+
FileUtils.mkdir_p(File.join(tmp_roles_dir, role_name))
|
850
|
+
Find.find(roles) do |source|
|
851
|
+
# Detect whether we are running tests on a role
|
852
|
+
# If so, make sure to copy into VM so dir structure is like: /tmp/kitchen/roles/role_name
|
853
|
+
role_path = source.sub(/#{roles}|\/roles/, '')
|
854
|
+
unless roles =~ /\/roles$/
|
855
|
+
role_path = "#{role_name}/#{role_path}"
|
856
|
+
end
|
857
|
+
|
858
|
+
target = File.join(tmp_roles_dir, role_path)
|
859
|
+
|
860
|
+
Find.prune if config[:ignore_paths_from_root].include? File.basename(source)
|
861
|
+
Find.prune if config[:ignore_extensions_from_root].include? File.extname(source)
|
862
|
+
if File.directory?(source)
|
863
|
+
FileUtils.mkdir_p(target)
|
864
|
+
else
|
865
|
+
FileUtils.cp(source, target)
|
866
|
+
end
|
867
|
+
end
|
868
|
+
end
|
869
|
+
|
870
|
+
# copy ansible.cfg if found
|
871
|
+
def prepare_ansible_cfg
|
872
|
+
info('Preparing ansible.cfg file')
|
873
|
+
ansible_config_file = "#{File.join(sandbox_path, 'ansible.cfg')}"
|
874
|
+
if !ansible_cfg_path.nil? && File.exist?(ansible_cfg_path)
|
875
|
+
info('Found existing ansible.cfg')
|
876
|
+
FileUtils.cp_r(ansible_cfg_path, ansible_config_file)
|
877
|
+
else
|
878
|
+
info('Empty ansible.cfg generated')
|
879
|
+
File.open(ansible_config_file, 'wb') do |file|
|
880
|
+
file.write("#no config parameters\n")
|
881
|
+
end
|
882
|
+
end
|
883
|
+
end
|
884
|
+
|
885
|
+
def prepare_inventory
|
886
|
+
info('Preparing inventory')
|
887
|
+
return unless ansible_inventory
|
888
|
+
if File.directory?(ansible_inventory)
|
889
|
+
debug("Copying inventory directory from #{ansible_inventory} to #{tmp_inventory_path}")
|
890
|
+
FileUtils.cp_r(ansible_inventory, sandbox_path)
|
891
|
+
else
|
892
|
+
debug("Copying inventory file from #{ansible_inventory} to #{tmp_inventory_path}")
|
893
|
+
FileUtils.cp_r(ansible_inventory, tmp_inventory_path)
|
894
|
+
end
|
895
|
+
end
|
896
|
+
|
897
|
+
# localhost ansible_connection=local
|
898
|
+
# [example_servers]
|
899
|
+
# localhost
|
900
|
+
def prepare_hosts
|
901
|
+
return if ansible_inventory
|
902
|
+
info('Preparing hosts file')
|
903
|
+
|
904
|
+
if config[:hosts].nil?
|
905
|
+
fail 'No hosts have been set. Please specify one in .kitchen.yml'
|
906
|
+
else
|
907
|
+
debug("Using host from #{hosts}")
|
908
|
+
File.open(File.join(sandbox_path, 'hosts'), 'wb') do |file|
|
909
|
+
file.write("localhost ansible_connection=local\n[#{hosts}]\nlocalhost\n")
|
910
|
+
end
|
911
|
+
end
|
912
|
+
end
|
913
|
+
|
914
|
+
def prepare_playbook
|
915
|
+
info('Preparing playbook')
|
916
|
+
debug("Copying playbook from #{playbook} to #{tmp_playbook_path}")
|
917
|
+
FileUtils.cp_r(playbook, tmp_playbook_path)
|
918
|
+
end
|
919
|
+
|
920
|
+
def prepare_group_vars
|
921
|
+
info('Preparing group_vars')
|
922
|
+
tmp_group_vars_dir = File.join(sandbox_path, 'group_vars')
|
923
|
+
FileUtils.mkdir_p(tmp_group_vars_dir)
|
924
|
+
|
925
|
+
unless File.directory?(group_vars)
|
926
|
+
info('nothing to do for group_vars')
|
927
|
+
return
|
928
|
+
end
|
929
|
+
|
930
|
+
debug("Using group_vars from #{group_vars}")
|
931
|
+
FileUtils.cp_r(Dir.glob("#{group_vars}/*"), tmp_group_vars_dir)
|
932
|
+
end
|
933
|
+
|
934
|
+
def prepare_additional_copy_path
|
935
|
+
info('Preparing additional_copy_path')
|
936
|
+
additional_files.each do |file|
|
937
|
+
info("Copy additional path: #{file}")
|
938
|
+
destination = File.join(sandbox_path, File.basename(file))
|
939
|
+
if File.directory?(file)
|
940
|
+
debug("Copy dir: #{file} #{destination}")
|
941
|
+
FileUtils.cp_r(file, destination)
|
942
|
+
else
|
943
|
+
debug("Copy file: #{file} #{destination}")
|
944
|
+
FileUtils.cp(file, destination)
|
945
|
+
end
|
946
|
+
end
|
947
|
+
recursive_additional_files.each do |file|
|
948
|
+
info("Copy recursive additional path: #{file}")
|
949
|
+
Find.find(file) do |files|
|
950
|
+
destination = File.join(sandbox_path, files)
|
951
|
+
Find.prune if config[:ignore_paths_from_root].include? File.basename(files)
|
952
|
+
Find.prune if config[:ignore_extensions_from_root].include? File.extname(files)
|
953
|
+
if File.directory?(files)
|
954
|
+
FileUtils.mkdir_p(destination)
|
955
|
+
else
|
956
|
+
FileUtils.cp(files, destination)
|
957
|
+
end
|
958
|
+
end
|
959
|
+
end
|
960
|
+
end
|
961
|
+
|
962
|
+
def additional_files
|
963
|
+
additional_files = []
|
964
|
+
if additional_copy
|
965
|
+
additional_files = additional_copy.is_a?(Array) ? additional_copy : [additional_copy]
|
966
|
+
end
|
967
|
+
additional_files.map(&:to_s)
|
968
|
+
end
|
969
|
+
|
970
|
+
def recursive_additional_files
|
971
|
+
recursive_additional_files = []
|
972
|
+
if recursive_additional_copy
|
973
|
+
recursive_additional_files = recursive_additional_copy.is_a?(Array) ? recursive_additional_copy : [recursive_additional_copy]
|
974
|
+
end
|
975
|
+
recursive_additional_files.map(&:to_s)
|
976
|
+
end
|
977
|
+
|
978
|
+
def prepare_host_vars
|
979
|
+
info('Preparing host_vars')
|
980
|
+
FileUtils.mkdir_p(tmp_host_vars_dir)
|
981
|
+
|
982
|
+
unless File.directory?(host_vars)
|
983
|
+
info 'nothing to do for host_vars'
|
984
|
+
return
|
985
|
+
end
|
986
|
+
|
987
|
+
debug("Using host_vars from #{host_vars}")
|
988
|
+
FileUtils.cp_r(Dir.glob("#{host_vars}/*"), tmp_host_vars_dir)
|
989
|
+
end
|
990
|
+
|
991
|
+
def prepare_modules
|
992
|
+
info('Preparing modules')
|
993
|
+
|
994
|
+
FileUtils.mkdir_p(tmp_modules_dir)
|
995
|
+
|
996
|
+
if modules && File.directory?(modules)
|
997
|
+
debug("Using modules from #{modules}")
|
998
|
+
FileUtils.cp_r(Dir.glob("#{modules}/*"), tmp_modules_dir, remove_destination: true)
|
999
|
+
else
|
1000
|
+
info 'nothing to do for modules'
|
1001
|
+
end
|
1002
|
+
end
|
1003
|
+
|
1004
|
+
def prepare_spec
|
1005
|
+
info('Preparing spec')
|
1006
|
+
|
1007
|
+
FileUtils.mkdir_p(tmp_spec_dir)
|
1008
|
+
|
1009
|
+
if spec && File.directory?(spec)
|
1010
|
+
debug("Using spec from #{spec}")
|
1011
|
+
FileUtils.cp_r(Dir.glob("#{spec}/*"), tmp_spec_dir, remove_destination: true)
|
1012
|
+
else
|
1013
|
+
info 'nothing to do for spec'
|
1014
|
+
end
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
def prepare_library_plugins
|
1018
|
+
info('Preparing library plugins')
|
1019
|
+
FileUtils.mkdir_p(tmp_library_plugins_dir)
|
1020
|
+
|
1021
|
+
if library_plugins && File.directory?(library_plugins)
|
1022
|
+
debug("Using library plugins from #{library_plugins}")
|
1023
|
+
FileUtils.cp_r(Dir.glob("#{library_plugins}/{*,!*.pyc}"), tmp_library_plugins_dir, remove_destination: true)
|
1024
|
+
else
|
1025
|
+
info 'nothing to do for library plugins'
|
1026
|
+
end
|
1027
|
+
end
|
1028
|
+
|
1029
|
+
def prepare_callback_plugins
|
1030
|
+
info('Preparing callback plugins')
|
1031
|
+
FileUtils.mkdir_p(tmp_callback_plugins_dir)
|
1032
|
+
|
1033
|
+
if callback_plugins && File.directory?(callback_plugins)
|
1034
|
+
debug("Using callback plugins from #{callback_plugins}")
|
1035
|
+
FileUtils.cp_r(Dir.glob("#{callback_plugins}/{*,!*.pyc}"), tmp_callback_plugins_dir, remove_destination: true)
|
1036
|
+
else
|
1037
|
+
info 'nothing to do for callback plugins'
|
1038
|
+
end
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
def prepare_filter_plugins
|
1042
|
+
info('Preparing filter_plugins')
|
1043
|
+
FileUtils.mkdir_p(tmp_filter_plugins_dir)
|
1044
|
+
|
1045
|
+
if filter_plugins && File.directory?(filter_plugins)
|
1046
|
+
debug("Using filter_plugins from #{filter_plugins}")
|
1047
|
+
FileUtils.cp_r(Dir.glob("#{filter_plugins}/*.py"), tmp_filter_plugins_dir, remove_destination: true)
|
1048
|
+
else
|
1049
|
+
info 'nothing to do for filter_plugins'
|
1050
|
+
end
|
1051
|
+
end
|
1052
|
+
|
1053
|
+
def prepare_lookup_plugins
|
1054
|
+
info('Preparing lookup_plugins')
|
1055
|
+
FileUtils.mkdir_p(tmp_lookup_plugins_dir)
|
1056
|
+
|
1057
|
+
if lookup_plugins && File.directory?(lookup_plugins)
|
1058
|
+
debug("Using lookup_plugins from #{lookup_plugins}")
|
1059
|
+
FileUtils.cp_r(Dir.glob("#{lookup_plugins}/*.py"), tmp_lookup_plugins_dir, remove_destination: true)
|
1060
|
+
else
|
1061
|
+
info 'nothing to do for lookup_plugins'
|
1062
|
+
end
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
def prepare_ansible_vault_password_file
|
1066
|
+
return unless ansible_vault_password_file
|
1067
|
+
|
1068
|
+
info('Preparing ansible vault password')
|
1069
|
+
debug("Copying ansible vault password file from #{ansible_vault_password_file} to #{tmp_ansible_vault_password_file_path}")
|
1070
|
+
|
1071
|
+
FileUtils.cp(ansible_vault_password_file, tmp_ansible_vault_password_file_path)
|
1072
|
+
end
|
1073
|
+
|
1074
|
+
def prepare_kerberos_conf_file
|
1075
|
+
return unless kerberos_conf_file
|
1076
|
+
|
1077
|
+
info('Preparing kerberos configuration file')
|
1078
|
+
debug("Copying kerberos configuration file from #{kerberos_conf_file} to #{tmp_kerberos_conf_file_path}")
|
1079
|
+
|
1080
|
+
FileUtils.cp(kerberos_conf_file, tmp_kerberos_conf_file_path)
|
1081
|
+
end
|
1082
|
+
|
1083
|
+
def resolve_with_librarian
|
1084
|
+
Kitchen.mutex.synchronize do
|
1085
|
+
Ansible::Librarian.new(ansiblefile, tmp_roles_dir, logger).resolve
|
1086
|
+
end
|
1087
|
+
end
|
1088
|
+
end
|
1089
|
+
end
|
1090
|
+
end
|