ansible_spec 0.2.25 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c590bfdd84716132e5a14c1ac3aa372aada32bbbc6f5e80e20c412db07cdcd48
4
- data.tar.gz: bc136b7cc0ee1af57b2d9b4183de15b0efe20747b36b8cf023d4a5c3f6b51873
3
+ metadata.gz: 250f5355a569c40d24193b19685ecc4d5ad454aa7c60ff445b12503b81a6a23a
4
+ data.tar.gz: 3b72c2519bc7600ba81c789b07a3415ac1ebd286d23c0133bdc39dce93ccd47a
5
5
  SHA512:
6
- metadata.gz: adfac09e9e273d179093a7d9aed9bec84b67cca40136958d6b387d6e2454370f2d1ebb3fc918d3ee508ad97b1e124da5b553c349596f1ab5e8372fb7792d33f8
7
- data.tar.gz: aaea9c5fc67e8d9bf3f4966ba4673baac23229cc78a6d4e1a7cdee360eec7fc48920d50eed0d5c3f080583afe65677d3b73bda2925c64b35e7188e7cd8bf758d
6
+ metadata.gz: c8f3fb9cc3861c77526ea9c8d24657550fa4ee1f0f1d74299660765721008af3fd00531b3045e4b72357d527ef6e02d94d3937ef1e486e7749a1d3173fd24f98
7
+ data.tar.gz: a0c3454aa81f7c374208ac78e7abd0e2fe95427080f6cd104230e9b22bcea981576c77fbe82bcec489873bf66d258bc420f7427f139053c37ebe2db7172b1ab4
@@ -1,12 +1,15 @@
1
1
  language: ruby
2
+ dist: trusty # work at Ubuntu 14.04 for install Ruby 1.9.3
2
3
  sudo: false
3
4
  rvm:
4
5
  - 1.9.3
5
6
  - 2.0.0
6
7
  - 2.1.10
7
8
  - 2.2.10
8
- - 2.3.7
9
- - 2.4.4
10
- - 2.5.1
9
+ - 2.3.8
10
+ - 2.4.6
11
+ - 2.5.5
12
+ - 2.6.3
13
+ - 2.7.0-preview1
11
14
  script:
12
15
  - rspec spec
@@ -1,3 +1,10 @@
1
+ # v0.3
2
+ - Support Ansible Vault (Run Ruby 2.1.0 and higher.)
3
+ - Merge [#116 Feature ansible vault](https://github.com/volanja/ansible_spec/pull/116) by [RebelCodeBase](https://github.com/RebelCodeBase)
4
+ - Merge [#123 skip test at unsupported version ref ansible vault](https://github.com/volanja/ansible_spec/pull/123) by volanja
5
+
6
+ And Some Bug Fixed. See [Milestone v0.3](https://github.com/volanja/ansible_spec/milestone/13?closed=1)
7
+
1
8
  # v0.2.25
2
9
  - Merge [#118 Incorporate group parent child relationships into variable assignment hierarchy](https://github.com/volanja/ansible_spec/pull/118) by [rbramwell](https://github.com/rbramwell)
3
10
 
data/Gemfile CHANGED
@@ -13,3 +13,8 @@ if Gem::Version.new(RUBY_VERSION.dup) <= Gem::Version.new('1.9.3')
13
13
  # winrm 2.1.1 dropped Ruby 1.9 support.
14
14
  gem 'winrm', '< 2.1.1'
15
15
  end
16
+
17
+ if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1')
18
+ # Ansible::Vault support Ruby 2.1.0 and higher.
19
+ gem 'ansible-vault'
20
+ end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ansible_spec
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/ansible_spec.svg)](http://badge.fury.io/rb/ansible_spec)
3
+ [![Gem Version](https://badge.fury.io/rb/ansible_spec.svg)](https://badge.fury.io/rb/ansible_spec)
4
4
  [![Build Status](https://travis-ci.org/volanja/ansible_spec.svg?branch=master)](https://travis-ci.org/volanja/ansible_spec)
5
5
 
6
6
  This is a Ruby gem that implements an Ansible Config Parser for Serverspec.
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_development_dependency "bundler", "~> 1.3"
21
+ gem.add_development_dependency "bundler"
22
22
  gem.add_development_dependency "rake"
23
23
  gem.add_development_dependency "diff-lcs"
24
24
  gem.add_development_dependency "simplecov"
@@ -28,5 +28,6 @@ Gem::Specification.new do |gem|
28
28
  gem.add_runtime_dependency "oj"
29
29
  gem.add_runtime_dependency "winrm"
30
30
  gem.add_runtime_dependency "inifile"
31
+ gem.add_runtime_dependency "ansible-vault"
31
32
 
32
33
  end
@@ -5,6 +5,9 @@ require 'open3'
5
5
  require 'yaml'
6
6
  require 'inifile'
7
7
  require 'ansible_spec/vendor/hash'
8
+ if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1')
9
+ require 'ansible/vault'
10
+ end
8
11
 
9
12
  module AnsibleSpec
10
13
  # param: inventory file of Ansible
@@ -158,6 +161,7 @@ module AnsibleSpec
158
161
  # 初期値
159
162
  host['name'] = line
160
163
  host['port'] = 22
164
+ host['connection'] = "ssh"
161
165
  if line.include?(":") # 192.168.0.1:22
162
166
  host['uri'] = line.split(":")[0]
163
167
  host['port'] = line.split(":")[1].to_i
@@ -365,15 +369,39 @@ module AnsibleSpec
365
369
  if File.directory?(vars_file)
366
370
  Dir.glob(File.join(vars_file, '*')).each { |f|
367
371
  vars = load_vars_file(vars, f)
368
- }
372
+ }
369
373
  else
370
- yaml = YAML.load_file(vars_file)
371
- vars = merge_variables(vars, yaml)
374
+ # you can use Ansible::Vault when use ruby 2.1.0 and higher.
375
+ # Ansible::Vault support Ruby 2.1.0 and higher.
376
+ if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1')
377
+ if Ansible::Vault.encrypted?(vars_file)
378
+ yaml = load_encrypted_file(vars_file)
379
+ else
380
+ yaml = YAML.load_file(vars_file)
381
+ end
382
+ vars = merge_variables(vars, yaml)
383
+ else
384
+ # Ruby 1.9 and 2.0
385
+ yaml = YAML.load_file(vars_file)
386
+ vars = merge_variables(vars, yaml)
387
+ end
372
388
  end
373
389
  end
374
390
  return vars
375
391
  end
376
392
 
393
+ # param: variable file
394
+ # return: be merged hash
395
+ def self.load_encrypted_file(vars_file)
396
+ cfg = AnsibleSpec::AnsibleCfg.new
397
+ vault_password_file = cfg.get('defaults', 'vault_password_file')
398
+ if vault_password_file
399
+ vault_password = File.open(vault_password_file).read.chomp
400
+ yaml = YAML.load(Ansible::Vault.read(path: vars_file, password: vault_password))
401
+ end
402
+ return yaml
403
+ end
404
+
377
405
  # param: target hash
378
406
  # param: be merged hash
379
407
  def self.merge_variables(vars, hash)
@@ -1,3 +1,3 @@
1
1
  module AnsibleSpec
2
- VERSION = "0.2.25"
2
+ VERSION = "0.3"
3
3
  end
@@ -23,15 +23,16 @@ when 'ssh'
23
23
  #
24
24
  set :backend, :ssh
25
25
 
26
+ # Ansible use `BECOME`, But Serverspec use `SUDO`.
26
27
  if ENV['ASK_BECOME_PASSWORD']
27
28
  begin
28
29
  require 'highline/import'
29
30
  rescue LoadError
30
31
  fail "highline is not available. Try installing it."
31
32
  end
32
- set :become_password, ask("Enter become password: ") { |q| q.echo = false }
33
+ set :sudo_password, ask("Enter become password: ") { |q| q.echo = false }
33
34
  else
34
- set :become_password, ENV['BECOME_PASSWORD']
35
+ set :sudo_password, ENV['BECOME_PASSWORD']
35
36
  end
36
37
 
37
38
  options = Net::SSH::Config.for(host)
@@ -48,8 +49,8 @@ when 'ssh'
48
49
  set :host, options[:host_name] || host
49
50
  set :ssh_options, options
50
51
 
51
- # Disable become
52
- # set :become, false
52
+ # Disable become (Serverspec use sudo)
53
+ # set :disable_sudo, true
53
54
 
54
55
 
55
56
  # Set environment variables
@@ -0,0 +1,2 @@
1
+ [defaults]
2
+ vault_password_file = vault-password-file
@@ -0,0 +1,6 @@
1
+ $ANSIBLE_VAULT;1.1;AES256
2
+ 33623930383865383331633337653461646233633934353935376363306265636331363565306532
3
+ 3935313131623364363162616335333530376134383137350a376231363430353963646535313335
4
+ 36383533346433306666623162663335353035333931366162353131383539643239646637333561
5
+ 3963386635663534310a323134643666343962303733616263613535623965366337393666623832
6
+ 3032
@@ -0,0 +1 @@
1
+ supersecretpassword
@@ -638,4 +638,33 @@ describe "load_vars_fileの実行" do
638
638
  end
639
639
  end
640
640
 
641
+ # Ansible::Vault support Ruby 2.1.0 and higher.
642
+ # Skip test when Ruby 1.9.3 & 2.0.0
643
+ if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1')
644
+ context 'Correct operation : vaults in directory' do
645
+ before do
646
+ @current_dir = Dir.pwd()
647
+ Dir.chdir('spec/case/load_vars_file/vault_dir/')
648
+ vars = Hash.new
649
+ file = 'group_vars/all'
650
+ @res = AnsibleSpec.load_vars_file(vars, file)
651
+ end
652
+
653
+ it 'res is hash' do
654
+ expect(@res.instance_of?(Hash)).to be_truthy
655
+ end
656
+
657
+ it 'exists one pair in Hash' do
658
+ expect(@res.length).to eq 1
659
+ end
660
+
661
+ it 'exists the pair' do
662
+ expect(@res).to include({'vault_var' => 'val'})
663
+ end
664
+
665
+ after do
666
+ Dir.chdir(@current_dir)
667
+ end
668
+ end
669
+ end
641
670
  end
@@ -1531,16 +1531,20 @@ EOF
1531
1531
  expect(@res[0]['hosts'].instance_of?(Array)).to be_truthy
1532
1532
  expect([{'name' => '192.168.0.103',
1533
1533
  'uri' => '192.168.0.103',
1534
- 'port' => 22},
1534
+ 'port' => 22,
1535
+ 'connection' => 'ssh'},
1535
1536
  {'name' => '192.168.0.104',
1536
1537
  'uri' => '192.168.0.104',
1537
- 'port' => 22},
1538
+ 'port' => 22,
1539
+ 'connection' => 'ssh'},
1538
1540
  {'name' => '192.168.0.105',
1539
1541
  'uri' => '192.168.0.105',
1540
- 'port' => 22},
1542
+ 'port' => 22,
1543
+ 'connection' => 'ssh'},
1541
1544
  {'name' => '192.168.0.106',
1542
1545
  'uri' => '192.168.0.106',
1543
- 'port' => 22}]).to match_array(@res[0]['hosts'])
1546
+ 'port' => 22,
1547
+ 'connection' => 'ssh'}]).to match_array(@res[0]['hosts'])
1544
1548
  end
1545
1549
 
1546
1550
  it 'exist user' do
@@ -1676,18 +1680,22 @@ EOF
1676
1680
  expect([{'name' => '192.168.0.103',
1677
1681
  'uri' => '192.168.0.103',
1678
1682
  'port' => 22,
1683
+ 'connection' => 'ssh',
1679
1684
  'hosts'=>'server'},
1680
1685
  {'name' => '192.168.0.104',
1681
1686
  'uri' => '192.168.0.104',
1682
1687
  'port' => 22,
1688
+ 'connection' => 'ssh',
1683
1689
  'hosts'=>'server'},
1684
1690
  {'name' => '192.168.0.105',
1685
1691
  'uri' => '192.168.0.105',
1686
1692
  'port' => 22,
1693
+ 'connection' => 'ssh',
1687
1694
  'hosts'=>'server2'},
1688
1695
  {'name' => '192.168.0.106',
1689
1696
  'uri' => '192.168.0.106',
1690
1697
  'port' => 22,
1698
+ 'connection' => 'ssh',
1691
1699
  'hosts'=>'server2'}]).to match_array(@res[0]['hosts'])
1692
1700
  end
1693
1701
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansible_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.25
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - volanja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-26 00:00:00.000000000 Z
11
+ date: 2019-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: ansible-vault
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description: Ansible Config Parser for Serverspec. Run test Multi Role and Multi Host
140
154
  by Ansible Configuration
141
155
  email:
@@ -310,6 +324,9 @@ files:
310
324
  - spec/case/load_vars_file/group_all_deep_merge/group_vars/all.yml
311
325
  - spec/case/load_vars_file/vars_dir/group_vars/all/file1
312
326
  - spec/case/load_vars_file/vars_dir/group_vars/all/file2
327
+ - spec/case/load_vars_file/vault_dir/ansible.cfg
328
+ - spec/case/load_vars_file/vault_dir/group_vars/all/vault_file
329
+ - spec/case/load_vars_file/vault_dir/vault-password-file
313
330
  - spec/commands_spec.rb
314
331
  - spec/dependency_spec.rb
315
332
  - spec/dynamic_inventory_hosts_childrens_spec.rb
@@ -497,6 +514,9 @@ test_files:
497
514
  - spec/case/load_vars_file/group_all_deep_merge/group_vars/all.yml
498
515
  - spec/case/load_vars_file/vars_dir/group_vars/all/file1
499
516
  - spec/case/load_vars_file/vars_dir/group_vars/all/file2
517
+ - spec/case/load_vars_file/vault_dir/ansible.cfg
518
+ - spec/case/load_vars_file/vault_dir/group_vars/all/vault_file
519
+ - spec/case/load_vars_file/vault_dir/vault-password-file
500
520
  - spec/commands_spec.rb
501
521
  - spec/dependency_spec.rb
502
522
  - spec/dynamic_inventory_hosts_childrens_spec.rb