ansible_tools 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d34641328a3d89bf9307516fc56ec2fefb56858e
4
+ data.tar.gz: afba9b96e204a62df1e055d0e54cbdc840da3492
5
+ SHA512:
6
+ metadata.gz: 51f7b7255900408cfb18b874841d69e9f59d44b59f145dc02e994e06b51e9efee672ae993fb1dd9de265313f98548f7ba4b35b8c92c6669bce576c9b790153d9
7
+ data.tar.gz: fd6bace8680a38c62de3cea9ed9f66d942042d7930f423eddb88f2ef4522b47da02c59f558ee33bdd12a409e2454240023c1c94551ee911e3df2a28df96cf228
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ansible_tools.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 volanja
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # AnsibleTools
2
+
3
+ Ansible Tools e.g. Create directory by BestPractice
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ansible_tools'
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ansible_tools
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ $ ansible-tools
23
+ 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
28
+ ```
29
+
30
+ ### BestPractice
31
+ [Best Practices - ANSIBLEWORKS](http://www.ansibleworks.com/docs/playbooks_best_practices.html)
32
+
33
+ ```
34
+ $ ansbile-tools init
35
+ create roles/common/tasks
36
+ create roles/common/handlers
37
+ create roles/common/templates
38
+ create roles/common/vars
39
+ create roles/common/file
40
+ create group_var
41
+ create host_var
42
+ create site.yml
43
+ create roles/common/tasks/main.yml
44
+ create roles/common/handlers/main.yml
45
+ create roles/common/templates/foo.conf.j2
46
+ 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
54
+ ```
55
+
56
+ ### Simple
57
+
58
+ ```
59
+ $ ansbile-tools init -s
60
+ create roles/common/tasks
61
+ create roles/common/handlers
62
+ create roles/common/templates
63
+ create roles/common/vars
64
+ create roles/common/file
65
+ create site.yml
66
+ create roles/common/tasks/main.yml
67
+ create roles/common/handlers/main.yml
68
+ create roles/common/templates/foo.conf.j2
69
+ create roles/common/vars/main.yml
70
+ create roles/common/file/bar.txt
71
+ ```
72
+
73
+ ### Add Role
74
+
75
+ ```
76
+ $ ansbile-tools init -r <roles name>
77
+
78
+ $ ansible-tools init -r gitlab
79
+ create roles/gitlab/tasks
80
+ create roles/gitlab/handlers
81
+ create roles/gitlab/templates
82
+ create roles/gitlab/vars
83
+ create roles/gitlab/file
84
+ create site.yml
85
+ create roles/gitlab/tasks/main.yml
86
+ create roles/gitlab/handlers/main.yml
87
+ create roles/gitlab/templates/foo.conf.j2
88
+ create roles/gitlab/vars/main.yml
89
+ create roles/gitlab/file/bar.txt
90
+ ```
91
+
92
+ ### Show Variables
93
+ Search vars/main.yml and write list
94
+
95
+ ```
96
+ $ ansbile-tools show
97
+ +----------------------------------------------------------------------------+
98
+ | File | Key | Value |
99
+ +----------------------------------------------------------------------------+
100
+ | roles/gitlab/vars/main.yml | mysql_gitlab_password | password |
101
+ | roles/gitlab/vars/main.yml | mysql_gitlab_database | gitlabhq_production |
102
+ | roles/mariadb/vars/main.yml | mysql_root_password | password |
103
+ | roles/Packages/vars/main.yml | www_port | 80 |
104
+ | roles/ruby/vars/main.yml | ruby_ver | 2.0.0-p247 |
105
+ +----------------------------------------------------------------------------+
106
+ ```
107
+
108
+ ### Show Variables
109
+ show version
110
+
111
+ ```
112
+ $ ansbile-tools version
113
+ 0.0.1
114
+ ```
115
+
116
+ ## Contributing
117
+
118
+ 1. Fork it
119
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
120
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
121
+ 4. Push to the branch (`git push origin my-new-feature`)
122
+ 5. Create new Pull Request
123
+
124
+ ## TODO
125
+ + Make Test
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ansible_tools/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ansible_tools"
8
+ spec.version = AnsibleTools::VERSION
9
+ spec.authors = ["volanja"]
10
+ spec.email = ["volaaanja@gmail.com"]
11
+ spec.description = %q{Ansible Tools e.g. Create directory by BestPractice}
12
+ spec.summary = %q{Ansible Tools e.g. Create directory by BestPractice}
13
+ spec.homepage = "https://github.com/volanja"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "thor", "~> 0.18.1"
24
+ spec.add_development_dependency "ruport", "~> 1.6.3"
25
+ end
data/bin/ansible-tools ADDED
@@ -0,0 +1,36 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require 'ansible_tools'
5
+ require 'rubygems'
6
+ require 'thor'
7
+
8
+ class Cli < Thor
9
+
10
+ desc "init [-s][-r]", "create ansible files by BestPractice"
11
+ option :simple, :type => :boolean, :aliases => '-s', :desc => "simple-mode, create only setup.yml, roles/common"
12
+ option :role, :type => :string, :aliases => '-r', :desc => "create roles/ROLE"
13
+ def init
14
+ if options[:simple]
15
+ AnsibleTools.init_simple
16
+ elsif options[:role]
17
+ AnsibleTools.init_role("#{options[:role]}")
18
+ else
19
+ AnsibleTools.init
20
+ end
21
+ end
22
+
23
+ desc "show", "show ansible valiables in vars/main.yml"
24
+ def show
25
+ AnsibleTools.show
26
+ end
27
+
28
+ desc "version", "show version"
29
+ def version
30
+ puts AnsibleTools::VERSION
31
+ end
32
+ end
33
+
34
+ Cli.start
35
+
36
+ exit 0
@@ -0,0 +1,3 @@
1
+ module AnsibleTools
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,142 @@
1
+ require "ansible_tools/version"
2
+ require "fileutils"
3
+ require "yaml"
4
+ require 'ruport'
5
+
6
+ module AnsibleTools
7
+
8
+ # command ansible-tools init
9
+ def self.init()
10
+ simple = safe_list_simple('common')
11
+ complex = safe_list_complex()
12
+ # dir
13
+ simple[:dir].each { |dir| safe_mkdir(dir) }
14
+ complex[:dir].each { |dir| safe_mkdir(dir) }
15
+ # file
16
+ simple[:file].each { |file| safe_touch(file) }
17
+ complex[:file].each { |file| safe_touch(file) }
18
+
19
+ end
20
+
21
+ # command ansible-tools init -s
22
+ def self.init_simple()
23
+ simple = safe_list_simple('common')
24
+ # dir
25
+ simple[:dir].each { |dir| safe_mkdir(dir) }
26
+ # file
27
+ simple[:file].each { |file| safe_touch(file) }
28
+ end
29
+
30
+ # command ansible-tools init -r <rolename>
31
+ def self.init_role(name)
32
+ role = safe_list_simple("#{name}")
33
+ # dir
34
+ role[:dir].each { |dir| safe_mkdir(dir) }
35
+ # file
36
+ role[:file].each { |file| safe_touch(file) }
37
+ end
38
+
39
+ def self.safe_list_simple(role)
40
+ dir = Array.new
41
+ dir_role = "roles/#{role}"
42
+ tasks = "#{dir_role}/tasks"
43
+ handlers = "#{dir_role}/handlers"
44
+ templates = "#{dir_role}/templates"
45
+ vars = "#{dir_role}/vars"
46
+ files = "#{dir_role}/file"
47
+ dir = [tasks,handlers,templates,vars,files]
48
+
49
+ file = Array.new
50
+ site = 'site.yml'
51
+ f_task = "#{tasks}/main.yml"
52
+ f_handlers = "#{handlers}/main.yml"
53
+ f_templates = "#{templates}/foo.conf.j2"
54
+ f_vars = "#{vars}/main.yml"
55
+ f_file = "#{files}/bar.txt"
56
+ file = [site,f_task,f_handlers,f_templates, f_vars, f_file]
57
+ return {:dir => dir, :file => file}
58
+ end
59
+
60
+ def self.safe_list_complex()
61
+ dir = Array.new
62
+ group = 'group_var'
63
+ host = 'host_var'
64
+ dir = [group, host]
65
+ file = ["production", "stage", "#{group}/group1", "#{group}/group2", "#{host}/hostname1", "#{host}/hostname2"]
66
+ return {:dir => dir, :file => file}
67
+ end
68
+
69
+ def self.safe_mkdir(dir)
70
+ unless FileTest.exist?("#{dir}")
71
+ FileUtils.mkdir_p("#{dir}")
72
+ TermColor.green
73
+ puts "\t\tcreate\t#{dir}"
74
+ TermColor.reset
75
+ else
76
+ TermColor.red
77
+ puts "\t\texists\t#{dir}"
78
+ TermColor.reset
79
+ end
80
+ end
81
+
82
+ def self.safe_touch(file)
83
+ unless File.exists? "#{file}"
84
+ File.open("#{file}", 'w') do |f|
85
+ #f.puts content
86
+ end
87
+ TermColor.green
88
+ puts "\t\tcreate\t#{file}"
89
+ TermColor.reset
90
+ else
91
+ TermColor.red
92
+ puts "\t\texists\t#{file}"
93
+ TermColor.reset
94
+ end
95
+ end
96
+
97
+ # command ansible-tools show
98
+ def self.show()
99
+ begin
100
+ if Dir.glob("**/vars/*").count == 0
101
+ puts 'Not Found'
102
+ exit 1
103
+ end
104
+ table = Ruport::Data::Table.new
105
+ table.column_names = %w[File Key Value]
106
+ Dir.glob("**/vars/*") {|f|
107
+ next unless FileTest.file?(f) #skip directory
108
+ yml = YAML.load_file(f)
109
+ if yml == false
110
+ puts "No Variables in #{f}"
111
+ next
112
+ end
113
+ yml.each{|key,value|
114
+ table << [f,key,value]
115
+ }
116
+ }
117
+ if table.count > 0
118
+ puts table.to_text
119
+ end
120
+ rescue
121
+ puts 'Sorry. Error hanppend..'
122
+ exit 1
123
+ end
124
+ end
125
+
126
+ class TermColor
127
+ class << self
128
+ # 色を解除
129
+ def reset ; c 0 ; end
130
+
131
+ # 各色
132
+ def red ; c 31; end
133
+ def green ; c 32; end
134
+
135
+ # カラーシーケンスの出力
136
+ def c(num)
137
+ print "\e[#{num.to_s}m"
138
+ end
139
+ end
140
+ end
141
+
142
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ansible_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - volanja
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.18.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.18.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.3
69
+ description: Ansible Tools e.g. Create directory by BestPractice
70
+ email:
71
+ - volaaanja@gmail.com
72
+ executables:
73
+ - ansible-tools
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - ansible_tools.gemspec
83
+ - bin/ansible-tools
84
+ - lib/ansible_tools.rb
85
+ - lib/ansible_tools/version.rb
86
+ homepage: https://github.com/volanja
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.1.11
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Ansible Tools e.g. Create directory by BestPractice
110
+ test_files: []