ansible_spec 0.0.1.4 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +91 -16
- data/ansible_spec.gemspec +8 -4
- data/lib/ansible_spec.rb +4 -132
- data/lib/ansible_spec/load_ansible.rb +179 -0
- data/lib/ansible_spec/version.rb +1 -1
- data/lib/src/.ansiblespec +4 -0
- data/lib/src/Rakefile +35 -0
- data/lib/src/spec/spec_helper.rb +36 -0
- data/spec/commands_spec.rb +26 -4
- data/spec/dynamic_inventory_spec.rb +46 -0
- data/spec/inventory_parameters_spec.rb +202 -0
- data/spec/load_ansible_spec.rb +752 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/ssh_spec.rb +161 -0
- metadata +77 -8
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
require 'specinfra'
|
2
|
+
require 'rspec/mocks/standalone'
|
3
|
+
require 'specinfra/helper/set'
|
4
|
+
require 'simplecov'
|
5
|
+
include Specinfra::Helper::Set
|
6
|
+
|
7
|
+
# Test Coverage
|
8
|
+
SimpleCov.start
|
1
9
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
10
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
11
|
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
data/spec/ssh_spec.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ansible_spec'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
set :backend, :ssh
|
6
|
+
|
7
|
+
describe 'ssh' do
|
8
|
+
context 'with root user' do
|
9
|
+
before do
|
10
|
+
create_normality
|
11
|
+
properties = AnsibleSpec.get_properties
|
12
|
+
@h = Hash.new
|
13
|
+
n = 0
|
14
|
+
properties.each do |property|
|
15
|
+
property["hosts"].each do |host|
|
16
|
+
#ENV['TARGET_PRIVATE_KEY'] = '~/.ssh/id_rsa'
|
17
|
+
#t.pattern = 'roles/{' + property["roles"].join(',') + '}/spec/*_spec.rb'
|
18
|
+
@ssh = double(:ssh)
|
19
|
+
if host.instance_of?(Hash)
|
20
|
+
set :host, host["uri"]
|
21
|
+
unless host["user"].nil?
|
22
|
+
user = host["user"]
|
23
|
+
else
|
24
|
+
user = property["user"]
|
25
|
+
end
|
26
|
+
set :ssh_options, :user => user, :port => host["port"], :keys => host["private_key"]
|
27
|
+
allow(@ssh).to receive(:port).and_return(Specinfra.configuration.ssh_options[:port])
|
28
|
+
allow(@ssh).to receive(:keys).and_return(Specinfra.configuration.ssh_options[:keys])
|
29
|
+
else
|
30
|
+
set :host, host
|
31
|
+
set :ssh_options, :user => property["user"]
|
32
|
+
end
|
33
|
+
allow(@ssh).to receive(:host).and_return(Specinfra.configuration.host)
|
34
|
+
allow(@ssh).to receive(:user).and_return(Specinfra.configuration.ssh_options[:user])
|
35
|
+
@h["task_#{n}"] = @ssh
|
36
|
+
n += 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it '192.168.0.1' do
|
42
|
+
v = @h["task_0"]
|
43
|
+
expect(v.user).to eq 'root'
|
44
|
+
expect(v.host).to eq '192.168.0.1'
|
45
|
+
end
|
46
|
+
it '192.168.0.2:22' do
|
47
|
+
v = @h["task_1"]
|
48
|
+
expect(v.user).to eq 'root'
|
49
|
+
expect(v.host).to eq '192.168.0.2'
|
50
|
+
expect(v.port).to eq 22
|
51
|
+
end
|
52
|
+
it '192.168.0.3 ansible_ssh_port=22' do
|
53
|
+
v = @h["task_2"]
|
54
|
+
expect(v.user).to eq 'root'
|
55
|
+
expect(v.host).to eq '192.168.0.3'
|
56
|
+
expect(v.port).to eq 5309
|
57
|
+
end
|
58
|
+
it '192.168.0.4 ansible_ssh_private_key_file=~/.ssh/id_rsa' do
|
59
|
+
v = @h["task_3"]
|
60
|
+
expect(v.user).to eq 'root'
|
61
|
+
expect(v.host).to eq '192.168.0.4'
|
62
|
+
expect(v.port).to eq 22
|
63
|
+
expect(v.keys).to eq '~/.ssh/id_rsa'
|
64
|
+
end
|
65
|
+
|
66
|
+
it '192.168.0.5 ansible_ssh_user=git' do
|
67
|
+
v = @h["task_4"]
|
68
|
+
expect(v.user).to eq 'git'
|
69
|
+
expect(v.host).to eq '192.168.0.5'
|
70
|
+
expect(v.port).to eq 22
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'jumper ansible_ssh_port=5555 ansible_ssh_host=192.168.1.50' do
|
74
|
+
v = @h["task_5"]
|
75
|
+
expect(v.user).to eq 'root'
|
76
|
+
expect(v.host).to eq '192.168.1.50'
|
77
|
+
expect(v.port).to eq 5555
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'www[01:02].example.com' do
|
81
|
+
v = @h["task_6"]
|
82
|
+
expect(v.user).to eq 'root'
|
83
|
+
expect(v.host).to eq 'www01.example.com'
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'www[01:02].example.com' do
|
87
|
+
v = @h["task_7"]
|
88
|
+
expect(v.user).to eq 'root'
|
89
|
+
expect(v.host).to eq 'www02.example.com'
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'db-[a:b].example.com' do
|
93
|
+
v = @h["task_8"]
|
94
|
+
expect(v.user).to eq 'root'
|
95
|
+
expect(v.host).to eq 'db-a.example.com'
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'db-[a:b].example.com' do
|
99
|
+
v = @h["task_9"]
|
100
|
+
expect(v.user).to eq 'root'
|
101
|
+
expect(v.host).to eq 'db-b.example.com'
|
102
|
+
end
|
103
|
+
|
104
|
+
after do
|
105
|
+
delete_normality
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_normality
|
111
|
+
tmp_ansiblespec = '.ansiblespec'
|
112
|
+
tmp_playbook = 'site.yml'
|
113
|
+
tmp_hosts = 'hosts'
|
114
|
+
|
115
|
+
content = <<'EOF'
|
116
|
+
---
|
117
|
+
-
|
118
|
+
playbook: site.yml
|
119
|
+
inventory: hosts
|
120
|
+
EOF
|
121
|
+
|
122
|
+
content_p = <<'EOF'
|
123
|
+
- name: Ansible-Sample-TDD
|
124
|
+
hosts: normal
|
125
|
+
user: root
|
126
|
+
roles:
|
127
|
+
- nginx
|
128
|
+
- mariadb
|
129
|
+
EOF
|
130
|
+
|
131
|
+
content_h = <<'EOF'
|
132
|
+
[normal]
|
133
|
+
192.168.0.1
|
134
|
+
192.168.0.2 ansible_ssh_port=22
|
135
|
+
192.168.0.3:5309
|
136
|
+
192.168.0.4 ansible_ssh_private_key_file=~/.ssh/id_rsa
|
137
|
+
192.168.0.5 ansible_ssh_user=git
|
138
|
+
jumper ansible_ssh_port=5555 ansible_ssh_host=192.168.1.50
|
139
|
+
www[01:02].example.com
|
140
|
+
db-[a:b].example.com
|
141
|
+
EOF
|
142
|
+
|
143
|
+
File.open(tmp_ansiblespec, 'w') do |f|
|
144
|
+
f.puts content
|
145
|
+
end
|
146
|
+
File.open(tmp_playbook, 'w') do |f|
|
147
|
+
f.puts content_p
|
148
|
+
end
|
149
|
+
File.open(tmp_hosts, 'w') do |f|
|
150
|
+
f.puts content_h
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def delete_normality
|
155
|
+
tmp_ansiblespec = '.ansiblespec'
|
156
|
+
tmp_playbook = 'site.yml'
|
157
|
+
tmp_hosts = 'hosts'
|
158
|
+
File.delete(tmp_ansiblespec)
|
159
|
+
File.delete(tmp_playbook)
|
160
|
+
File.delete(tmp_hosts)
|
161
|
+
end
|
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.
|
4
|
+
version: '0.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- volanja
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,22 +38,78 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: diff-lcs
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: serverspec
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
73
|
- - '>='
|
46
74
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
75
|
+
version: 2.0.0
|
48
76
|
type: :runtime
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
80
|
- - '>='
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
55
|
-
|
56
|
-
|
82
|
+
version: 2.0.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: hostlist_expression
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: oj
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Ansible Config Parser for Serverspec. Run test Multi Role and Multi Host
|
112
|
+
by Ansible Configuration
|
57
113
|
email:
|
58
114
|
- volaaanja@gmail.com
|
59
115
|
executables:
|
@@ -71,10 +127,18 @@ files:
|
|
71
127
|
- ansible_spec.gemspec
|
72
128
|
- bin/ansiblespec-init
|
73
129
|
- lib/ansible_spec.rb
|
130
|
+
- lib/ansible_spec/load_ansible.rb
|
74
131
|
- lib/ansible_spec/version.rb
|
132
|
+
- lib/src/.ansiblespec
|
133
|
+
- lib/src/Rakefile
|
134
|
+
- lib/src/spec/spec_helper.rb
|
75
135
|
- spec/commands_spec.rb
|
136
|
+
- spec/dynamic_inventory_spec.rb
|
137
|
+
- spec/inventory_parameters_spec.rb
|
138
|
+
- spec/load_ansible_spec.rb
|
76
139
|
- spec/spec_helper.rb
|
77
|
-
|
140
|
+
- spec/ssh_spec.rb
|
141
|
+
homepage: https://github.com/volanja/ansible_spec
|
78
142
|
licenses:
|
79
143
|
- MIT
|
80
144
|
metadata: {}
|
@@ -97,7 +161,12 @@ rubyforge_project:
|
|
97
161
|
rubygems_version: 2.1.11
|
98
162
|
signing_key:
|
99
163
|
specification_version: 4
|
100
|
-
summary:
|
164
|
+
summary: Ansible Config Parser for Serverspec. Run test Multi Role and Multi Host
|
165
|
+
by Ansible Configuration
|
101
166
|
test_files:
|
102
167
|
- spec/commands_spec.rb
|
168
|
+
- spec/dynamic_inventory_spec.rb
|
169
|
+
- spec/inventory_parameters_spec.rb
|
170
|
+
- spec/load_ansible_spec.rb
|
103
171
|
- spec/spec_helper.rb
|
172
|
+
- spec/ssh_spec.rb
|