pupcap 0.0.5 → 0.1.0

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.
@@ -1,14 +1,14 @@
1
1
  require 'pupcap/action'
2
2
  require 'pupcap/command'
3
3
 
4
- class Pupcap::Action::Cook < Pupcap::Action::Base
4
+ class Pupcap::Action::Apply < Pupcap::Action::Base
5
5
  def initialize
6
6
  check_puppetfile!
7
7
  end
8
8
 
9
9
  def start
10
10
  cap = create_cap_for(parsed_options[:file])
11
- cap_load_and_run_task(cap, "cook")
11
+ cap_load_and_run_task(cap, "apply")
12
12
  end
13
13
 
14
14
  def parsed_options
@@ -42,7 +42,7 @@ class Pupcap::Action::Cook < Pupcap::Action::Base
42
42
 
43
43
  def default_options
44
44
  {
45
- :file => File.expand_path("Puppetfile"),
45
+ :file => File.expand_path("Capfile"),
46
46
  :debug => false,
47
47
  :noop => false
48
48
  }
@@ -0,0 +1,35 @@
1
+ require 'erb'
2
+
3
+ namespace :apply do
4
+ task :default do
5
+ rsync
6
+ puppet
7
+ cleanup
8
+ end
9
+
10
+ task :rsync do
11
+ from = "#{local_root}/puppet"
12
+ to = deploy_to
13
+ upload(from, to, :recursive => true, :via => :scp)
14
+ end
15
+
16
+ task :puppet do
17
+ remote_command = "#{deploy_to}/apply.sh"
18
+
19
+ puppet = "/usr/local/bin/puppet"
20
+ modules = "--modulepath=#{deploy_to}/modules:#{deploy_to}/site-modules"
21
+ nook = pupcap_options[:noop] ? " --noop" : ""
22
+ debug = pupcap_options[:debug] ? " --debug --verbose" : ""
23
+
24
+ erb = ERB.new(File.read("#{pupcap_root}/action/apply/puppet.sh.erb"))
25
+ rs = erb.result(binding)
26
+
27
+ put(rs, remote_command)
28
+ run("chmod +x #{remote_command}")
29
+ sudo("#{remote_command} \"$CAPISTRANO:HOSTROLES$\"")
30
+ end
31
+
32
+ task :cleanup do
33
+ run("rm -rf #{deploy_to}")
34
+ end
35
+ end
@@ -2,7 +2,7 @@ set -e
2
2
 
3
3
  for role in $(echo "${1}" | tr "," "\n")
4
4
  do
5
- echo "*** ${role} ***"
5
+ echo "*** Role: ${role} ***"
6
6
  <%= puppet %> apply <%= nook + debug %> --detailed-exitcodes <%= modules %> <%= deploy_to %>/manifests/${role}.pp || true
7
7
  done
8
8
 
@@ -10,8 +10,10 @@ class Pupcap::Action::Init < Pupcap::Action::Base
10
10
  def start
11
11
  create_directories
12
12
  create_vagrantfile
13
- create_puppetfile
13
+ create_capfile
14
14
  create_pp
15
+ librarian_puppet
16
+ create_gitignore
15
17
  end
16
18
 
17
19
  def create_vagrantfile
@@ -20,38 +22,52 @@ class Pupcap::Action::Init < Pupcap::Action::Base
20
22
  erb = ERB.new(File.read("#{lib_root}/init/Vagrantfile.erb"))
21
23
  rs = erb.result(binding)
22
24
  File.open(out, "w+"){ |io| io.write rs }
25
+ puts "\t create Vagrantfile"
23
26
  else
24
- puts "Skip file #{out}"
27
+ puts "\t skip #{out}"
25
28
  end
26
29
  end
27
30
 
28
- def create_puppetfile
29
- out = "#{work_dir}/Puppetfile"
31
+ def create_capfile
32
+ out = "#{work_dir}/Capfile"
30
33
  if !File.exists?(out) || force?
31
- erb = ERB.new(File.read("#{lib_root}/init/Puppetfile.erb"))
34
+ erb = ERB.new(File.read("#{lib_root}/init/Capfile.erb"))
32
35
  rs = erb.result(binding)
33
36
  File.open(out, "w+"){ |io| io.write rs }
37
+ puts "\t create Capfile"
34
38
  else
35
- puts "Skip file #{out}"
39
+ puts "\t skip #{out}"
36
40
  end
37
41
  end
38
42
 
39
43
  def create_pp
40
- out = "#{work_dir}/puppet/manifests/default.pp"
44
+ out = "#{work_dir}/puppet/manifests/site.pp"
41
45
  if !File.exists?(out) || force?
42
- erb = ERB.new(File.read("#{lib_root}/init/default.pp.erb"))
46
+ erb = ERB.new(File.read("#{lib_root}/init/site.pp.erb"))
43
47
  rs = erb.result(binding)
44
48
  File.open(out, "w+"){ |io| io.write rs }
49
+ puts "\t create puppet/manifests/site.pp"
45
50
  else
46
- puts "Skip file #{out}"
51
+ puts "\t skip #{out}"
47
52
  end
48
53
  end
49
54
 
50
55
  def create_directories
51
56
  FileUtils.mkdir_p("#{work_dir}/puppet/modules")
57
+ FileUtils.mkdir_p("#{work_dir}/puppet/site-modules")
52
58
  FileUtils.mkdir_p("#{work_dir}/puppet/manifests")
53
- system("touch #{work_dir}/puppet/modules/.gitkeep")
54
59
  system("touch #{work_dir}/puppet/manifests/.gitkeep")
60
+ system("touch #{work_dir}/puppet/site-modules/.gitkeep")
61
+ end
62
+
63
+ def librarian_puppet
64
+ Pupcap::Command.run_local("(cd #{work_dir}/puppet && librarian-puppet init)")
65
+ end
66
+
67
+ def create_gitignore
68
+ unless File.exists?("#{work_dir}.gitignore")
69
+ FileUtils.copy("#{lib_root}/init/gitignore", "#{work_dir}/.gitignore")
70
+ end
55
71
  end
56
72
 
57
73
  def work_dir
@@ -0,0 +1,3 @@
1
+ task :vagrant do
2
+ role :site, "<%= ip %>", :user => "vagrant", :port => 22
3
+ end
@@ -0,0 +1,2 @@
1
+ .vagrant
2
+ *.swp
@@ -0,0 +1,9 @@
1
+ require 'pupcap/action/apply'
2
+
3
+ class Pupcap::Action::Noop < Pupcap::Action::Apply
4
+ def start
5
+ cap = create_cap_for(parsed_options[:file])
6
+ cap.pupcap_options[:noop] = true
7
+ cap_load_and_run_task(cap, "apply")
8
+ end
9
+ end
@@ -46,7 +46,7 @@ class Pupcap::Action::Prepare < Pupcap::Action::Base
46
46
 
47
47
  def default_options
48
48
  {
49
- :file => File.expand_path("Puppetfile"),
49
+ :file => File.expand_path("Capfile"),
50
50
  :force => false,
51
51
  :upgrade => false
52
52
  }
@@ -6,9 +6,10 @@ then
6
6
  exit 0
7
7
  fi
8
8
 
9
- if test ! -e /root/.pupcap_prepare_locale_ok -o "x${PUPCAP_FORCE}" = "x1"
9
+ CURRENT_LANG=`locale | awk '/LANG=/{ split($1, a, "=") ; print a[2] }'`
10
+ if test "x${CURRENT_LANG}" != "xen_US.UTF-8"
10
11
  then
11
- locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8 && touch /root/pupcap_prepare_locale_ok
12
+ locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8
12
13
  fi
13
14
 
14
15
  if test -n "${PUPCAP_HOSTNAME}"
@@ -21,7 +22,7 @@ SOURCES_LIST=/etc/apt/sources.list
21
22
 
22
23
  SOURCES_LIST_MD5=`md5sum ${SOURCES_LIST} | awk '{ print $1 }'`
23
24
 
24
- if test "$SOURCES_LIST_MD5" != "14846cd43a3ef58b204b0807fa4856f8" -o "x${PUPCAP_FORCE}" = "x1"
25
+ if test "$SOURCES_LIST_MD5" != "14846cd43a3ef58b204b0807fa4856f8"
25
26
  then
26
27
 
27
28
  cp -f ${SOURCES_LIST} ${SOURCES_LIST}.pupcap_back
@@ -52,6 +53,8 @@ apt-get install -qy rsync wget rubygems vim git-core build-essential > /dev/null
52
53
  apt-get -qy clean
53
54
 
54
55
  /usr/bin/gem install -q --no-ri --no-rdoc --version '~> 2.7.1' puppet
56
+ /usr/bin/gem install -q --no-ri --no-rdoc librarian-puppet
57
+
55
58
  /usr/sbin/groupadd -f puppet
56
59
 
57
60
  touch /root/.pupcap_prepare_ok
@@ -34,7 +34,7 @@ class Pupcap::Action::Ssh < Pupcap::Action::Base
34
34
 
35
35
  def default_options
36
36
  {
37
- :file => File.expand_path("Puppetfile"),
37
+ :file => File.expand_path("Capfile"),
38
38
  }
39
39
  end
40
40
  end
@@ -17,7 +17,7 @@ class Pupcap::CLI
17
17
  end
18
18
 
19
19
  def valid_actions
20
- %w{ prepare cook ssh init }
20
+ %w{ prepare apply ssh init noop }
21
21
  end
22
22
  end
23
23
  end
@@ -4,8 +4,8 @@ module Pupcap
4
4
  class Version
5
5
 
6
6
  MAJOR = 0
7
- MINOR = 0
8
- PATCH = 5
7
+ MINOR = 1
8
+ PATCH = 0
9
9
 
10
10
  def self.to_s
11
11
  "#{MAJOR}.#{MINOR}.#{PATCH}"
@@ -22,12 +22,15 @@ Gem::Specification.new do |s|
22
22
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
23
23
  s.add_runtime_dependency(%q<capistrano>, [">= 2.12.0"])
24
24
  s.add_runtime_dependency(%q<vagrant>, [">= 1.0.0"])
25
+ s.add_runtime_dependency(%q<librarian-puppet>, [">= 0.9.7"])
25
26
  else
26
27
  s.add_dependency(%q<capistrano>, [">= 2.12.0"])
27
28
  s.add_dependency(%q<vagrant>, [">= 1.0.0"])
29
+ s.add_dependency(%q<librarian-puppet>, [">= 0.9.7"])
28
30
  end
29
31
  else
30
32
  s.add_dependency(%q<capistrano>, [">= 2.12.0"])
31
33
  s.add_dependency(%q<vagrant>, [">= 1.0.0"])
34
+ s.add_dependency(%q<librarian-puppet>, [">= 0.9.7"])
32
35
  end
33
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pupcap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 1.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: librarian-puppet
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.7
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.7
46
62
  description: under development description
47
63
  email:
48
64
  - dima.exe@gmail.com
@@ -58,13 +74,15 @@ files:
58
74
  - bin/pupcap
59
75
  - lib/pupcap.rb
60
76
  - lib/pupcap/action.rb
61
- - lib/pupcap/action/cook.rb
62
- - lib/pupcap/action/cook/Capfile
63
- - lib/pupcap/action/cook/apply.sh.erb
77
+ - lib/pupcap/action/apply.rb
78
+ - lib/pupcap/action/apply/Capfile
79
+ - lib/pupcap/action/apply/puppet.sh.erb
64
80
  - lib/pupcap/action/init.rb
65
- - lib/pupcap/action/init/Puppetfile.erb
81
+ - lib/pupcap/action/init/Capfile.erb
66
82
  - lib/pupcap/action/init/Vagrantfile.erb
67
- - lib/pupcap/action/init/default.pp.erb
83
+ - lib/pupcap/action/init/gitignore
84
+ - lib/pupcap/action/init/site.pp.erb
85
+ - lib/pupcap/action/noop.rb
68
86
  - lib/pupcap/action/prepare.rb
69
87
  - lib/pupcap/action/prepare/Capfile
70
88
  - lib/pupcap/action/prepare/ubuntu/precise.sh
@@ -1,41 +0,0 @@
1
- require 'erb'
2
-
3
- namespace :cook do
4
- task :default do
5
- rsync
6
- apply
7
- cleanup
8
- end
9
-
10
- task :rsync do
11
- find_servers.each do |server|
12
- port = Pupcap::Command.server_port(self, server)
13
- host = Pupcap::Command.server_host(self, server)
14
- ssh_cmd = "-e \"ssh -p #{port} -i #{provision_key}\""
15
- rsync_options = "-p --chmod=o+r,g+r -az"
16
- cmd = "rsync #{rsync_options} #{ssh_cmd} #{local_root}/puppet/ #{host}:#{deploy_to}"
17
- logger.important(cmd)
18
- system(cmd)
19
- end
20
- end
21
-
22
- task :apply do
23
- remote_command = "#{deploy_to}/apply.sh"
24
-
25
- puppet = "/usr/local/bin/puppet"
26
- modules = "--modulepath=#{deploy_to}/modules:#{deploy_to}/manifests"
27
- nook = pupcap_options[:noop] ? " --noop" : ""
28
- debug = pupcap_options[:debug] ? " --debug --verbose" : ""
29
-
30
- erb = ERB.new(File.read("#{pupcap_root}/action/cook/apply.sh.erb"))
31
- rs = erb.result(binding)
32
-
33
- put(rs, remote_command)
34
- run("chmod +x #{remote_command}")
35
- sudo("#{remote_command} \"$CAPISTRANO:HOSTROLES$\"")
36
- end
37
-
38
- task :cleanup do
39
- run("rm -rf #{deploy_to}")
40
- end
41
- end
@@ -1,3 +0,0 @@
1
- task :vagrant do
2
- role :vagrant, "<%= ip %>", :user => "vagrant", :port => 22
3
- end