itamae 1.0.0.beta32 → 1.0.0.beta33

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e05142ebe2064c8ea35f6ca3f54fe9ce1df6383
4
- data.tar.gz: 292bfe518cb67a305ee08891459ecb5b5f6c0f66
3
+ metadata.gz: c7789de3e2192706f3fbc070c21b4c8655ee069e
4
+ data.tar.gz: 53c079ad48be16240db72583dbd259789f13f18f
5
5
  SHA512:
6
- metadata.gz: 935258ed1e922445a2f7a501739519d5df67177e1351fb897b0959946f65b2c354de75f9c0241ad91a686a649593a2df254de249b3a26a405bd961b5183894a3
7
- data.tar.gz: 9360186a116aea90b32b9bc5d1627c93756a7981b15ca2fdb5031c9ca2d5cb87e4f06e93273edd2c8ba3576571f13e81e76700642b83a198a797d75146663844
6
+ metadata.gz: ebe47750eca4115b24f816d646305df6b61eb370bb0955db711fc0fe522c20f6f72cdfb953d5029d67a8eda8ff367b20e027b39e7d94b9d81f71bab3bf156a97
7
+ data.tar.gz: fe8db93b2450cbd67a3038f482f3773cd8e6a77fd5d20fe2f3bfc983311cae8b612186645cd1b9203ef3642990e4c5ecc9eddfd593e18be33c85b0754bf1f7c7
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Itamae [![Gem Version](https://badge.fury.io/rb/itamae.svg)](http://badge.fury.io/rb/itamae) [![wercker status](https://app.wercker.com/status/d44df82d2f4529ff664f32fa54ce12f5/s/master "wercker status")](https://app.wercker.com/project/bykey/d44df82d2f4529ff664f32fa54ce12f5)
1
+ # Itamae [![Gem Version](https://badge.fury.io/rb/itamae.svg)](http://badge.fury.io/rb/itamae) [![Code Climate](https://codeclimate.com/github/ryotarai/itamae/badges/gpa.svg)](https://codeclimate.com/github/ryotarai/itamae) [![wercker status](https://app.wercker.com/status/d44df82d2f4529ff664f32fa54ce12f5/s/master "wercker status")](https://app.wercker.com/project/bykey/d44df82d2f4529ff664f32fa54ce12f5)
2
2
 
3
3
  Simple and lightweight configuration management tool inspired by Chef.
4
4
 
@@ -54,6 +54,10 @@ end
54
54
 
55
55
  Further example is here: [spec/integration/recipes/default.rb](spec/integration/recipes/default.rb)
56
56
 
57
+ ## Doc
58
+
59
+ https://github.com/ryotarai/itamae/wiki
60
+
57
61
  ## Run tests
58
62
 
59
63
  Requirements: Vagrant
data/itamae.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_runtime_dependency "thor"
21
- spec.add_runtime_dependency "specinfra", "2.0.0.beta41"
21
+ spec.add_runtime_dependency "specinfra", "2.0.0.beta43"
22
22
  spec.add_runtime_dependency "hashie"
23
23
  spec.add_runtime_dependency "ansi"
24
24
 
@@ -60,37 +60,39 @@ module Itamae
60
60
  command = "sudo -u #{Shellwords.escape(user)} -- /bin/sh -c #{Shellwords.escape(command)}"
61
61
  end
62
62
 
63
- Logger.debug " Executing `#{command}`..."
63
+ Logger.debug "Executing `#{command}`..."
64
64
 
65
65
  result = Specinfra::Runner.run_command(command)
66
66
  exit_status = result.exit_status
67
67
 
68
- if exit_status == 0 || !options[:error]
69
- method = :debug
70
- message = " exited with #{exit_status}"
71
- else
72
- method = :error
73
- message = " Command `#{command}` failed. (exit status: #{exit_status})"
74
- end
68
+ Logger.formatter.indent do
69
+ if exit_status == 0 || !options[:error]
70
+ method = :debug
71
+ message = "exited with #{exit_status}"
72
+ else
73
+ method = :error
74
+ message = "Command `#{command}` failed. (exit status: #{exit_status})"
75
+ end
75
76
 
76
- Logger.public_send(method, message)
77
+ Logger.public_send(method, message)
77
78
 
78
- {"stdout" => result.stdout, "stderr" => result.stderr}.each_pair do |name, value|
79
- next unless value && value != ''
79
+ {"stdout" => result.stdout, "stderr" => result.stderr}.each_pair do |name, value|
80
+ next unless value && value != ''
80
81
 
81
- if value.bytesize > 1024 * 1024
82
- Logger.public_send(method, " #{name} is suppressed because it's too large")
83
- next
84
- end
85
-
86
- value.each_line do |line|
87
- # remove control chars
88
- case line.encoding
89
- when Encoding::UTF_8
90
- line = line.tr("\u0000-\u001f\u007f\u2028",'')
82
+ if value.bytesize > 1024 * 1024
83
+ Logger.public_send(method, "#{name} is suppressed because it's too large")
84
+ next
91
85
  end
92
86
 
93
- Logger.public_send(method, " #{name} | #{line}")
87
+ value.each_line do |line|
88
+ # remove control chars
89
+ case line.encoding
90
+ when Encoding::UTF_8
91
+ line = line.tr("\u0000-\u001f\u007f\u2028",'')
92
+ end
93
+
94
+ Logger.public_send(method, "#{name} | #{line}")
95
+ end
94
96
  end
95
97
  end
96
98
 
data/lib/itamae/logger.rb CHANGED
@@ -6,23 +6,33 @@ module Itamae
6
6
  module Logger
7
7
  class Formatter
8
8
  attr_accessor :colored
9
+ attr_accessor :depth
9
10
 
10
- def call(severity, datetime, progname, msg)
11
+ INDENT_LENGTH = 3
11
12
 
12
- severity = if colored
13
- color("%5s" % severity, severity)
14
- else
15
- "%5s" % severity
16
- end
13
+ def initialize(*args)
14
+ super
17
15
 
18
- "[%s] %s : %s\n" % [format_datetime(datetime), severity, msg2str(msg)]
16
+ @depth = 0
19
17
  end
20
18
 
21
- private
22
- def format_datetime(time)
23
- time.strftime("%Y-%m-%dT%H:%M:%S%:z")
19
+ def call(severity, datetime, progname, msg)
20
+ log = "%s : %s%s\n" % ["%5s" % severity, ' ' * INDENT_LENGTH * depth , msg2str(msg)]
21
+ if colored
22
+ color(log, severity)
23
+ else
24
+ log
25
+ end
26
+ end
27
+
28
+ def indent
29
+ @depth += 1
30
+ yield
31
+ ensure
32
+ @depth -= 1
24
33
  end
25
34
 
35
+ private
26
36
  def msg2str(msg)
27
37
  case msg
28
38
  when ::String
@@ -64,6 +74,14 @@ module Itamae
64
74
  def method_missing(method, *args, &block)
65
75
  logger.public_send(method, *args, &block)
66
76
  end
77
+
78
+ def depth
79
+ @depth || 0
80
+ end
81
+
82
+ def depth=(value)
83
+ @depth = value
84
+ end
67
85
  end
68
86
  end
69
87
  end
data/lib/itamae/recipe.rb CHANGED
@@ -25,15 +25,15 @@ module Itamae
25
25
  def run(options = {})
26
26
  Logger.info "Recipe: #{@path}"
27
27
 
28
- @children.run(options)
29
-
30
- @delayed_notifications.uniq do |notification|
31
- [notification.action, notification.action_resource]
32
- end.each do |notification|
33
- notification.run(options)
28
+ Logger.formatter.indent do
29
+ @children.run(options)
30
+
31
+ @delayed_notifications.uniq do |notification|
32
+ [notification.action, notification.action_resource]
33
+ end.each do |notification|
34
+ notification.run(options)
35
+ end
34
36
  end
35
-
36
- Logger.info "< Finished. (#{@path})"
37
37
  end
38
38
 
39
39
  private
@@ -56,7 +56,7 @@ module Itamae
56
56
  target = candidate_paths.find {|path| File.exist?(path) }
57
57
 
58
58
  unless target
59
- raise NotFoundError, "File not found. (#{target})"
59
+ raise NotFoundError, "Recipe not found. (#{recipe})"
60
60
  end
61
61
 
62
62
  if runner.children.find_recipe_by_path(target)
@@ -48,33 +48,36 @@ module Itamae
48
48
  end
49
49
 
50
50
  def run(specific_action = nil, options = {})
51
- Logger.info "Executing #{resource_type} (#{attributes})..."
52
-
53
- if do_not_run_because_of_only_if?
54
- Logger.info "Execution skipped because of only_if attribute"
55
- return
56
- elsif do_not_run_because_of_not_if?
57
- Logger.info "Execution skipped because of not_if attribute"
58
- return
59
- end
51
+ attributes_without_action = attributes.dup.tap {|attr| attr.delete(:action) }
52
+ Logger.info "#{resource_type} (#{attributes_without_action})..."
53
+
54
+ Logger.formatter.indent do
55
+ if do_not_run_because_of_only_if?
56
+ Logger.info "Execution skipped because of only_if attribute"
57
+ return
58
+ elsif do_not_run_because_of_not_if?
59
+ Logger.info "Execution skipped because of not_if attribute"
60
+ return
61
+ end
60
62
 
61
- pre_action
63
+ pre_action
62
64
 
63
- set_current_attributes
64
- show_differences
65
+ set_current_attributes
66
+ show_differences
65
67
 
66
- unless options[:dry_run]
67
- [action].flatten.each do |action|
68
- public_send("#{specific_action || action}_action".to_sym, options)
68
+ unless options[:dry_run]
69
+ [action].flatten.each do |action|
70
+ Logger.info "action: #{action}"
71
+ Logger.formatter.indent do
72
+ public_send("#{specific_action || action}_action".to_sym, options)
73
+ end
74
+ end
69
75
  end
70
- end
71
-
72
- updated! if different?
73
76
 
74
- notify(options) if updated?
77
+ updated! if different?
75
78
 
76
- Logger.info "Succeeded."
77
- Logger.info ''
79
+ notify(options) if updated?
80
+ end
78
81
  rescue Backend::CommandExecutionError
79
82
  Logger.error "Failed."
80
83
  exit 2
@@ -132,11 +135,11 @@ module Itamae
132
135
  if current_value.nil? && value.nil?
133
136
  # ignore
134
137
  elsif current_value.nil? && !value.nil?
135
- Logger.info " #{key} will be '#{value}'"
138
+ Logger.info "#{key} will be '#{value}'"
136
139
  elsif current_value == value || value.nil?
137
- Logger.info " #{key} will not change (current value is '#{current_value}')"
140
+ Logger.debug "#{key} will not change (current value is '#{current_value}')"
138
141
  else
139
- Logger.info " #{key} will change from '#{current_value}' to '#{value}'"
142
+ Logger.info "#{key} will change from '#{current_value}' to '#{value}'"
140
143
  end
141
144
  end
142
145
  end
@@ -162,7 +165,7 @@ module Itamae
162
165
  end
163
166
 
164
167
  def send_file(src, dst)
165
- Logger.debug " Sending a file from '#{src}' to '#{dst}'..."
168
+ Logger.debug "Sending a file from '#{src}' to '#{dst}'..."
166
169
  unless ::File.exist?(src)
167
170
  raise Error, "The file '#{src}' doesn't exist."
168
171
  end
@@ -227,7 +230,7 @@ module Itamae
227
230
 
228
231
  def updated!
229
232
  unless @updated
230
- Logger.debug " This resource is updated."
233
+ Logger.debug "This resource is updated."
231
234
  end
232
235
  @updated = true
233
236
  end
@@ -51,11 +51,11 @@ module Itamae
51
51
  diff = run_command(["diff", "-u", path, @temppath], error: false)
52
52
  if diff.exit_status == 0
53
53
  # no change
54
- Logger.info " file content will not change"
54
+ Logger.debug "file content will not change"
55
55
  else
56
- Logger.info " diff:"
56
+ Logger.info "diff:"
57
57
  diff.stdout.each_line do |line|
58
- Logger.info " #{line.strip}"
58
+ Logger.info "#{line.strip}"
59
59
  end
60
60
  end
61
61
  end
@@ -78,8 +78,7 @@ module Itamae
78
78
 
79
79
  def delete_action(options)
80
80
  if run_specinfra(:check_file_is_file, path)
81
- # TODO: delegate to Specinfra
82
- run_command(["rm", path])
81
+ run_specinfra(:remove_file, path)
83
82
  end
84
83
  end
85
84
  end
@@ -15,10 +15,10 @@ module Itamae
15
15
  end
16
16
 
17
17
  def set_current_attributes
18
- @current_attributes[:exist?] = (run_command(["test", "-L", link], error: false).exit_status == 0)
18
+ @current_attributes[:exist?] = run_specinfra(:check_file_is_link, link)
19
19
 
20
20
  if @current_attributes[:exist?]
21
- @current_attributes[:to] = run_command(["readlink", "-f", link]).stdout.strip
21
+ @current_attributes[:to] = run_specinfra(:get_file_link_target, link).stdout.strip
22
22
  end
23
23
  end
24
24
 
@@ -15,10 +15,9 @@ module Itamae
15
15
  @current_attributes[:exist?] = exist?
16
16
 
17
17
  if @current_attributes[:exist?]
18
- # TODO: delegate to Specinfra
19
- @current_attributes[:uid] = run_command(["id", "-u", username]).stdout.strip
20
- @current_attributes[:gid] = run_command(["id", "-g", username]).stdout.strip
21
- @current_attributes[:home] = run_command("echo ~#{shell_escape(username)}").stdout.strip
18
+ @current_attributes[:uid] = run_specinfra(:get_user_uid, username).stdout.strip
19
+ @current_attributes[:gid] = run_specinfra(:get_user_gid, username).stdout.strip
20
+ @current_attributes[:home] = run_specinfra(:get_user_home_directory, username).stdout.strip
22
21
  @current_attributes[:password] = current_password
23
22
  end
24
23
  end
@@ -26,32 +25,29 @@ module Itamae
26
25
  def create_action(options)
27
26
  if run_specinfra(:check_user_exists, username)
28
27
  if uid && uid.to_s != @current_attributes[:uid]
29
- # TODO: delegate to Specinfra
30
- run_command(["usermod", "-u", uid, username])
28
+ run_specinfra(:update_user_uid, username, uid)
31
29
  updated!
32
30
  end
33
31
 
34
32
  if gid && gid.to_s != @current_attributes[:gid]
35
- # TODO: delegate to Specinfra
36
- run_command(["usermod", "-g", gid, username])
33
+ run_specinfra(:update_user_gid, username, gid)
37
34
  updated!
38
35
  end
39
36
 
40
37
  if password && password != current_password
41
- # TODO: delegate to Specinfra
42
- run_command("echo #{shell_escape("#{username}:#{password}")} | chpasswd -e")
38
+ run_specinfra(:update_user_encrypted_password, username, password)
43
39
  updated!
44
40
  end
45
41
  else
46
- # TODO: delegate to Specinfra
47
- args = ["useradd"]
48
- args << "-g" << gid if gid
49
- args << "-d" << home if home
50
- args << "-p" << password if password
51
- args << "-r" if system_user
52
- args << "-u" << uid.to_s if uid
53
- args << username
54
- run_command(args)
42
+ options = {
43
+ gid: gid,
44
+ home_directory: home,
45
+ password: password,
46
+ system_user: system_user,
47
+ uid: uid,
48
+ }
49
+
50
+ run_specinfra(:add_user, username, options)
55
51
 
56
52
  updated!
57
53
  end
@@ -63,11 +59,9 @@ module Itamae
63
59
  end
64
60
 
65
61
  def current_password
66
- # TODO: delegate to Specinfra
67
- result = run_command("cat /etc/shadow | grep -E ^#{shell_escape(username)}:", error: false)
68
-
69
- if result.exit_status == 0
70
- result.stdout.split(":")[1]
62
+ result = run_specinfra(:get_user_encrypted_password, username)
63
+ if result.success?
64
+ result.stdout.strip
71
65
  else
72
66
  nil
73
67
  end
@@ -1 +1 @@
1
- 1.0.0.beta32
1
+ 1.0.0.beta33
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta32
4
+ version: 1.0.0.beta33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2014-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.0.beta41
33
+ version: 2.0.0.beta43
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.0.beta41
40
+ version: 2.0.0.beta43
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hashie
43
43
  requirement: !ruby/object:Gem::Requirement