ansible_tools 0.0.4.2 → 0.0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +6 -6
- data/lib/ansible_tools.rb +29 -39
- data/lib/ansible_tools/version.rb +1 -1
- data/spec/commands_spec.rb +46 -58
- data/spec/lists/init_false.yml +25 -0
- data/spec/lists/init_role_false.yml +15 -0
- data/spec/lists/init_role_true.yml +13 -0
- data/spec/lists/init_simple_false.yml +15 -0
- data/spec/lists/init_simple_true.yml +13 -0
- data/spec/lists/init_true.yml +15 -0
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30b2f60295d3cd2a95e09ca5aced123fe4892c01
|
4
|
+
data.tar.gz: 8f76703395860c42fa6246faa85e5cc9705ebfbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6049c692d0f951a2bfd255561bd6b3c4f45aa471504e1c27572b7a6bedeeaa1a8fa13426ebf556de2f73e910ded01c55074076b9e18868ef00ce21ec1293467
|
7
|
+
data.tar.gz: e600b9926210ceff39e97d4e669106c3dbe8a9ddc9ce4db3e225fae3e621c8a88b1cc1d3bc4aace5da71cdf5357f2829624ce7f3febdf8e0650a286688c42b58
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Ansible Tools e.g. Create directory by BestPractice
|
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/ansible_tools.png)](http://badge.fury.io/rb/ansible_tools)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/volanja/ansible_tools.png)](https://codeclimate.com/github/volanja/ansible_tools)
|
7
|
-
[![
|
7
|
+
[![Build Status](https://travis-ci.org/volanja/ansible_tools.svg?branch=master)](https://travis-ci.org/volanja/ansible_tools)
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -28,7 +28,7 @@ Commands:
|
|
28
28
|
[Best Practices - ANSIBLEWORKS](http://www.ansibleworks.com/docs/playbooks_best_practices.html)
|
29
29
|
|
30
30
|
```
|
31
|
-
$
|
31
|
+
$ ansible-tools init [-y]
|
32
32
|
create roles/common/tasks
|
33
33
|
create roles/common/handlers
|
34
34
|
create roles/common/templates
|
@@ -55,7 +55,7 @@ $ ansbile-tools init [-y]
|
|
55
55
|
### Simple
|
56
56
|
|
57
57
|
```
|
58
|
-
$
|
58
|
+
$ ansible-tools init -s [-y]
|
59
59
|
create roles/common/tasks
|
60
60
|
create roles/common/handlers
|
61
61
|
create roles/common/templates
|
@@ -74,7 +74,7 @@ $ ansbile-tools init -s [-y]
|
|
74
74
|
### Add Role
|
75
75
|
|
76
76
|
```
|
77
|
-
$
|
77
|
+
$ ansible-tools init -r <roles name> [-y]
|
78
78
|
|
79
79
|
$ ansible-tools init -r gitlab
|
80
80
|
create roles/gitlab/tasks
|
@@ -97,7 +97,7 @@ Search file and write list
|
|
97
97
|
file => `roles/*/vars/main.yml`, `group_vars/*.yml`, `host_vars/*.yml`, `*.yml`
|
98
98
|
|
99
99
|
```
|
100
|
-
$
|
100
|
+
$ ansible-tools show
|
101
101
|
+----------------------------------------------------------------------------+
|
102
102
|
| File | Key | Value |
|
103
103
|
+----------------------------------------------------------------------------+
|
@@ -115,7 +115,7 @@ $ ansbile-tools show
|
|
115
115
|
show version
|
116
116
|
|
117
117
|
```
|
118
|
-
$
|
118
|
+
$ ansible-tools version
|
119
119
|
0.0.4
|
120
120
|
```
|
121
121
|
|
data/lib/ansible_tools.rb
CHANGED
@@ -124,50 +124,40 @@ module AnsibleTools
|
|
124
124
|
table = Ruport::Data::Table.new
|
125
125
|
table.column_names = %w[File Key Value]
|
126
126
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
next
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
}
|
153
|
-
# search roles/*/vars/*.yml
|
154
|
-
Dir.glob("**/vars/*") {|f|
|
155
|
-
next unless FileTest.file?(f) #skip directory
|
156
|
-
yml = YAML.load_file(f)
|
157
|
-
if yml == false
|
158
|
-
puts "No Variables in #{f}"
|
159
|
-
next
|
160
|
-
end
|
161
|
-
yml.each{|key,value|
|
162
|
-
table << [f,key,value]
|
127
|
+
regexp_str = Array.new
|
128
|
+
regexp_str << "*.yml" # search *.yml
|
129
|
+
regexp_str << "*/*.yml" # search */*.yml e.g. group_vars, host_vars
|
130
|
+
regexp_str << "**/vars/*" # search roles/*/vars/*.yml
|
131
|
+
regexp_str.each{|str|
|
132
|
+
Dir.glob(str) {|f|
|
133
|
+
next unless FileTest.file?(f) #skip directory
|
134
|
+
yml = YAML.load_file(f)
|
135
|
+
if yml == false
|
136
|
+
puts "No Variables in #{f}"
|
137
|
+
next
|
138
|
+
end
|
139
|
+
if str == "*.yml"
|
140
|
+
yml.each{|h|
|
141
|
+
if h.instance_of?(Hash) && h.has_key?("vars")
|
142
|
+
h["vars"].each{|key,value|
|
143
|
+
table << [f,key,value]
|
144
|
+
}
|
145
|
+
end
|
146
|
+
}
|
147
|
+
else
|
148
|
+
yml.each{|key,value|
|
149
|
+
table << [f,key,value]
|
150
|
+
}
|
151
|
+
end
|
163
152
|
}
|
164
153
|
}
|
154
|
+
|
165
155
|
if table.count > 0
|
166
156
|
puts table.to_text
|
167
157
|
end
|
168
|
-
rescue
|
169
|
-
puts
|
170
|
-
|
158
|
+
rescue => e
|
159
|
+
puts e
|
160
|
+
fail 'Sorry. Error hanppend..'
|
171
161
|
end
|
172
162
|
end
|
173
163
|
|
data/spec/commands_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'ansible_tools'
|
3
|
+
require 'yaml'
|
3
4
|
|
4
5
|
test_dir = "tmp"
|
5
6
|
|
@@ -26,82 +27,69 @@ describe "テスト" do
|
|
26
27
|
|
27
28
|
# ディレクトリの存在をチェックする。
|
28
29
|
def expect_dir_exist(array)
|
29
|
-
array
|
30
|
+
array.each{|d|
|
30
31
|
expect(File.directory?(d)).to be_truthy
|
31
32
|
}
|
32
33
|
end
|
33
34
|
# ファイルの存在をチェックする。
|
34
35
|
def expect_file_exist(array)
|
35
|
-
array
|
36
|
+
array.each{|f|
|
36
37
|
expect(FileTest.exist?(f)).to be_truthy
|
37
38
|
}
|
38
39
|
end
|
39
40
|
|
41
|
+
#YAMLファイルをロードする。
|
42
|
+
def load_yaml(path)
|
43
|
+
yaml = File.open( File.dirname(__FILE__) + path).read
|
44
|
+
return YAML.load(yaml)
|
45
|
+
end
|
46
|
+
|
47
|
+
# run: ansbile-tools init
|
40
48
|
it "init(yml-only = false)" do
|
41
49
|
AnsibleTools.init(false)
|
42
|
-
|
43
|
-
expect_file_exist(
|
44
|
-
expect_dir_exist(
|
50
|
+
yaml = load_yaml("/lists/init_false.yml")
|
51
|
+
expect_file_exist(yaml["file"])
|
52
|
+
expect_dir_exist(yaml["dir"])
|
45
53
|
end
|
46
54
|
|
55
|
+
# run: ansbile-tools init -y
|
47
56
|
it "init(yml-only = true)" do
|
48
57
|
AnsibleTools.init(true)
|
49
|
-
|
50
|
-
expect_file_exist(
|
51
|
-
expect_dir_exist(
|
58
|
+
yaml = load_yaml("/lists/init_true.yml")
|
59
|
+
expect_file_exist(yaml["file"])
|
60
|
+
expect_dir_exist(yaml["dir"])
|
61
|
+
end
|
62
|
+
|
63
|
+
# run: ansbile-tools init -s
|
64
|
+
it "init simple (yml-only = false)" do
|
65
|
+
AnsibleTools.init_simple(false)
|
66
|
+
yaml = load_yaml("/lists/init_simple_false.yml")
|
67
|
+
expect_file_exist(yaml["file"])
|
68
|
+
expect_dir_exist(yaml["dir"])
|
52
69
|
end
|
53
70
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
"roles/common/tasks/main.yml",
|
61
|
-
"roles/common/handlers/main.yml",
|
62
|
-
"roles/common/templates/foo.conf.j2",
|
63
|
-
"roles/common/vars/main.yml",
|
64
|
-
"roles/common/files/bar.txt",
|
65
|
-
"production",
|
66
|
-
"stage",
|
67
|
-
"group_vars/group1",
|
68
|
-
"group_vars/group2",
|
69
|
-
"host_vars/hostname1",
|
70
|
-
"host_vars/hostname2"
|
71
|
-
]
|
72
|
-
res["created_dir"] = [
|
73
|
-
"roles",
|
74
|
-
"roles/common",
|
75
|
-
"roles/common/tasks",
|
76
|
-
"roles/common/handlers",
|
77
|
-
"roles/common/templates",
|
78
|
-
"roles/common/vars",
|
79
|
-
"roles/common/files",
|
80
|
-
"group_vars",
|
81
|
-
"host_vars",
|
82
|
-
]
|
83
|
-
return res
|
71
|
+
# run: ansbile-tools init -s -y
|
72
|
+
it "init simple (yml-only = true)" do
|
73
|
+
AnsibleTools.init_simple(true)
|
74
|
+
yaml = load_yaml("/lists/init_simple_true.yml")
|
75
|
+
expect_file_exist(yaml["file"])
|
76
|
+
expect_dir_exist(yaml["dir"])
|
84
77
|
end
|
85
78
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
"roles/common/tasks/main.yml",
|
93
|
-
"roles/common/handlers/main.yml",
|
94
|
-
"roles/common/vars/main.yml",
|
95
|
-
]
|
96
|
-
res["created_dir"] = [
|
97
|
-
"roles",
|
98
|
-
"roles/common",
|
99
|
-
"roles/common/tasks",
|
100
|
-
"roles/common/handlers",
|
101
|
-
"roles/common/templates",
|
102
|
-
"roles/common/vars",
|
103
|
-
"roles/common/files",
|
104
|
-
]
|
105
|
-
return res
|
79
|
+
# run: ansbile-tools init -r gitlab
|
80
|
+
it "init role (yml-only = false)" do
|
81
|
+
AnsibleTools.init_role("gitlab", false)
|
82
|
+
yaml = load_yaml("/lists/init_role_false.yml")
|
83
|
+
expect_file_exist(yaml["file"])
|
84
|
+
expect_dir_exist(yaml["dir"])
|
106
85
|
end
|
86
|
+
|
87
|
+
# run: ansbile-tools init -r gitlab -y
|
88
|
+
it "init role (yml-only = true)" do
|
89
|
+
AnsibleTools.init_role("gitlab", true)
|
90
|
+
yaml = load_yaml("/lists/init_role_true.yml")
|
91
|
+
expect_file_exist(yaml["file"])
|
92
|
+
expect_dir_exist(yaml["dir"])
|
93
|
+
end
|
94
|
+
|
107
95
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"file":
|
2
|
+
- "group_vars"
|
3
|
+
- "host_vars"
|
4
|
+
- "site.yml"
|
5
|
+
- "roles/common/tasks/main.yml"
|
6
|
+
- "roles/common/handlers/main.yml"
|
7
|
+
- "roles/common/templates/foo.conf.j2"
|
8
|
+
- "roles/common/vars/main.yml"
|
9
|
+
- "roles/common/files/bar.txt"
|
10
|
+
- "production"
|
11
|
+
- "stage"
|
12
|
+
- "group_vars/group1"
|
13
|
+
- "group_vars/group2"
|
14
|
+
- "host_vars/hostname1"
|
15
|
+
- "host_vars/hostname2"
|
16
|
+
"dir":
|
17
|
+
- "roles"
|
18
|
+
- "roles/common"
|
19
|
+
- "roles/common/tasks"
|
20
|
+
- "roles/common/handlers"
|
21
|
+
- "roles/common/templates"
|
22
|
+
- "roles/common/vars"
|
23
|
+
- "roles/common/files"
|
24
|
+
- "group_vars"
|
25
|
+
- "host_vars"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"file":
|
2
|
+
- "site.yml"
|
3
|
+
- "roles/gitlab/tasks/main.yml"
|
4
|
+
- "roles/gitlab/handlers/main.yml"
|
5
|
+
- "roles/gitlab/templates/foo.conf.j2"
|
6
|
+
- "roles/gitlab/vars/main.yml"
|
7
|
+
- "roles/gitlab/files/bar.txt"
|
8
|
+
"dir":
|
9
|
+
- "roles"
|
10
|
+
- "roles/gitlab"
|
11
|
+
- "roles/gitlab/tasks"
|
12
|
+
- "roles/gitlab/handlers"
|
13
|
+
- "roles/gitlab/templates"
|
14
|
+
- "roles/gitlab/vars"
|
15
|
+
- "roles/gitlab/files"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"file":
|
2
|
+
- "site.yml"
|
3
|
+
- "roles/gitlab/tasks/main.yml"
|
4
|
+
- "roles/gitlab/handlers/main.yml"
|
5
|
+
- "roles/gitlab/vars/main.yml"
|
6
|
+
"dir":
|
7
|
+
- "roles"
|
8
|
+
- "roles/gitlab"
|
9
|
+
- "roles/gitlab/tasks"
|
10
|
+
- "roles/gitlab/handlers"
|
11
|
+
- "roles/gitlab/templates"
|
12
|
+
- "roles/gitlab/vars"
|
13
|
+
- "roles/gitlab/files"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"file":
|
2
|
+
- "site.yml"
|
3
|
+
- "roles/common/tasks/main.yml"
|
4
|
+
- "roles/common/handlers/main.yml"
|
5
|
+
- "roles/common/templates/foo.conf.j2"
|
6
|
+
- "roles/common/vars/main.yml"
|
7
|
+
- "roles/common/files/bar.txt"
|
8
|
+
"dir":
|
9
|
+
- "roles"
|
10
|
+
- "roles/common"
|
11
|
+
- "roles/common/tasks"
|
12
|
+
- "roles/common/handlers"
|
13
|
+
- "roles/common/templates"
|
14
|
+
- "roles/common/vars"
|
15
|
+
- "roles/common/files"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"file":
|
2
|
+
- "site.yml"
|
3
|
+
- "roles/common/tasks/main.yml"
|
4
|
+
- "roles/common/handlers/main.yml"
|
5
|
+
- "roles/common/vars/main.yml"
|
6
|
+
"dir":
|
7
|
+
- "roles"
|
8
|
+
- "roles/common"
|
9
|
+
- "roles/common/tasks"
|
10
|
+
- "roles/common/handlers"
|
11
|
+
- "roles/common/templates"
|
12
|
+
- "roles/common/vars"
|
13
|
+
- "roles/common/files"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"file":
|
2
|
+
- "group_vars"
|
3
|
+
- "host_vars"
|
4
|
+
- "site.yml"
|
5
|
+
- "roles/common/tasks/main.yml"
|
6
|
+
- "roles/common/handlers/main.yml"
|
7
|
+
- "roles/common/vars/main.yml"
|
8
|
+
"dir":
|
9
|
+
- "roles"
|
10
|
+
- "roles/common"
|
11
|
+
- "roles/common/tasks"
|
12
|
+
- "roles/common/handlers"
|
13
|
+
- "roles/common/templates"
|
14
|
+
- "roles/common/vars"
|
15
|
+
- "roles/common/files"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansible_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.4.
|
4
|
+
version: 0.0.4.3
|
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-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -101,6 +101,12 @@ files:
|
|
101
101
|
- lib/ansible_tools.rb
|
102
102
|
- lib/ansible_tools/version.rb
|
103
103
|
- spec/commands_spec.rb
|
104
|
+
- spec/lists/init_false.yml
|
105
|
+
- spec/lists/init_role_false.yml
|
106
|
+
- spec/lists/init_role_true.yml
|
107
|
+
- spec/lists/init_simple_false.yml
|
108
|
+
- spec/lists/init_simple_true.yml
|
109
|
+
- spec/lists/init_true.yml
|
104
110
|
- spec/spec_helper.rb
|
105
111
|
homepage: https://github.com/volanja
|
106
112
|
licenses:
|
@@ -128,4 +134,10 @@ specification_version: 4
|
|
128
134
|
summary: Ansible Tools e.g. Create directory by BestPractice
|
129
135
|
test_files:
|
130
136
|
- spec/commands_spec.rb
|
137
|
+
- spec/lists/init_false.yml
|
138
|
+
- spec/lists/init_role_false.yml
|
139
|
+
- spec/lists/init_role_true.yml
|
140
|
+
- spec/lists/init_simple_false.yml
|
141
|
+
- spec/lists/init_simple_true.yml
|
142
|
+
- spec/lists/init_true.yml
|
131
143
|
- spec/spec_helper.rb
|