chef-handler-motd 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'chef-handler-motd'
3
- s.version = '0.2.0'
3
+ s.version = '0.3.0'
4
4
  s.author = 'Simple Finance'
5
5
  s.email = 'ops@simple.com'
6
6
  s.homepage = 'http://github.com/SimpleFinance/chef-handler-motd'
@@ -30,7 +30,22 @@ class ChefMOTD < Chef::Handler
30
30
  @priority = options[:priority]
31
31
  end
32
32
 
33
- def report
33
+ def delete_outdated
34
+ Dir.entries('/etc/update-motd.d').select do |entry|
35
+ /chef-motd/.match entry && !/^#{@priority}/.match entry
36
+ end.each do |del|
37
+ Chef::Log.warn "Deleting #{del} as it does not match the current ChefMOTD priority"
38
+ FileUtils.rm ::File.join('/etc', 'update-motd.d', del)
39
+ end
40
+ end
41
+
42
+ def write_out(msg)
43
+ file = "/etc/update-motd.d/#{@priority}-chef-motd"
44
+ ::File.open(file, 'w') {|f| f.puts msg}
45
+ ::File.chmod(0755, file)
46
+ end
47
+
48
+ def generate_message
34
49
  msg = <<-eos
35
50
  #!/bin/sh
36
51
  echo \"Node #{node.name} last success at #{Time.now.to_s} in #{run_status.elapsed_time} seconds\"
@@ -39,11 +54,14 @@ echo \"Updated resources on last run (total: #{run_status.updated_resources.leng
39
54
  run_status.updated_resources.each do |res|
40
55
  msg += "echo \" #{res.resource_name}[#{res.name}]\"\n"
41
56
  end
57
+ return msg
58
+ end
59
+
60
+ def report
42
61
  if run_status.success?
43
62
  Chef::Log.info 'Updating Chef info in MOTD ...'
44
- file = "/etc/update-motd.d/#{@priority}-chef-motd"
45
- ::File.open(file, 'w') {|f| f.puts msg}
46
- ::File.chmod(0755, file)
63
+ delete_outdated
64
+ write_out(generate_message)
47
65
  end
48
66
  end
49
67
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-handler-motd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
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: 2013-05-14 00:00:00.000000000 Z
12
+ date: 2013-05-16 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Edits MOTD at the end of a Chef run
15
15
  email: ops@simple.com
@@ -17,7 +17,6 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - chef-handler-motd-0.1.2.gem
21
20
  - chef-handler-motd.gemspec
22
21
  - lib/chef-handler-motd.rb
23
22
  - LICENSE
Binary file