ansible_tools 0.0.3.1 → 0.0.4

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.
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: Dus6yjl3TGYJvy2BWKuDl5CWDbv5LTqQk
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in ansible_tools.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -2,91 +2,93 @@
2
2
 
3
3
  Ansible Tools e.g. Create directory by BestPractice
4
4
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'ansible_tools'
5
+ [![Code Climate](https://codeclimate.com/github/volanja/ansible_tools.png)](https://codeclimate.com/github/volanja/ansible_tools)
6
+ [![Coverage Status](https://coveralls.io/repos/volanja/ansible_tools/badge.png)](https://coveralls.io/r/volanja/ansible_tools)
10
7
 
11
- And then execute:
12
-
13
- $ bundle install
14
-
15
- Or install it yourself as:
8
+ ## Installation
16
9
 
17
- $ gem install ansible_tools
10
+ Install it yourself as:
11
+ ```
12
+ $ gem install ansible_tools
13
+ ```
18
14
 
19
15
  ## Usage
20
16
 
21
17
  ```
22
18
  $ ansible-tools
23
19
  Commands:
24
- ansible-tools help [COMMAND] # Describe available commands or one specific command
25
- ansible-tools init [-s][-r] # create ansible files by BestPractice
26
- ansible-tools show # show ansible valiables in vars/main.yml
27
- ansible-tools version # show version
20
+ ansible-tools help [COMMAND] # Describe available commands or one specific command
21
+ ansible-tools init [-s][-r][-y] # create ansible files by BestPractice
22
+ ansible-tools show # show ansible valiables in vars/main.yml
23
+ ansible-tools version # show version
28
24
  ```
29
25
 
30
26
  ### BestPractice
31
27
  [Best Practices - ANSIBLEWORKS](http://www.ansibleworks.com/docs/playbooks_best_practices.html)
32
28
 
33
29
  ```
34
- $ ansbile-tools init
30
+ $ ansbile-tools init [-y]
35
31
  create roles/common/tasks
36
32
  create roles/common/handlers
37
33
  create roles/common/templates
38
34
  create roles/common/vars
39
- create roles/common/file
40
- create group_var
41
- create host_var
35
+ create roles/common/files
36
+ create group_vars
37
+ create host_vars
42
38
  create site.yml
43
39
  create roles/common/tasks/main.yml
44
40
  create roles/common/handlers/main.yml
45
- create roles/common/templates/foo.conf.j2
41
+ create roles/common/templates/foo.conf.j2 #(*1)
46
42
  create roles/common/vars/main.yml
47
- create roles/common/file/bar.txt
48
- create production
49
- create stage
50
- create group_var/group1
51
- create group_var/group2
52
- create host_var/hostname1
53
- create host_var/hostname2
43
+ create roles/common/files/bar.txt #(*1)
44
+ create production #(*1)
45
+ create stage #(*1)
46
+ create group_vars/group1 #(*1)
47
+ create group_vars/group2 #(*1)
48
+ create host_vars/hostname1 #(*1)
49
+ create host_vars/hostname2 #(*1)
50
+
51
+ (*1)...if set [-y], this file is not create.
54
52
  ```
55
53
 
56
54
  ### Simple
57
55
 
58
56
  ```
59
- $ ansbile-tools init -s
57
+ $ ansbile-tools init -s [-y]
60
58
  create roles/common/tasks
61
59
  create roles/common/handlers
62
60
  create roles/common/templates
63
61
  create roles/common/vars
64
- create roles/common/file
62
+ create roles/common/files
65
63
  create site.yml
66
64
  create roles/common/tasks/main.yml
67
65
  create roles/common/handlers/main.yml
68
- create roles/common/templates/foo.conf.j2
66
+ create roles/common/templates/foo.conf.j2 #(*1)
69
67
  create roles/common/vars/main.yml
70
- create roles/common/file/bar.txt
68
+ create roles/common/files/bar.txt #(*1)
69
+
70
+ (*1)...if set [-y], this file is not create.
71
71
  ```
72
72
 
73
73
  ### Add Role
74
74
 
75
75
  ```
76
- $ ansbile-tools init -r <roles name>
76
+ $ ansbile-tools init -r <roles name> [-y]
77
77
 
78
78
  $ ansible-tools init -r gitlab
79
79
  create roles/gitlab/tasks
80
80
  create roles/gitlab/handlers
81
81
  create roles/gitlab/templates
82
82
  create roles/gitlab/vars
83
- create roles/gitlab/file
83
+ create roles/gitlab/files
84
84
  create site.yml
85
85
  create roles/gitlab/tasks/main.yml
86
86
  create roles/gitlab/handlers/main.yml
87
- create roles/gitlab/templates/foo.conf.j2
87
+ create roles/gitlab/templates/foo.conf.j2 #(*1)
88
88
  create roles/gitlab/vars/main.yml
89
- create roles/gitlab/file/bar.txt
89
+ create roles/gitlab/files/bar.txt #(*1)
90
+
91
+ (*1)...if set [-y], this file is not create.
90
92
  ```
91
93
 
92
94
  ### Show Variables
@@ -110,7 +112,7 @@ show version
110
112
 
111
113
  ```
112
114
  $ ansbile-tools version
113
- 0.0.1
115
+ 0.0.4
114
116
  ```
115
117
 
116
118
  ## Contributing
@@ -121,5 +123,8 @@ $ ansbile-tools version
121
123
  4. Push to the branch (`git push origin my-new-feature`)
122
124
  5. Create new Pull Request
123
125
 
126
+ ## History
127
+ 0.0.4 Add Option init [-y]
128
+
124
129
  ## TODO
125
130
  + Make Test
data/bin/ansible-tools CHANGED
@@ -7,16 +7,17 @@ require 'thor'
7
7
 
8
8
  class Cli < Thor
9
9
 
10
- desc "init [-s][-r]", "create ansible files by BestPractice"
10
+ desc "init [-s][-r][-y]", "create ansible files by BestPractice"
11
11
  option :simple, :type => :boolean, :aliases => '-s', :desc => "simple-mode, create only setup.yml, roles/common"
12
12
  option :role, :type => :string, :aliases => '-r', :desc => "create roles/ROLE"
13
+ option :"yml-only", :type => :boolean, :aliases => '-y', :desc => "create directory and yml"
13
14
  def init
14
15
  if options[:simple]
15
- AnsibleTools.init_simple
16
+ AnsibleTools.init_simple(options[:"yml-only"])
16
17
  elsif options[:role]
17
- AnsibleTools.init_role("#{options[:role]}")
18
+ AnsibleTools.init_role("#{options[:role]}", options[:"yml-only"])
18
19
  else
19
- AnsibleTools.init
20
+ AnsibleTools.init(options[:"yml-only"])
20
21
  end
21
22
  end
22
23
 
@@ -1,3 +1,3 @@
1
1
  module AnsibleTools
2
- VERSION = "0.0.3.1"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/ansible_tools.rb CHANGED
@@ -6,21 +6,21 @@ require 'ruport'
6
6
  module AnsibleTools
7
7
 
8
8
  # command ansible-tools init
9
- def self.init()
10
- simple = safe_list_simple('common')
9
+ def self.init(yml_only)
10
+ simple = yml_only ? safe_list_yml_only('common') : safe_list_simple('common')
11
11
  complex = safe_list_complex()
12
12
  # dir
13
13
  simple[:dir].each { |dir| safe_mkdir(dir) }
14
14
  complex[:dir].each { |dir| safe_mkdir(dir) }
15
15
  # file
16
16
  simple[:file].each { |file| safe_touch(file) }
17
- complex[:file].each { |file| safe_touch(file) }
17
+ complex[:file].each { |file| safe_touch(file) } unless yml_only
18
18
 
19
19
  end
20
-
20
+
21
21
  # command ansible-tools init -s
22
- def self.init_simple()
23
- simple = safe_list_simple('common')
22
+ def self.init_simple(yml_only)
23
+ simple = yml_only ? safe_list_yml_only('common') : safe_list_simple('common')
24
24
  # dir
25
25
  simple[:dir].each { |dir| safe_mkdir(dir) }
26
26
  # file
@@ -28,8 +28,8 @@ module AnsibleTools
28
28
  end
29
29
 
30
30
  # command ansible-tools init -r <rolename>
31
- def self.init_role(name)
32
- role = safe_list_simple("#{name}")
31
+ def self.init_role(name, yml_only)
32
+ role = yml_only ? safe_list_yml_only("#{name}") : safe_list_simple("#{name}")
33
33
  # dir
34
34
  role[:dir].each { |dir| safe_mkdir(dir) }
35
35
  # file
@@ -57,6 +57,26 @@ module AnsibleTools
57
57
  return {:dir => dir, :file => file}
58
58
  end
59
59
 
60
+ def self.safe_list_yml_only(role)
61
+ dir = Array.new
62
+ dir_role = "roles/#{role}"
63
+ tasks = "#{dir_role}/tasks"
64
+ handlers = "#{dir_role}/handlers"
65
+ templates = "#{dir_role}/templates"
66
+ vars = "#{dir_role}/vars"
67
+ files = "#{dir_role}/files"
68
+ dir = [tasks,handlers,templates,vars,files]
69
+
70
+ file = Array.new
71
+ site = 'site.yml'
72
+ f_task = "#{tasks}/main.yml"
73
+ f_handlers = "#{handlers}/main.yml"
74
+ f_vars = "#{vars}/main.yml"
75
+ file = [site,f_task,f_handlers, f_vars]
76
+ return {:dir => dir, :file => file}
77
+ end
78
+
79
+
60
80
  def self.safe_list_complex()
61
81
  dir = Array.new
62
82
  group = 'group_vars'
@@ -65,7 +85,7 @@ module AnsibleTools
65
85
  file = ["production", "stage", "#{group}/group1", "#{group}/group2", "#{host}/hostname1", "#{host}/hostname2"]
66
86
  return {:dir => dir, :file => file}
67
87
  end
68
-
88
+
69
89
  def self.safe_mkdir(dir)
70
90
  unless FileTest.exist?("#{dir}")
71
91
  FileUtils.mkdir_p("#{dir}")
@@ -87,7 +107,7 @@ module AnsibleTools
87
107
  TermColor.green
88
108
  puts "\t\tcreate\t#{file}"
89
109
  TermColor.reset
90
- else
110
+ else
91
111
  TermColor.red
92
112
  puts "\t\texists\t#{file}"
93
113
  TermColor.reset
@@ -126,17 +146,17 @@ module AnsibleTools
126
146
  class TermColor
127
147
  class << self
128
148
  # 色を解除
129
- def reset ; c 0 ; end
130
-
149
+ def reset ; c 0 ; end
150
+
131
151
  # 各色
132
- def red ; c 31; end
133
- def green ; c 32; end
134
-
152
+ def red ; c 31; end
153
+ def green ; c 32; end
154
+
135
155
  # カラーシーケンスの出力
136
156
  def c(num)
137
157
  print "\e[#{num.to_s}m"
138
- end
139
- end
158
+ end
159
+ end
140
160
  end
141
161
 
142
162
  end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'ansible_tools'
4
+
5
+ require 'coveralls'
6
+ Coveralls.wear!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansible_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.1
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-20 00:00:00.000000000 Z
12
+ date: 2014-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -115,6 +115,7 @@ executables:
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - .coveralls.yml
118
119
  - .gitignore
119
120
  - Gemfile
120
121
  - LICENSE.txt
@@ -124,6 +125,7 @@ files:
124
125
  - bin/ansible-tools
125
126
  - lib/ansible_tools.rb
126
127
  - lib/ansible_tools/version.rb
128
+ - spec/spec_helper.rb
127
129
  homepage: https://github.com/volanja
128
130
  licenses:
129
131
  - MIT
@@ -149,4 +151,5 @@ rubygems_version: 1.8.24
149
151
  signing_key:
150
152
  specification_version: 3
151
153
  summary: Ansible Tools e.g. Create directory by BestPractice
152
- test_files: []
154
+ test_files:
155
+ - spec/spec_helper.rb