chake 0.1.7 → 0.2

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: 161b45c39f5a14fae37e455294898846f33693f0
4
- data.tar.gz: 0fe53375064b3db380f0de958fb047ccf6c7d8ba
3
+ metadata.gz: 4dab95473935a70ac4191737d2f0e5fe7cb81cac
4
+ data.tar.gz: ab453a86e896472cb44d6f7cdc5ff5035d4925d9
5
5
  SHA512:
6
- metadata.gz: 14163774c1180ba81b142d9f5575e21817481e9e02cbe411078ac8e52bd471cb0781bd4872c45235d7bc54b3b13ea6dfe1bdfdf63650f81694a75c4932578d00
7
- data.tar.gz: 3d9eabbc50376c907114317e9d8ba82fd2bda2006710f227f00178187e920fde0137181e6c8eaacf9468bf9c72ea4a010f4516093be93c31ed4945f16a674769
6
+ metadata.gz: 1c4287d875ac6220db86d879ae7997392918b90fdd830b6d637f296a9901e5006d168a5d62e995def7fb8a5ea5fa6849b0fac13b194d76c011374858e0dc4c82
7
+ data.tar.gz: 9b4259782db5b68c8c3cb17671893d6bbc1f4d151af6f0345a8f4cb890e1cea07cfda342c6480294ddcefb06198e4dddbde86d34cef63b3480b462a9f44687c5
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rake'
4
+
5
+ rakefiles = %w[rakefile Rakefile rakefile.rb Rakefile.rb]
6
+
7
+ if (!rakefiles.any? { |f| File.exist?(f) }) && !ARGV.include?('-f') && !ARGV.include?('--rakefile')
8
+ require 'tmpdir'
9
+ require 'fileutils'
10
+
11
+ # syntethize a Rakefile
12
+ tmpdir = Dir.mktmpdir
13
+ rakefile = File.join(tmpdir, 'Rakefile')
14
+ File.open(rakefile, 'w') do |f|
15
+ f.puts 'require "chake"'
16
+ end
17
+ ARGV.unshift << '--rakefile' << rakefile
18
+
19
+ # clenup after finishing
20
+ at_exit do
21
+ FileUtils.rm_rf tmpdir
22
+ end
23
+ end
24
+
25
+ Rake.application.run
@@ -14,7 +14,9 @@ $nodes = node_data.map { |node,data| Chake::Node.new(node, data) }.reject(&:skip
14
14
 
15
15
  desc "Initializes current directory with sample structure"
16
16
  task :init do
17
- if !File.exists?('nodes.yaml')
17
+ if File.exists?('nodes.yaml')
18
+ puts '[exists] nodes.yaml'
19
+ else
18
20
  File.open('nodes.yaml', 'w') do |f|
19
21
  sample_nodes = <<EOF
20
22
  host1.my.tld:
@@ -22,27 +24,46 @@ host1.my.tld:
22
24
  - recipe[myhost]
23
25
  EOF
24
26
  f.write(sample_nodes)
25
- puts " nodes.yaml"
27
+ puts "[create] nodes.yaml"
26
28
  end
27
29
  end
28
- if !File.exists?('config.rb')
30
+ if File.exists?('config.rb')
31
+ puts '[exists] config.rb'
32
+ else
29
33
  File.open('config.rb', 'w') do |f|
30
34
  f.puts "root = File.expand_path(File.dirname(__FILE__))"
31
35
  f.puts "file_cache_path root + '/cache'"
32
36
  f.puts "cookbook_path root + '/cookbooks'"
33
37
  f.puts "role_path root + '/config/roles'"
34
38
  end
35
- puts " config.rb"
39
+ puts "[create] config.rb"
40
+ end
41
+
42
+ if !File.exist?('config/roles')
43
+ FileUtils.mkdir_p 'config/roles'
44
+ puts '[ mkdir] config/roles'
45
+ end
46
+ if !File.exist?('cookbooks/myhost/recipes')
47
+ FileUtils.mkdir_p 'cookbooks/myhost/recipes/'
48
+ puts '[ mkdir] cookbooks/myhost/recipes/'
36
49
  end
37
- mkdir_p 'config/roles'
38
- mkdir_p 'cookbooks/myhost/recipes/'
39
50
  recipe = 'cookbooks/myhost/recipes/default.rb'
40
- if !File.exists?(recipe)
51
+ if File.exists?(recipe)
52
+ puts "[exists] #{recipe}"
53
+ else
41
54
  File.open(recipe, 'w') do |f|
42
55
  f.puts "package 'openssh-server'"
43
56
  end
44
- puts " #{recipe}"
57
+ puts "[create] #{recipe}"
58
+ end
59
+ if File.exists?('Rakefile')
60
+ puts '[exists] Rakefile'
61
+ else
62
+ File.open('Rakefile', 'w') do |f|
63
+ f.puts 'require "chake"'
64
+ puts '[create] Rakefile'
45
65
  end
66
+ end
46
67
  end
47
68
 
48
69
  desc 'list nodes'
@@ -73,31 +94,52 @@ def if_files_changed(node, group_name, files)
73
94
  end
74
95
  end
75
96
 
97
+
98
+ def write_json_file(file, data)
99
+ File.open(file, 'w') do |f|
100
+ f.write(JSON.dump(data))
101
+ f.write("\n")
102
+ end
103
+ end
104
+
105
+ platforms = Dir.glob(File.expand_path('chake/bootstrap/*.sh', File.dirname(__FILE__))).sort
106
+ bootstrap_script = '.tmp/bootstrap'
107
+
76
108
  $nodes.each do |node|
77
109
 
78
110
  hostname = node.hostname
79
111
 
112
+ file bootstrap_script => platforms do |t|
113
+ mkdir_p(File.dirname(bootstrap_script))
114
+ File.open(t.name, 'w') do |f|
115
+ f.puts '#!/bin/sh'
116
+ f.puts 'set -eu'
117
+ platforms.each do |platform|
118
+ f.puts(File.read(platform))
119
+ end
120
+ end
121
+ chmod 0755, t.name
122
+ end
123
+
80
124
  desc "bootstrap #{hostname}"
81
- task "bootstrap:#{hostname}" do
125
+ task "bootstrap:#{hostname}" => bootstrap_script do
82
126
  mkdir_p '.tmp', :verbose => false
83
127
  config = '.tmp/' + hostname + '.json'
84
128
 
85
- seen_before = File.exists?(config)
129
+ if File.exists?(config)
130
+ # already bootstrapped, just overwrite
131
+ write_json_file(config, node.data)
132
+ else
133
+ # copy bootstrap script over
134
+ scp = node.scp
135
+ target = "/tmp/.chake-bootstrap.#{Etc.getpwuid.name}"
136
+ sh *scp, bootstrap_script, node.scp_dest + target
86
137
 
87
- # overwrite config with current contents
88
- File.open(config, 'w') do |f|
89
- json_data = node.data
90
- f.write(JSON.dump(json_data))
91
- f.write("\n")
92
- end
138
+ # run bootstrap script
139
+ node.run_as_root(target)
93
140
 
94
- unless seen_before
95
- begin
96
- node.run_as_root('apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -q -y install rsync chef && update-rc.d chef-client disable && service chef-client stop')
97
- rescue
98
- rm_f config
99
- raise
100
- end
141
+ # overwrite config with current contents
142
+ write_json_file(config, node.data)
101
143
  end
102
144
 
103
145
  end
@@ -107,7 +149,7 @@ $nodes.each do |node|
107
149
  encrypted = encrypted_for(hostname)
108
150
  rsync_excludes = (encrypted.values + encrypted.keys).map { |f| ["--exclude", f] }.flatten
109
151
 
110
- rsync = "rsync", "-avp", "--exclude", ".git/"
152
+ rsync = node.rsync + ["-avp", "--exclude", ".git/"]
111
153
  rsync_logging = Rake.application.options.silent && '--quiet' || '--verbose'
112
154
 
113
155
  files = Dir.glob("**/*").select { |f| !File.directory?(f) } - encrypted.keys - encrypted.values
@@ -2,6 +2,21 @@ module Chake
2
2
 
3
3
  class Backend < Struct.new(:node)
4
4
 
5
+ class CommandFailed < Exception
6
+ end
7
+
8
+ def scp
9
+ ['scp']
10
+ end
11
+
12
+ def scp_dest
13
+ ''
14
+ end
15
+
16
+ def rsync
17
+ ['rsync']
18
+ end
19
+
5
20
  def rsync_dest
6
21
  node.path + '/'
7
22
  end
@@ -16,7 +31,7 @@ module Chake
16
31
  if $?
17
32
  status = $?.exitstatus
18
33
  if status != 0
19
- puts [node.hostname, 'FAILED with exit status %d' % status].join(': ')
34
+ raise CommandFailed.new([node.hostname, 'FAILED with exit status %d' % status].join(': '))
20
35
  end
21
36
  end
22
37
  end
@@ -4,16 +4,36 @@ module Chake
4
4
 
5
5
  class Ssh < Backend
6
6
 
7
+ def scp
8
+ ['scp', ssh_config].flatten.compact
9
+ end
10
+
11
+ def scp_dest
12
+ ssh_target + ':'
13
+ end
14
+
15
+ def rsync
16
+ ['rsync', rsync_ssh].flatten.compact
17
+ end
18
+
7
19
  def rsync_dest
8
20
  [ssh_target, node.path + '/'].join(':')
9
21
  end
10
22
 
11
23
  def command_runner
12
- ['ssh', ssh_target]
24
+ ['ssh', ssh_config, ssh_target].flatten.compact
13
25
  end
14
26
 
15
27
  private
16
28
 
29
+ def rsync_ssh
30
+ File.exist?('.ssh_config') && ['-e', 'ssh -F .ssh_config'] || []
31
+ end
32
+
33
+ def ssh_config
34
+ File.exist?('.ssh_config') && ['-F' '.ssh_config'] || []
35
+ end
36
+
17
37
  def ssh_target
18
38
  [node.username, node.hostname].compact.join('@')
19
39
  end
@@ -0,0 +1,81 @@
1
+ if [ -f /etc/centos-release ] && grep -q 'CentOS Linux release 7' /etc/centos-release; then
2
+ cat > /etc/yum.repos.d/chef.key <<EOF
3
+ -----BEGIN PGP PUBLIC KEY BLOCK-----
4
+ Version: GnuPG v1.4.11 (GNU/Linux)
5
+
6
+ mQINBFLUbogBEADceEoxBDoE6QM5xV/13qiELbFIkQgy/eEi3UesXmJblFdU7wcD
7
+ LOW3NuOIx/dgbZljeMEerj6N1cR7r7X5sVoFVEZiK4RLkC3Cpdns0d90ud2f3VyK
8
+ K7PXRBstdLm3JlW9OWZoe4VSADSMGWm1mIhT601qLKKAuWJoBIhnKY/RhA/RBXt7
9
+ z22g4ta9bT67PlliTo1a8y6DhUA7gd+5TsVHaxDRrzc3mKObdyS5LOT/gf8Ti2tY
10
+ BY5MBbQ8NUGExls4dXKlieePhKutFbde7sq3n5sdp1Ndoran1u0LsWnaSDx11R3x
11
+ iYfXJ6xGukAc6pYlUD1yYjU4oRGhD2fPyuewqhHNUVwqupTBQtEGULrtdwK04kgI
12
+ H93ssGRsLqUKe88uZeeBczVuupv8ZLd1YcQ29AfJHe6nsevsgjF+eajYlzsvC8BN
13
+ q3nOvvedcuI6BW4WWFjraH06GNTyMAZi0HibTg65guZXpLcpPW9hTzXMoUrZz8Mv
14
+ J9yUBcFPKuFOLDpRP6uaIbxJsYqiituoltl0vgS/vJcpIVVRwSaqPHa6S63dmKm2
15
+ 6gq18v4l05mVcInPn+ciHtcSlZgQkCsRTSvfUrK+7nzyWtNQMGKstAZ7AHCoA8Pb
16
+ c3i7wyOtnTgfPFHVpHg3JHsPXKk9/71YogtoNFoETMFeKL1K+O+GMQddYQARAQAB
17
+ tDdwYWNrYWdlY2xvdWQgb3BzIChwcm9kdWN0aW9uIGtleSkgP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+ sA==
65
+ =H60S
66
+ -----END PGP PUBLIC KEY BLOCK-----
67
+ EOF
68
+ cat > /etc/yum.repos.d/chef.repo <<EOF
69
+ [chef_stable]
70
+ name=chef_stable
71
+ baseurl=https://packagecloud.io/chef/stable/el/7/\$basearch
72
+ repo_gpgcheck=1
73
+ gpgcheck=0
74
+ enabled=1
75
+ gpgkey=file:///etc/yum.repos.d/chef.key
76
+ sslverify=1
77
+ sslcacert=/etc/pki/tls/certs/ca-bundle.crt
78
+ EOF
79
+ yum install -y chef rsync
80
+ exit
81
+ fi
@@ -0,0 +1,7 @@
1
+ if [ -x /usr/bin/apt-get ]; then
2
+ apt-get update
3
+ export DEBIAN_FRONTEND=noninteractive apt-get -q -y install rsync chef
4
+ update-rc.d chef-client disable
5
+ service chef-client stop
6
+ exit
7
+ fi
@@ -0,0 +1,11 @@
1
+ echo "---------------------"
2
+ echo "Unsupported platform:"
3
+ echo "---------------------"
4
+ echo
5
+ for file in /etc/os-release /etc/issue; do
6
+ if [ -f $file ]; then
7
+ cat $file
8
+ break
9
+ fi
10
+ done
11
+ exit 1
@@ -36,7 +36,7 @@ module Chake
36
36
  @backend ||= Chake::Backend.get(@backend_name).new(self)
37
37
  end
38
38
 
39
- def_delegators :backend, :run, :run_as_root, :rsync_dest, :skip?
39
+ def_delegators :backend, :run, :run_as_root, :rsync, :rsync_dest, :scp, :scp_dest, :skip?
40
40
 
41
41
  end
42
42
 
@@ -1,3 +1,3 @@
1
1
  module Chake
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio Terceiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-25 00:00:00.000000000 Z
11
+ date: 2015-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,7 +57,8 @@ description: chake provides a set of rake tasks that you can use to manage any n
57
57
  from where you can SSH into all your hosts.
58
58
  email:
59
59
  - terceiro@softwarelivre.org
60
- executables: []
60
+ executables:
61
+ - chake
61
62
  extensions: []
62
63
  extra_rdoc_files: []
63
64
  files:
@@ -66,6 +67,7 @@ files:
66
67
  - LICENSE.txt
67
68
  - README.md
68
69
  - Rakefile
70
+ - bin/chake
69
71
  - chake.gemspec
70
72
  - examples/test/Rakefile
71
73
  - examples/test/config.rb
@@ -75,6 +77,9 @@ files:
75
77
  - lib/chake/backend.rb
76
78
  - lib/chake/backend/local.rb
77
79
  - lib/chake/backend/ssh.rb
80
+ - lib/chake/bootstrap/00_centos7.sh
81
+ - lib/chake/bootstrap/00_debian.sh
82
+ - lib/chake/bootstrap/99_unsupported.sh
78
83
  - lib/chake/node.rb
79
84
  - lib/chake/version.rb
80
85
  - spec/chake/backend/local_spec.rb