ansible_spec 0.3.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d77ce9fa38453ab6f652cc6c20a79509c722d615790cb49b59ec8e37154aad7b
4
- data.tar.gz: 27384622e2d91ad928ee5b37fa061efa3b80af5baad5b887823ec3df7e83dded
3
+ metadata.gz: 4d6f9c6e42c88594d1b2cc2d7f18d96d172f2362e26fffac1a4a4e8b334600ab
4
+ data.tar.gz: f1d479135980a9cfa9a8e658ca9f55df3b95e63dba68e5d788347e892b477164
5
5
  SHA512:
6
- metadata.gz: 2591637e35a8fa5fe8f2add17e24d5f32844030d9fd1f268ec4a0e607bb4f2500ef8a75c166c337d20c8e97c8db979dc1bdf317f64f5f93095493699bef37665
7
- data.tar.gz: e1124d4328dc3430545f94a87306fc9148f3b91bc5074d84180edac293966115b15794e5ecd142335a2c972415143f7893bf6516d951bfb4b4ffd1f2855d561d
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,8 @@
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
+
1
6
  # v0.3.2
2
7
  - Merge [#135 Fix wrong index by empty group](https://github.com/volanja/ansible_spec/pull/135) by [mamiya312](https://github.com/mamiya312)
3
8
 
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
  [![Gem Version](https://badge.fury.io/rb/ansible_spec.svg)](https://badge.fury.io/rb/ansible_spec)
4
- [![Build Status](https://travis-ci.org/volanja/ansible_spec.svg?branch=master)](https://travis-ci.org/volanja/ansible_spec)
4
+ [![build](https://github.com/volanja/ansible_spec/actions/workflows/build.yml/badge.svg)](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', __FILE__)
2
+ lib = File.expand_path('../lib', __dir__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'ansible_spec/version'
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 = YAML.load_file(f)
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 = YAML.load_file(path).fetch("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 = YAML.load_file(f)
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
- YAML.load_file(site["include"]).each { |site|
262
+ load_yaml_file(site["include"]).each { |site|
257
263
  properties.push site
258
264
  }
259
265
  elsif site.has_key?("import_playbook")
260
- YAML.load_file(site["import_playbook"]).each { |site|
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 = YAML.load_file(f)
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 = YAML.load_file(vars_file)
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 = YAML.load_file(vars_file)
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 = YAML.load_file(f)
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
@@ -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.exists? f
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
- cfg = IniFile.new
623
+ cfg_hash = {}
607
624
  self.find_ansible_cfgs.each do |file|
608
- cfg = cfg.merge(IniFile.new :filename => file)
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
- cfg.to_h
629
+ cfg_hash # return Hash
611
630
  end
612
631
  end
613
632
 
@@ -1,3 +1,3 @@
1
1
  module AnsibleSpec
2
- VERSION = "0.3.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/ansible_spec.rb CHANGED
@@ -65,7 +65,7 @@ module AnsibleSpec
65
65
  end
66
66
 
67
67
  def self.safe_touch(file)
68
- unless File.exists? "#{file}"
68
+ unless File.exist? "#{file}"
69
69
  File.open("#{file}", 'w') do |f|
70
70
  #f.puts content
71
71
  end
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.3.2
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: 2020-08-24 00:00:00.000000000 Z
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
@@ -350,7 +349,6 @@ homepage: https://github.com/volanja/ansible_spec
350
349
  licenses:
351
350
  - MIT
352
351
  metadata: {}
353
- post_install_message:
354
352
  rdoc_options: []
355
353
  require_paths:
356
354
  - lib
@@ -358,15 +356,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
358
356
  requirements:
359
357
  - - ">="
360
358
  - !ruby/object:Gem::Version
361
- version: '0'
359
+ version: 2.1.0
362
360
  required_rubygems_version: !ruby/object:Gem::Requirement
363
361
  requirements:
364
362
  - - ">="
365
363
  - !ruby/object:Gem::Version
366
364
  version: '0'
367
365
  requirements: []
368
- rubygems_version: 3.1.2
369
- signing_key:
366
+ rubygems_version: 4.0.16
370
367
  specification_version: 4
371
368
  summary: Ansible Config Parser for Serverspec. Run test Multi Role and Multi Host
372
369
  by Ansible Configuration
data/.travis.yml DELETED
@@ -1,15 +0,0 @@
1
- language: ruby
2
- dist: trusty # work at Ubuntu 14.04 for install Ruby 1.9.3
3
- sudo: false
4
- rvm:
5
- - 1.9.3
6
- - 2.0.0
7
- - 2.1.10
8
- - 2.2.10
9
- - 2.3.8
10
- - 2.4.10
11
- - 2.5.8
12
- - 2.6.6
13
- - 2.7.1
14
- script:
15
- - rspec spec