ansible_tools 0.0.4.2 → 0.0.4.3

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
  SHA1:
3
- metadata.gz: 94fb995baabedf8e996bba56a662b1da6ab184e3
4
- data.tar.gz: ce1e98e939b665cfe5810af5cf80427eb2c328b7
3
+ metadata.gz: 30b2f60295d3cd2a95e09ca5aced123fe4892c01
4
+ data.tar.gz: 8f76703395860c42fa6246faa85e5cc9705ebfbf
5
5
  SHA512:
6
- metadata.gz: cb099f0076cfa2b549c06815632ae6338bf4e7b81811d5b260dff5fd1d27f4d7981006a95d7e4f43f91cabd61c78264d32625afa059dd309d1fcc2250a40e488
7
- data.tar.gz: debb812b52f074a31dad66457ee84abfb8ed9406cff3dae774f2ab25c3a49cf823804b0096f74684f6e82cab753d8a3da19b10c393617af331387b7de06a07ad
6
+ metadata.gz: e6049c692d0f951a2bfd255561bd6b3c4f45aa471504e1c27572b7a6bedeeaa1a8fa13426ebf556de2f73e910ded01c55074076b9e18868ef00ce21ec1293467
7
+ data.tar.gz: e600b9926210ceff39e97d4e669106c3dbe8a9ddc9ce4db3e225fae3e621c8a88b1cc1d3bc4aace5da71cdf5357f2829624ce7f3febdf8e0650a286688c42b58
@@ -1,8 +1,11 @@
1
1
  language: ruby
2
+ sudo: false
2
3
  rvm:
3
4
  - 1.9.3
4
5
  - 2.0.0
5
6
  - 2.1.0
6
7
  - 2.1.1
8
+ - 2.2.0
9
+ - 2.2.1
7
10
  script:
8
11
  - rspec spec
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
- [![Coverage Status](https://coveralls.io/repos/volanja/ansible_tools/badge.png)](https://coveralls.io/r/volanja/ansible_tools)
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
- $ ansbile-tools init [-y]
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
- $ ansbile-tools init -s [-y]
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
- $ ansbile-tools init -r <roles name> [-y]
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
- $ ansbile-tools show
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
- $ ansbile-tools version
118
+ $ ansible-tools version
119
119
  0.0.4
120
120
  ```
121
121
 
@@ -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
- # search *.yml
128
- Dir.glob("*.yml") {|f|
129
- next unless FileTest.file?(f) #skip directory
130
- yml = YAML.load_file(f)
131
- if yml == false
132
- puts "No Variables in #{f}"
133
- next
134
- end
135
- yml.each{|h|
136
- h["vars"].each{|key,value|
137
- table << [f,key,value]
138
- }
139
- }
140
- }
141
- # search */*.yml e.g. group_vars, host_vars
142
- Dir.glob("*/*.yml") {|f|
143
- next unless FileTest.file?(f) #skip directory
144
- yml = YAML.load_file(f)
145
- if yml == false
146
- puts "No Variables in #{f}"
147
- next
148
- end
149
- yml.each{|key,value|
150
- table << [f,key,value]
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 'Sorry. Error hanppend..'
170
- exit 1
158
+ rescue => e
159
+ puts e
160
+ fail 'Sorry. Error hanppend..'
171
161
  end
172
162
  end
173
163
 
@@ -1,3 +1,3 @@
1
1
  module AnsibleTools
2
- VERSION = "0.0.4.2"
2
+ VERSION = "0.0.4.3"
3
3
  end
@@ -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["created_dir"].each{|d|
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["created_file"].each{|f|
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
- array = init_false
43
- expect_file_exist(array)
44
- expect_dir_exist(array)
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
- array = init_true
50
- expect_file_exist(array)
51
- expect_dir_exist(array)
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
- def init_false
55
- res = Hash.new
56
- res["created_file"] = [
57
- "group_vars",
58
- "host_vars",
59
- "site.yml",
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
- def init_true
87
- res = Hash.new
88
- res["created_file"] = [
89
- "group_vars",
90
- "host_vars",
91
- "site.yml",
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.2
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: 2014-10-18 00:00:00.000000000 Z
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