ansible_spec 0.3.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +45 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +0 -11
- data/README.md +4 -1
- data/ansible_spec.gemspec +3 -2
- data/lib/ansible_spec/load_ansible.rb +39 -20
- data/lib/ansible_spec/version.rb +1 -1
- data/lib/ansible_spec.rb +1 -1
- data/spec/case/get_variable/empty_group/group_vars/group_a.yml +2 -0
- data/spec/case/get_variable/empty_group/group_vars/group_b.yml +2 -0
- data/spec/case/get_variable/empty_group/hosts +3 -0
- data/spec/case/get_variable/empty_group/site.yml +9 -0
- data/spec/get_variable_spec.rb +39 -0
- metadata +13 -8
- data/.travis.yml +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4d6f9c6e42c88594d1b2cc2d7f18d96d172f2362e26fffac1a4a4e8b334600ab
|
|
4
|
+
data.tar.gz: f1d479135980a9cfa9a8e658ca9f55df3b95e63dba68e5d788347e892b477164
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1572a692ac1d26119f0646d48c626b2956d0944c9cd8339a75f1a16def2e14565254cf01ce7e06358825e627d007a6bd17c5aefa8f185205e87c3714689a0f8e
|
|
7
|
+
data.tar.gz: ee34a574f2f29f3c959c417d4587baed95b04ce278b7534b6d960f6b47737982f48174927084ca789ae753f2ebc5cbcd852df7e170fe7d40ee436adf98a19813
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
+
|
|
8
|
+
name: build
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [ main ]
|
|
13
|
+
pull_request:
|
|
14
|
+
branches: [ main ]
|
|
15
|
+
workflow_dispatch:
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
test:
|
|
19
|
+
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
strategy:
|
|
22
|
+
matrix:
|
|
23
|
+
# https://github.com/ruby/setup-ruby#supported-versions
|
|
24
|
+
# EOL >= 2.6
|
|
25
|
+
ruby-version: ['2.6.10', '2.7.7', '3.0.5', '3.1.3', '3.2.11', '3.3.12', '3.4.10']
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v3
|
|
29
|
+
- name: Set up Ruby
|
|
30
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
|
31
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
|
32
|
+
uses: ruby/setup-ruby@v1
|
|
33
|
+
#uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
|
34
|
+
with:
|
|
35
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
36
|
+
# 'latest', the latest compatible Bundler version is installed (Bundler 2 on Ruby >= 2.3, Bundler 1 on Ruby < 2.3).
|
|
37
|
+
bundler: latest
|
|
38
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
39
|
+
- name: Install dependencies
|
|
40
|
+
run: bundle install --jobs=3 --retry=3
|
|
41
|
+
- name: check env
|
|
42
|
+
run: |
|
|
43
|
+
bundle list
|
|
44
|
+
- name: Run tests
|
|
45
|
+
run: bundle exec rspec spec
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# v1.0.0
|
|
2
|
+
- Support Ruby 3.2, 3.3, 3.4
|
|
3
|
+
- Merge [#155 Support Ruby 3.2.11](https://github.com/volanja/ansible_spec/pull/155) by volanja
|
|
4
|
+
- Merge [#156 Add test case 3.3.12, 3.4.10](https://github.com/volanja/ansible_spec/pull/156) by volanja
|
|
5
|
+
|
|
6
|
+
# v0.3.2
|
|
7
|
+
- Merge [#135 Fix wrong index by empty group](https://github.com/volanja/ansible_spec/pull/135) by [mamiya312](https://github.com/mamiya312)
|
|
8
|
+
|
|
1
9
|
# v0.3.1
|
|
2
10
|
- Fix [#126 no implicit conversion of nil into Array Error when process get_parent](https://github.com/volanja/ansible_spec/issues/126) by [shogos3](https://github.com/shogos3)
|
|
3
11
|
|
data/Gemfile
CHANGED
|
@@ -3,17 +3,6 @@ source 'https://rubygems.org'
|
|
|
3
3
|
# Specify your gem's dependencies in ansible_spec.gemspec
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
|
-
if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
|
|
7
|
-
# net-ssh 3.x dropped Ruby 1.8 and 1.9 support.
|
|
8
|
-
gem 'net-ssh', '~> 2.7'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
if Gem::Version.new(RUBY_VERSION.dup) <= Gem::Version.new('1.9.3')
|
|
12
|
-
gem 'json', '~> 1.8.3'
|
|
13
|
-
# winrm 2.1.1 dropped Ruby 1.9 support.
|
|
14
|
-
gem 'winrm', '< 2.1.1'
|
|
15
|
-
end
|
|
16
|
-
|
|
17
6
|
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1')
|
|
18
7
|
# Ansible::Vault support Ruby 2.1.0 and higher.
|
|
19
8
|
gem 'ansible-vault'
|
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# ansible_spec
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/ansible_spec)
|
|
4
|
-
[](https://github.com/volanja/ansible_spec/actions/workflows/build.yml)
|
|
5
5
|
|
|
6
6
|
This is a Ruby gem that implements an Ansible Config Parser for Serverspec.
|
|
7
7
|
It creates a Rake task that can run tests, using Ansible inventory files
|
|
@@ -336,3 +336,6 @@ To contribute your change, create a GitHub pull request as follows:
|
|
|
336
336
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
337
337
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
338
338
|
5. Create new Pull Request at https://github.com/volanja/ansible_spec
|
|
339
|
+
|
|
340
|
+
# Old CI
|
|
341
|
+
[Travis CI - volanja/ansible_spec](https://travis-ci.org/github/volanja/ansible_spec)
|
data/ansible_spec.gemspec
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
lib = File.expand_path('../lib',
|
|
2
|
+
lib = File.expand_path('../lib', __dir__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
|
|
4
|
+
require_relative 'lib/ansible_spec/version'
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |gem|
|
|
7
7
|
gem.name = "ansible_spec"
|
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
|
|
|
17
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
gem.require_paths = ["lib"]
|
|
20
|
+
gem.required_ruby_version = '>= 2.1.0'
|
|
20
21
|
|
|
21
22
|
gem.add_development_dependency "bundler"
|
|
22
23
|
gem.add_development_dependency "rake"
|
|
@@ -190,7 +190,7 @@ module AnsibleSpec
|
|
|
190
190
|
f = '.ansiblespec'
|
|
191
191
|
y = nil
|
|
192
192
|
if File.exist?(f)
|
|
193
|
-
y =
|
|
193
|
+
y = load_yaml_file(f)
|
|
194
194
|
end
|
|
195
195
|
if ENV["PLAYBOOK"]
|
|
196
196
|
playbook = ENV["PLAYBOOK"]
|
|
@@ -226,7 +226,7 @@ module AnsibleSpec
|
|
|
226
226
|
path = File.join(rolepath, role, "meta", "main.yml")
|
|
227
227
|
|
|
228
228
|
if File.exist?(path)
|
|
229
|
-
dependencies =
|
|
229
|
+
dependencies = load_yaml_file(path).fetch("dependencies", [])
|
|
230
230
|
unless dependencies.nil?
|
|
231
231
|
new_deps = dependencies.map { |h|
|
|
232
232
|
h["role"] || h
|
|
@@ -243,21 +243,27 @@ module AnsibleSpec
|
|
|
243
243
|
# return: json
|
|
244
244
|
# {"name"=>"Ansible-Sample-TDD", "hosts"=>"server", "user"=>"root", "roles"=>["nginx", "mariadb"]}
|
|
245
245
|
def self.load_playbook(f)
|
|
246
|
-
playbook =
|
|
246
|
+
playbook = load_yaml_file(f)
|
|
247
247
|
|
|
248
248
|
# e.g. comment-out
|
|
249
249
|
if playbook === false
|
|
250
250
|
puts "Error: No data in #{f}"
|
|
251
251
|
exit
|
|
252
252
|
end
|
|
253
|
+
# for Ruby 3.1.
|
|
254
|
+
if playbook.nil?
|
|
255
|
+
puts "Error: No data in #{f}"
|
|
256
|
+
exit
|
|
257
|
+
end
|
|
258
|
+
|
|
253
259
|
properties = Array.new
|
|
254
260
|
playbook.each do |site|
|
|
255
261
|
if site.has_key?("include")
|
|
256
|
-
|
|
262
|
+
load_yaml_file(site["include"]).each { |site|
|
|
257
263
|
properties.push site
|
|
258
264
|
}
|
|
259
265
|
elsif site.has_key?("import_playbook")
|
|
260
|
-
|
|
266
|
+
load_yaml_file(site["import_playbook"]).each { |site|
|
|
261
267
|
properties.push site
|
|
262
268
|
}
|
|
263
269
|
else
|
|
@@ -313,7 +319,7 @@ module AnsibleSpec
|
|
|
313
319
|
f = '.ansiblespec'
|
|
314
320
|
y = nil
|
|
315
321
|
if File.exist?(f)
|
|
316
|
-
y =
|
|
322
|
+
y = load_yaml_file(f)
|
|
317
323
|
end
|
|
318
324
|
hash_behaviour = 'replace'
|
|
319
325
|
if ENV["HASH_BEHAVIOUR"]
|
|
@@ -377,12 +383,12 @@ module AnsibleSpec
|
|
|
377
383
|
if Ansible::Vault.encrypted?(vars_file)
|
|
378
384
|
yaml = load_encrypted_file(vars_file)
|
|
379
385
|
else
|
|
380
|
-
yaml =
|
|
386
|
+
yaml = load_yaml_file(vars_file)
|
|
381
387
|
end
|
|
382
388
|
vars = merge_variables(vars, yaml)
|
|
383
389
|
else
|
|
384
390
|
# Ruby 1.9 and 2.0
|
|
385
|
-
yaml =
|
|
391
|
+
yaml = load_yaml_file(vars_file)
|
|
386
392
|
vars = merge_variables(vars, yaml)
|
|
387
393
|
end
|
|
388
394
|
end
|
|
@@ -458,7 +464,7 @@ module AnsibleSpec
|
|
|
458
464
|
f = '.ansiblespec'
|
|
459
465
|
y = nil
|
|
460
466
|
if File.exist?(f)
|
|
461
|
-
y =
|
|
467
|
+
y = load_yaml_file(f)
|
|
462
468
|
end
|
|
463
469
|
if ENV["VARS_DIRS_PATH"]
|
|
464
470
|
vars_dirs_path = ENV["VARS_DIRS_PATH"]
|
|
@@ -477,7 +483,7 @@ module AnsibleSpec
|
|
|
477
483
|
target_host.keys[0]
|
|
478
484
|
end
|
|
479
485
|
|
|
480
|
-
# query replace jinja2 templates with target values
|
|
486
|
+
# query replace jinja2 templates with target values
|
|
481
487
|
# param: hash (cf. result self.get_variables)
|
|
482
488
|
# param: number of iterations if found_template
|
|
483
489
|
# return: hash
|
|
@@ -497,15 +503,15 @@ module AnsibleSpec
|
|
|
497
503
|
# ignore whitespaces (\s*)
|
|
498
504
|
# use non-greedy regex (.*?)
|
|
499
505
|
target = template.gsub(/{{\s*(.*?)\s*}}/, '\1')
|
|
500
|
-
|
|
506
|
+
|
|
501
507
|
# lookup value of target variable
|
|
502
508
|
value = vars[target]
|
|
503
|
-
|
|
509
|
+
|
|
504
510
|
# return lookup value if it exists
|
|
505
|
-
# or leave template alone
|
|
506
|
-
if value.nil?
|
|
511
|
+
# or leave template alone
|
|
512
|
+
if value.nil?
|
|
507
513
|
template
|
|
508
|
-
else
|
|
514
|
+
else
|
|
509
515
|
found_template = true
|
|
510
516
|
value
|
|
511
517
|
end
|
|
@@ -516,7 +522,7 @@ module AnsibleSpec
|
|
|
516
522
|
|
|
517
523
|
def self.get_variables(host, group_idx, hosts=nil)
|
|
518
524
|
vars = {}
|
|
519
|
-
p = self.get_properties
|
|
525
|
+
p = self.get_properties.compact.reject{|e| e["hosts"].length == 0}
|
|
520
526
|
|
|
521
527
|
# roles default
|
|
522
528
|
p[group_idx]['roles'].each do |role|
|
|
@@ -580,6 +586,16 @@ module AnsibleSpec
|
|
|
580
586
|
|
|
581
587
|
end
|
|
582
588
|
|
|
589
|
+
def self.load_yaml_file(file)
|
|
590
|
+
begin
|
|
591
|
+
# Psych::VERSION >= '3.1.0'
|
|
592
|
+
YAML.load_file(file, permitted_classes: [Symbol], aliases: true)
|
|
593
|
+
rescue ArgumentError
|
|
594
|
+
# Fallback for older Psych versions
|
|
595
|
+
YAML.load_file(file)
|
|
596
|
+
end
|
|
597
|
+
end
|
|
598
|
+
|
|
583
599
|
class AnsibleCfg
|
|
584
600
|
def initialize
|
|
585
601
|
@cfg = self.class.load_ansible_cfg
|
|
@@ -598,16 +614,19 @@ module AnsibleSpec
|
|
|
598
614
|
"./ansible.cfg",
|
|
599
615
|
ENV["ANSIBLE_CFG"],
|
|
600
616
|
].each do |f|
|
|
601
|
-
files << f if f and File.
|
|
617
|
+
files << f if f and File.exist? f
|
|
602
618
|
end
|
|
603
619
|
end
|
|
604
620
|
|
|
621
|
+
# return : Hash
|
|
605
622
|
def load_ansible_cfg()
|
|
606
|
-
|
|
623
|
+
cfg_hash = {}
|
|
607
624
|
self.find_ansible_cfgs.each do |file|
|
|
608
|
-
|
|
625
|
+
cfg_file = IniFile.new :filename => file
|
|
626
|
+
# Merge without calling tainted? method
|
|
627
|
+
cfg_hash.merge!(cfg_file.to_h)
|
|
609
628
|
end
|
|
610
|
-
|
|
629
|
+
cfg_hash # return Hash
|
|
611
630
|
end
|
|
612
631
|
end
|
|
613
632
|
|
data/lib/ansible_spec/version.rb
CHANGED
data/lib/ansible_spec.rb
CHANGED
data/spec/get_variable_spec.rb
CHANGED
|
@@ -362,6 +362,45 @@ describe "get_variablesの実行" do
|
|
|
362
362
|
end
|
|
363
363
|
end
|
|
364
364
|
|
|
365
|
+
# Fixed a problem that there is a gap between Index passed from Rakefile when empty group exists. by #135
|
|
366
|
+
# cat hosts
|
|
367
|
+
# [group_a] #no host
|
|
368
|
+
# [group_b]
|
|
369
|
+
# localhost.localdomain ansible_ssh_private_key_file=~/.ssh/id_rsa
|
|
370
|
+
|
|
371
|
+
context 'Correct operation : empty group PR #135 ' do
|
|
372
|
+
before do
|
|
373
|
+
@current_dir = Dir.pwd()
|
|
374
|
+
Dir.chdir('spec/case/get_variable/empty_group')
|
|
375
|
+
ENV["PLAYBOOK"] = 'site.yml'
|
|
376
|
+
ENV["INVENTORY"] = 'hosts'
|
|
377
|
+
ENV["VARS_DIRS_PATH"] = ''
|
|
378
|
+
@res = AnsibleSpec.get_variables("localhost.localdomain", 0)
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
it 'res is hash' do
|
|
382
|
+
expect(@res.instance_of?(Hash)).to be_truthy
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
it 'exist 1 pair in Hash' do
|
|
386
|
+
expect(@res.length).to eq 1
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
it 'get correct variable' do
|
|
390
|
+
expect(@res).to eq("group_b_var" => "fuga")
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
it 'not get incorrect variables' do
|
|
394
|
+
expect(@res).not_to eq("group_a_var" => "hoge")
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
after do
|
|
398
|
+
ENV.delete('PLAYBOOK')
|
|
399
|
+
ENV.delete('INVENTORY')
|
|
400
|
+
ENV.delete('VARS_DIRS_PATH')
|
|
401
|
+
Dir.chdir(@current_dir)
|
|
402
|
+
end
|
|
403
|
+
end
|
|
365
404
|
end
|
|
366
405
|
|
|
367
406
|
describe "get_hash_behaviourの実行" do
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ansible_spec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- volanja
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: bundler
|
|
@@ -159,9 +158,9 @@ executables:
|
|
|
159
158
|
extensions: []
|
|
160
159
|
extra_rdoc_files: []
|
|
161
160
|
files:
|
|
161
|
+
- ".github/workflows/build.yml"
|
|
162
162
|
- ".gitignore"
|
|
163
163
|
- ".rspec"
|
|
164
|
-
- ".travis.yml"
|
|
165
164
|
- CHANGELOG.md
|
|
166
165
|
- Gemfile
|
|
167
166
|
- LICENSE.txt
|
|
@@ -190,6 +189,10 @@ files:
|
|
|
190
189
|
- spec/case/get_variable/deep_merge/hosts
|
|
191
190
|
- spec/case/get_variable/deep_merge/roles/test/defaults/main.yml
|
|
192
191
|
- spec/case/get_variable/deep_merge/site.yml
|
|
192
|
+
- spec/case/get_variable/empty_group/group_vars/group_a.yml
|
|
193
|
+
- spec/case/get_variable/empty_group/group_vars/group_b.yml
|
|
194
|
+
- spec/case/get_variable/empty_group/hosts
|
|
195
|
+
- spec/case/get_variable/empty_group/site.yml
|
|
193
196
|
- spec/case/get_variable/group_all/group_vars/all.yml
|
|
194
197
|
- spec/case/get_variable/group_all/hosts
|
|
195
198
|
- spec/case/get_variable/group_all/roles/test/defaults/main.yml
|
|
@@ -346,7 +349,6 @@ homepage: https://github.com/volanja/ansible_spec
|
|
|
346
349
|
licenses:
|
|
347
350
|
- MIT
|
|
348
351
|
metadata: {}
|
|
349
|
-
post_install_message:
|
|
350
352
|
rdoc_options: []
|
|
351
353
|
require_paths:
|
|
352
354
|
- lib
|
|
@@ -354,15 +356,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
354
356
|
requirements:
|
|
355
357
|
- - ">="
|
|
356
358
|
- !ruby/object:Gem::Version
|
|
357
|
-
version:
|
|
359
|
+
version: 2.1.0
|
|
358
360
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
359
361
|
requirements:
|
|
360
362
|
- - ">="
|
|
361
363
|
- !ruby/object:Gem::Version
|
|
362
364
|
version: '0'
|
|
363
365
|
requirements: []
|
|
364
|
-
rubygems_version:
|
|
365
|
-
signing_key:
|
|
366
|
+
rubygems_version: 4.0.16
|
|
366
367
|
specification_version: 4
|
|
367
368
|
summary: Ansible Config Parser for Serverspec. Run test Multi Role and Multi Host
|
|
368
369
|
by Ansible Configuration
|
|
@@ -379,6 +380,10 @@ test_files:
|
|
|
379
380
|
- spec/case/get_variable/deep_merge/hosts
|
|
380
381
|
- spec/case/get_variable/deep_merge/roles/test/defaults/main.yml
|
|
381
382
|
- spec/case/get_variable/deep_merge/site.yml
|
|
383
|
+
- spec/case/get_variable/empty_group/group_vars/group_a.yml
|
|
384
|
+
- spec/case/get_variable/empty_group/group_vars/group_b.yml
|
|
385
|
+
- spec/case/get_variable/empty_group/hosts
|
|
386
|
+
- spec/case/get_variable/empty_group/site.yml
|
|
382
387
|
- spec/case/get_variable/group_all/group_vars/all.yml
|
|
383
388
|
- spec/case/get_variable/group_all/hosts
|
|
384
389
|
- spec/case/get_variable/group_all/roles/test/defaults/main.yml
|