ansible_spec 0.2.15 → 0.2.16

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
  SHA1:
3
- metadata.gz: f02d25f38bddb84adcadc813fcb9514ae27d4437
4
- data.tar.gz: 989c684e643e740430e6e14cb0af8ef99d0c27a9
3
+ metadata.gz: b23a5303fd8abc86840d5450d162dbb43d6e5e34
4
+ data.tar.gz: 1440c45d801dceaf4b0c745a4f10b46160adade8
5
5
  SHA512:
6
- metadata.gz: 3ae7e44a33c88d4a851aa9350dec1f209ea48454c19a0549464958cb6f3bb8808afd1cd0681643d1e8d4f07272c5c57c569ce230833485842bd773d17b85b51a
7
- data.tar.gz: 383afd4c8708a09c756c90eb0d8acd1737bd5138e41f49dd0f022f140cec0b5b0776e6ba1f39bec38996e2405c783c1768bb5f1beef23aa85f9f761eea6236b0
6
+ metadata.gz: 7f3b1574d6a15feb18ccb8ca038172ce8196407135a4647aad90c3ad08a4fc7bc235e1fe3e1ae0cb16649546aa4e9bae45260a16d8eae0c29e02e19bf85a66e6
7
+ data.tar.gz: 059a9313c114296ba18db37d96a7d9a0b7a0f71adad091cd76abe76266d9275b5f6fd2882d9f9170e8f4e7dc7927ed5df2ed6ce980a0c6a51cf1a2fe7117e2bc
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
data/.travis.yml CHANGED
@@ -4,7 +4,7 @@ rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
6
  - 2.1.10
7
- - 2.2.4
8
- - 2.3.0
7
+ - 2.2.5
8
+ - 2.3.1
9
9
  script:
10
10
  - rspec spec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # v0.2.16
2
+ - Merge [#88 fix nil dependencies](https://github.com/volanja/ansible_spec/pull/88) by [developerinlondon](https://github.com/developerinlondon)
3
+ - Merge [#87 added .DS_Store to gitignore](https://github.com/volanja/ansible_spec/pull/87) by [developerinlondon](https://github.com/developerinlondon)
4
+ - Merge [#85 #84 modify variable expansion](https://github.com/volanja/ansible_spec/pull/85) by volanja
5
+ - Merge [#84 On errors print the playbook name](https://github.com/volanja/ansible_spec/pull/84) by [agx](https://github.com/agx)
6
+ - Merge [#83 Handle "simple" role dependencies](https://github.com/volanja/ansible_spec/pull/83) by [agx](https://github.com/agx)
7
+ - Merge [#82 Handle directories with vars as well](https://github.com/volanja/ansible_spec/pull/82) by [agx](https://github.com/agx)
8
+ - Merge [#78 should use json v1.8.3 at ruby 1.9.3](https://github.com/volanja/ansible_spec/pull/78) by volanja
9
+ - Merge [#77 support ansible_host, ansible_user, ansible_port](https://github.com/volanja/ansible_spec/pull/77) by volanja
10
+
1
11
  # v0.2.15
2
12
  - Merge [Add .rspec when run `ansiblespec-init`](https://github.com/volanja/ansible_spec/pull/76) by volanja
3
13
 
data/Gemfile CHANGED
@@ -7,3 +7,7 @@ if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
7
7
  # net-ssh 3.x dropped Ruby 1.8 and 1.9 support.
8
8
  gem 'net-ssh', '~> 2.7'
9
9
  end
10
+
11
+ if Gem::Version.new(RUBY_VERSION.dup) <= Gem::Version.new('1.9.3')
12
+ gem 'json', '~> 1.8.3'
13
+ end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # AnsibleSpec
1
+ # ansible_spec
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/ansible_spec.svg)](http://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)
@@ -11,9 +11,9 @@ and playbooks. You can test multiple roles and multiple hosts.
11
11
 
12
12
  - Supports [Serverspec](http://serverspec.org/) v2
13
13
  - Supports special host variables
14
- - `ansible_ssh_port`
15
- - `ansible_ssh_user`
16
- - `ansible_ssh_host`
14
+ - `ansible_ssh_port` or `ansible_port`
15
+ - `ansible_ssh_user` or `ansible_user`
16
+ - `ansible_ssh_host` or `ansible_host`
17
17
  - `ansible_ssh_private_key_file`
18
18
  - Supports [host patterns/ranges](http://docs.ansible.com/intro_inventory.html#hosts-and-groups) -- e.g.: `www[01:50].example.com`
19
19
  - Supports Ansible [dynamic inventory sources](http://docs.ansible.com/ansible/intro_dynamic_inventory.html)
@@ -81,10 +81,10 @@ See http://docs.ansible.com/ansible/intro_configuration.html#hash-behaviour.
81
81
  Inventory files can:
82
82
 
83
83
  - use standard ansible parameters
84
- - `ansible_ssh_port`
85
- - `ansible_ssh_user`
86
- - `ansible_ssh_private_key`
87
- - `ansible_ssh_host`
84
+ - `ansible_ssh_port` or `ansible_port`
85
+ - `ansible_ssh_user` or `ansible_user`
86
+ - `ansible_ssh_host` or `ansible_host`
87
+ - `ansible_ssh_private_key_file`
88
88
  - define hosts as expressions. `host-[1:3]` would expand into `host-1`,`host-2`,`host-3`
89
89
  - Group Children
90
90
  - Use [dynamic inventory sources](http://docs.ansible.com/intro_dynamic_inventory.html)
@@ -106,6 +106,10 @@ Inventory files can:
106
106
  192.168.0.5 ansible_ssh_user=git
107
107
  # use port 5555 & host 192.168.1.50
108
108
  jumper ansible_ssh_port=5555 ansible_ssh_host=192.168.1.50
109
+ # Ansible 2.0
110
+ 192.168.10.2 ansible_port=2222
111
+ 192.168.10.5 ansible_user=git
112
+ jumper2 ansible_port=5555 ansible_host=192.168.10.50
109
113
 
110
114
  [web]
111
115
  # www1.example.com to www99.example.com
@@ -150,10 +150,10 @@ module AnsibleSpec
150
150
  host['uri'] = v
151
151
  else
152
152
  key,value = v.split("=")
153
- host['port'] = value.to_i if key == "ansible_ssh_port"
153
+ host['port'] = value.to_i if key == "ansible_ssh_port" or key == "ansible_port"
154
154
  host['private_key'] = value if key == "ansible_ssh_private_key_file"
155
- host['user'] = value if key == "ansible_ssh_user"
156
- host['uri'] = value if key == "ansible_ssh_host"
155
+ host['user'] = value if key == "ansible_ssh_user" or key == "ansible_user"
156
+ host['uri'] = value if key == "ansible_ssh_host" or key == "ansible_host"
157
157
  host['pass'] = value if key == "ansible_ssh_pass"
158
158
  host['connection'] = value if key == "ansible_connection"
159
159
  end
@@ -203,11 +203,14 @@ module AnsibleSpec
203
203
  path = File.join("./", "roles", role, "meta", "main.yml")
204
204
 
205
205
  if File.exist?(path)
206
- new_deps = YAML.load_file(path).fetch("dependencies", []).map { |h|
207
- h["role"]
208
- }
209
- role_queue.concat(new_deps)
210
- deps.concat(new_deps)
206
+ dependencies = YAML.load_file(path).fetch("dependencies", [])
207
+ unless dependencies.nil?
208
+ new_deps = dependencies.map { |h|
209
+ h["role"] || h
210
+ }
211
+ role_queue.concat(new_deps)
212
+ deps.concat(new_deps)
213
+ end
211
214
  end
212
215
  end
213
216
  return deps
@@ -221,7 +224,7 @@ module AnsibleSpec
221
224
 
222
225
  # e.g. comment-out
223
226
  if playbook === false
224
- puts 'Error: No data in site.yml'
227
+ puts "Error: No data in #{f}"
225
228
  exit
226
229
  end
227
230
  properties = Array.new
@@ -307,8 +310,14 @@ module AnsibleSpec
307
310
  vars_file = path+".yml"
308
311
  end
309
312
  if File.exist?(vars_file)
310
- yaml = YAML.load_file(vars_file)
311
- vars = merge_variables(vars, yaml)
313
+ if File.directory?(vars_file)
314
+ Dir.glob(File.join(vars_file, '*')).each { |f|
315
+ vars = load_vars_file(vars, f)
316
+ }
317
+ else
318
+ yaml = YAML.load_file(vars_file)
319
+ vars = merge_variables(vars, yaml)
320
+ end
312
321
  end
313
322
  return vars
314
323
  end
@@ -1,3 +1,3 @@
1
1
  module AnsibleSpec
2
- VERSION = "0.2.15"
2
+ VERSION = "0.2.16"
3
3
  end
@@ -0,0 +1 @@
1
+ var1: "val1"
@@ -0,0 +1 @@
1
+ var2: "val2"
@@ -35,7 +35,7 @@ EOF
35
35
  ---
36
36
  dependencies:
37
37
  - { role: dep1 }
38
- - { role: dep2 }
38
+ - dep2
39
39
  EOF
40
40
 
41
41
  dep1_meta_content = <<'EOF'
@@ -65,3 +65,25 @@ EOF
65
65
  File.delete(tmp_dep1_meta)
66
66
  end
67
67
  end
68
+
69
+ describe "load_dependencies (nil dependencies)" do
70
+ tmp_webapp_meta = 'roles/webapp/meta/main.yml'
71
+
72
+ webapp_meta_content = <<'EOF'
73
+ ---
74
+ dependencies:
75
+ EOF
76
+
77
+ before do
78
+ create_file(tmp_webapp_meta, webapp_meta_content)
79
+ @deps = AnsibleSpec.load_dependencies("webapp")
80
+ end
81
+
82
+ it 'should correctly resolve nested dependencies' do
83
+ expect(@deps).to eq []
84
+ end
85
+
86
+ after do
87
+ File.delete(tmp_webapp_meta)
88
+ end
89
+ end
@@ -465,4 +465,31 @@ describe "load_vars_fileの実行" do
465
465
  Dir.chdir(@current_dir)
466
466
  end
467
467
  end
468
+
469
+ context 'Correct operation : vars in directory' do
470
+ before do
471
+ @current_dir = Dir.pwd()
472
+ Dir.chdir('spec/case/load_vars_file/vars_dir/')
473
+ vars = Hash.new
474
+ file = 'group_vars/all'
475
+ @res = AnsibleSpec.load_vars_file(vars, file)
476
+ end
477
+
478
+ it 'res is hash' do
479
+ expect(@res.instance_of?(Hash)).to be_truthy
480
+ end
481
+
482
+ it 'exist 1 pair in Hash' do
483
+ expect(@res.length).to eq 2
484
+ end
485
+
486
+ it 'exist each pair' do
487
+ expect(@res).to include({'var1' => 'val1'})
488
+ expect(@res).to include({'var2' => 'val2'})
489
+ end
490
+
491
+ after do
492
+ Dir.chdir(@current_dir)
493
+ end
494
+ end
468
495
  end
@@ -30,6 +30,7 @@ EOF
30
30
 
31
31
  content_h = <<'EOF'
32
32
  node ansible_ssh_port=4444 ansible_ssh_host=192.168.1.55
33
+ node1 ansible_port=4444 ansible_host=192.168.1.55
33
34
 
34
35
  [normal]
35
36
  192.168.0.1
@@ -39,6 +40,11 @@ node ansible_ssh_port=4444 ansible_ssh_host=192.168.1.55
39
40
  192.168.0.5 ansible_ssh_user=git
40
41
  jumper ansible_ssh_port=5555 ansible_ssh_host=192.168.1.50
41
42
  node
43
+ # Ansible 2.0
44
+ 192.168.10.2 ansible_port=2222
45
+ 192.168.10.5 ansible_user=git
46
+ jumper2 ansible_port=5555 ansible_host=192.168.10.50
47
+ node1
42
48
  EOF
43
49
 
44
50
  create_file(tmp_ansiblespec,content)
@@ -116,6 +122,35 @@ describe "load_targetsの実行" do
116
122
  expect(obj['port']).to eq 4444
117
123
  end
118
124
 
125
+ it '192.168.10.2 ansible_port=2222' do
126
+ obj = @res['normal'][7]
127
+ expect(obj.instance_of?(Hash)).to be_truthy
128
+ expect(obj['uri']).to eq '192.168.10.2'
129
+ expect(obj['port']).to eq 2222
130
+ end
131
+
132
+ it '192.168.10.5 ansible_user=git' do
133
+ obj = @res['normal'][8]
134
+ expect(obj.instance_of?(Hash)).to be_truthy
135
+ expect(obj['uri']).to eq '192.168.10.5'
136
+ expect(obj['user']).to eq 'git'
137
+ end
138
+
139
+ it 'jumper2 ansible_port=5555 ansible_host=192.168.10.50' do
140
+ obj = @res['normal'][9]
141
+ expect(obj.instance_of?(Hash)).to be_truthy
142
+ expect(obj['name']).to eq 'jumper2 ansible_port=5555 ansible_host=192.168.10.50'
143
+ expect(obj['uri']).to eq '192.168.10.50'
144
+ expect(obj['port']).to eq 5555
145
+ end
146
+
147
+ it 'node1 ansible_port=4444 ansible_host=192.168.1.55' do
148
+ obj = @res['normal'][10]
149
+ expect(obj.instance_of?(Hash)).to be_truthy
150
+ expect(obj['name']).to eq 'node1 ansible_port=4444 ansible_host=192.168.1.55'
151
+ expect(obj['uri']).to eq '192.168.1.55'
152
+ expect(obj['port']).to eq 4444
153
+ end
119
154
  after do
120
155
  File.delete(tmp_hosts)
121
156
  end
data/spec/ssh_spec.rb CHANGED
@@ -91,6 +91,27 @@ describe 'ssh' do
91
91
  expect(v.port).to eq '5985'
92
92
  end
93
93
 
94
+ it '192.168.10.2 ansible_port=2222' do
95
+ v = @h["task_11"]
96
+ expect(v.user).to eq 'root'
97
+ expect(v.host).to eq '192.168.10.2'
98
+ expect(v.port).to eq '2222'
99
+ end
100
+
101
+ it '192.168.10.5 ansible_user=git' do
102
+ v = @h["task_12"]
103
+ expect(v.user).to eq 'git'
104
+ expect(v.host).to eq '192.168.10.5'
105
+ expect(v.port).to eq '22'
106
+ end
107
+
108
+ it 'jumper2 ansible_port=5555 ansible_host=192.168.10.50' do
109
+ v = @h["task_13"]
110
+ expect(v.user).to eq 'root'
111
+ expect(v.host).to eq '192.168.10.50'
112
+ expect(v.port).to eq '5555'
113
+ end
114
+
94
115
  after do
95
116
  delete_normality
96
117
  end
@@ -178,6 +199,10 @@ jumper ansible_ssh_port=5555 ansible_ssh_host=192.168.1.50
178
199
  www[01:02].example.com
179
200
  db-[a:b].example.com
180
201
  192.168.1.3 ansible_connection=winrm ansible_ssh_port=5985 ansible_ssh_user=administrator ansible_ssh_pass=Passw0rd
202
+ # Ansible 2.0
203
+ 192.168.10.2 ansible_port=2222
204
+ 192.168.10.5 ansible_user=git
205
+ jumper2 ansible_port=5555 ansible_host=192.168.10.50
181
206
  EOF
182
207
 
183
208
  File.open(tmp_ansiblespec, 'w') do |f|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansible_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.15
4
+ version: 0.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - volanja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-29 00:00:00.000000000 Z
11
+ date: 2016-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -254,6 +254,8 @@ files:
254
254
  - spec/case/load_vars_file/group_all/group_vars/all.yml
255
255
  - spec/case/load_vars_file/group_all_deep_merge/.ansiblespec
256
256
  - spec/case/load_vars_file/group_all_deep_merge/group_vars/all.yml
257
+ - spec/case/load_vars_file/vars_dir/group_vars/all/file1
258
+ - spec/case/load_vars_file/vars_dir/group_vars/all/file2
257
259
  - spec/commands_spec.rb
258
260
  - spec/dependency_spec.rb
259
261
  - spec/dynamic_inventory_hosts_childrens_spec.rb
@@ -395,6 +397,8 @@ test_files:
395
397
  - spec/case/load_vars_file/group_all/group_vars/all.yml
396
398
  - spec/case/load_vars_file/group_all_deep_merge/.ansiblespec
397
399
  - spec/case/load_vars_file/group_all_deep_merge/group_vars/all.yml
400
+ - spec/case/load_vars_file/vars_dir/group_vars/all/file1
401
+ - spec/case/load_vars_file/vars_dir/group_vars/all/file2
398
402
  - spec/commands_spec.rb
399
403
  - spec/dependency_spec.rb
400
404
  - spec/dynamic_inventory_hosts_childrens_spec.rb