malkovich 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +182 -0
- data/Rakefile +1 -0
- data/lib/malkovich/capistrano/defaults.rb +31 -0
- data/lib/malkovich/capistrano/fact.rb +14 -0
- data/lib/malkovich/capistrano/puppet.rb +11 -0
- data/lib/malkovich/capistrano/tasks.rb +59 -0
- data/lib/malkovich/capistrano/version.rb +5 -0
- data/lib/malkovich/capistrano.rb +9 -0
- data/malkovich.gemspec +25 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZGFkODJhNTU0NzQ5ZjJhOWRmNWJhZjAyM2MxZWMxYzUxMTgzNmI5NQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZGRmYzIyZTM0ZGI0ZDYzNDQ0MTA4YjMyMzczZGNmNmQ0YjdiNzVjOA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTE0NzZhMzc5YjViOTgwODRjYjk0NWM2NzI2ZTNhYmM5ODc1ZDQ4MDE4YmQz
|
10
|
+
MDhmZTE3NDgxYmMxODkwMDZkOTRlMDEzM2ZhYmUzZGFkNWJlMDNhMDhlMTNl
|
11
|
+
OTYwOWI2ZGI2MjIxN2I0YjJiZTZiNDkxODA3ZmViZTJjZjkwMTY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Y2Y2NTUzYTdiNGVmOTI3NzU2Yzg1ODBiNzQ0MzhkNjAwNWZlMTM2M2IwM2Ji
|
14
|
+
M2Q3NWE4Y2FhMWJmMmRiY2U1OWVhMzBkOGQ4MmFjNmZkMWJjZWEzNDI1MjJj
|
15
|
+
ZTJlNzM4NjdlODk1ZGJmM2IyMGY3YzczZTY0MGFjNzI4ZTQyNzc=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Steve Masterman
|
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,182 @@
|
|
1
|
+
# Malkovich
|
2
|
+
|
3
|
+
Makes it reasonably easy to develop and deploy Puppet modules using Capistrano. Also includes a convenience for Vagrant.
|
4
|
+
|
5
|
+
This is a work in progress. Currently targets Ubuntu 12.04.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
In your `Capfile` add
|
10
|
+
|
11
|
+
```rb
|
12
|
+
require 'malkovich/capistrano'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Vagrant
|
16
|
+
|
17
|
+
Use a script provisioner to create the ubuntu user with your public key.
|
18
|
+
|
19
|
+
Requires recent-ish version of Vagrant (e.g., 1.2.7).
|
20
|
+
|
21
|
+
First, initialize a VM with Ubuntu Precise:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
$ vagrant init precise32 http://files.vagrantup.com/precise32.box
|
25
|
+
```
|
26
|
+
|
27
|
+
Then create the shell provisioner script in `.vagrant/` with:
|
28
|
+
|
29
|
+
```bash
|
30
|
+
$ cap vagrant
|
31
|
+
```
|
32
|
+
|
33
|
+
The `vagrant` task by default assumes your ssh key is in `~/.ssh/id_rsa`.
|
34
|
+
It will attempt to create a public key file at `~/.ssh/id_rsa.pub` if one doesn't already exist.
|
35
|
+
The key filenames can be set with `private_key_filename` and `public_key_filename`.
|
36
|
+
|
37
|
+
After the shell provisioner is written, inside the config block in your Vagrantfile add:
|
38
|
+
|
39
|
+
```rb
|
40
|
+
config.vm.provision :shell, :path => '.vagrant/shell_provisioner'
|
41
|
+
```
|
42
|
+
|
43
|
+
You might also set the network address for the VM so you can define the server in `Capfile`, for example:
|
44
|
+
|
45
|
+
```rb
|
46
|
+
config.vm.network :private_network, ip: "192.168.101.101"
|
47
|
+
```
|
48
|
+
|
49
|
+
Otherwise you can get it later from inside the VM using `ifconfig`.
|
50
|
+
|
51
|
+
Finally, boot up your Vagrant VM for the first time:
|
52
|
+
|
53
|
+
```bash
|
54
|
+
$ vagrant up
|
55
|
+
```
|
56
|
+
|
57
|
+
At this point, you may wish to run the `bootstrap`, described below.
|
58
|
+
|
59
|
+
## Stages
|
60
|
+
|
61
|
+
For each stage, define a Capistrano task where you set a vaule for `:stage` and other values:
|
62
|
+
|
63
|
+
```rb
|
64
|
+
task :qa do
|
65
|
+
set :stage, 'qa'
|
66
|
+
server 'qa.myapp.com', :app, :db
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
You can make a stage for your Vagrant VM:
|
71
|
+
|
72
|
+
```rb
|
73
|
+
task :dev do
|
74
|
+
set :stage, 'dev'
|
75
|
+
server '192.168.101.101', :app
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
Then invoke a stage task on the Capistrano command line before any primary task, e.g.:
|
80
|
+
|
81
|
+
```bash
|
82
|
+
|
83
|
+
$ cap dev bootstrap
|
84
|
+
```
|
85
|
+
|
86
|
+
## Bootstrap
|
87
|
+
|
88
|
+
A bootstrap Capistrano task is provided to prepare a base image with installed Puppet. This is for Ubuntu 12.04 precise.
|
89
|
+
|
90
|
+
One approach is to run bootstrap once on a clean image, and then create a new EC2 image or Vagrant box from that.
|
91
|
+
Then destroy the running machine and change your Vagrantfile to use the new image, also removing the shell provisioner.
|
92
|
+
|
93
|
+
Now you can use this new image as a starting point for Puppet module development.
|
94
|
+
|
95
|
+
## Puppet tasks
|
96
|
+
|
97
|
+
For every `.pp` file in `puppet/manifests` a Capistrano task will be created in the `puppet` namespace.
|
98
|
+
E.g., `puppet/manifests/web.pp` will result in the task `puppet:web` that can be run on stages.
|
99
|
+
When `puppet:web` is run it will upload `puppet/` to the servers with the `:web` role and use `puppet apply` to apply the `web` manifest.
|
100
|
+
|
101
|
+
This assumes `puppet/modules` is the path to the modules the manifest includes.
|
102
|
+
|
103
|
+
## Facts
|
104
|
+
|
105
|
+
Specifying a stage, a server and a role is enough to let you run your puppet manifests on your server, but in many cases it is useful to make arbitrary dynamic values available to your puppet modules when they run on the server.
|
106
|
+
The `fact` method makes this easy. For example,
|
107
|
+
|
108
|
+
```rb
|
109
|
+
task :qa do
|
110
|
+
set :stage, 'qa'
|
111
|
+
server 'qa.myapp.com', :app, :db
|
112
|
+
fact :hostname, 'qa.myapp.com'
|
113
|
+
end
|
114
|
+
```
|
115
|
+
|
116
|
+
will make a `$hostname` variable available in your puppet manifests. This is achieved with Facter environment variables.
|
117
|
+
|
118
|
+
## Required values
|
119
|
+
|
120
|
+
You must define at least one stage for most tasks, except for example `vagrant`.
|
121
|
+
|
122
|
+
## Default values
|
123
|
+
|
124
|
+
Some default Capistrano values are set such as user. See defaults.rb for more.
|
125
|
+
Set your own values in `Capfile`.
|
126
|
+
These work with the Vagrant shell provisioner and Canonical EC2 images.
|
127
|
+
|
128
|
+
## Capistrano tasks
|
129
|
+
|
130
|
+
There are some other tasks such as `uptime` and `upgrade`. View them all with:
|
131
|
+
|
132
|
+
```bash
|
133
|
+
$ cap -T
|
134
|
+
```
|
135
|
+
|
136
|
+
## Example
|
137
|
+
|
138
|
+
* Capfile
|
139
|
+
|
140
|
+
```rb
|
141
|
+
load 'deploy'
|
142
|
+
require 'malkovich/capistrano'
|
143
|
+
|
144
|
+
task :qa do
|
145
|
+
set :stage, 'qa'
|
146
|
+
server 'qa.myapp.com', :web
|
147
|
+
fact :hostname, 'qa.myapp.com'
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
151
|
+
* puppet/manifests/web.pp
|
152
|
+
|
153
|
+
```puppet
|
154
|
+
include nginx
|
155
|
+
```
|
156
|
+
|
157
|
+
* puppet/modules/nginx/manifests/init.pp
|
158
|
+
|
159
|
+
```puppet
|
160
|
+
class nginx {
|
161
|
+
file {
|
162
|
+
"/etc/nginx/nginx.conf":
|
163
|
+
content => template('nginx/nginx.conf.erb')
|
164
|
+
}
|
165
|
+
}
|
166
|
+
```
|
167
|
+
|
168
|
+
* puppet/modules/nginx/templates/nginx.conf.erb
|
169
|
+
|
170
|
+
```puppet
|
171
|
+
http {
|
172
|
+
server {
|
173
|
+
server_name <%= @hostname %>; #Puppet facts become Ruby instance variables in ERB
|
174
|
+
}
|
175
|
+
}
|
176
|
+
```
|
177
|
+
|
178
|
+
* Apply the manifest
|
179
|
+
|
180
|
+
```bash
|
181
|
+
$ cap qa puppet:web
|
182
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Capistrano::Configuration.instance.load do
|
2
|
+
_cset(:stage) { abort "please specify stage" }
|
3
|
+
|
4
|
+
set :application, 'application'
|
5
|
+
set :user, 'ubuntu'
|
6
|
+
set :use_sudo, false
|
7
|
+
set(:deploy_to) { "/home/#{user}" }
|
8
|
+
|
9
|
+
set(:facter_vars) { "" }
|
10
|
+
|
11
|
+
default_run_options[:pty] = true
|
12
|
+
ssh_options[:forward_agent] = true
|
13
|
+
|
14
|
+
set :private_key_filename, "#{ENV['HOME']}/.ssh/id_rsa"
|
15
|
+
set :public_key_filename, "#{ENV['HOME']}/.ssh/id_rsa.pub"
|
16
|
+
|
17
|
+
set :apt_get_cmd, %|DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confnew" --force-yes --fix-broken --yes|
|
18
|
+
|
19
|
+
set :essential_packages, "build-essential openssl libreadline6 libreadline6-dev curl
|
20
|
+
git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev
|
21
|
+
sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev
|
22
|
+
automake libtool bison"
|
23
|
+
|
24
|
+
set :bonus_packages, "vim tmux ack-grep"
|
25
|
+
|
26
|
+
set :puppet_packages, "puppet ruby1.8 libopenssl-ruby ruby rubygems"
|
27
|
+
|
28
|
+
set :packages, [essential_packages.squeeze, bonus_packages, puppet_packages].join(" ")
|
29
|
+
|
30
|
+
set :puppet_opts, '--verbose --modulepath=modules'
|
31
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Capistrano::Configuration.instance.load do
|
2
|
+
namespace :puppet do
|
3
|
+
Dir['puppet/manifests/*'].map{|s| s.split('/').last.split('.').first.to_sym}.each do |manifest|
|
4
|
+
desc "apply #{manifest} manifest to server with #{manifest} role"
|
5
|
+
task manifest, :roles => manifest do
|
6
|
+
upload "puppet", deploy_to, :via => :scp, :recursive => true
|
7
|
+
run "cd #{deploy_to}/puppet && sudo #{_facter_envs} puppet apply #{puppet_opts} manifests/#{manifest}.pp"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Capistrano::Configuration.instance.load do
|
2
|
+
|
3
|
+
desc 'Generate .vagrant/shell_provisioner with your publick_key'
|
4
|
+
task :vagrant do
|
5
|
+
dirname = '.vagrant'
|
6
|
+
filename = "#{dirname}/shell_provisioner"
|
7
|
+
|
8
|
+
abort("#{filename} already exists.") if File.exists? filename
|
9
|
+
|
10
|
+
unless File.exists? public_key_filename
|
11
|
+
puts "SSH public key #{public_key_filename} does not exist."
|
12
|
+
puts "Extracting from #{private_key_filename}..."
|
13
|
+
pub = `ssh-keygen -y -f #{private_key_filename}`
|
14
|
+
abort("Cancelled.") unless $? == 0
|
15
|
+
File.open(public_key_filename, 'a') {|f| f.write pub}
|
16
|
+
end
|
17
|
+
sh = <<-SH
|
18
|
+
adduser #{user} --gecos #{user} --disabled-password
|
19
|
+
adduser #{user} admin
|
20
|
+
mkdir ~#{user}/.ssh
|
21
|
+
echo "#{File.open(public_key_filename).read}" >> ~#{user}/.ssh/authorized_keys
|
22
|
+
chown #{user}.#{user} ~#{user}/.ssh/authorized_keys
|
23
|
+
chmod 600 ~#{user}/.ssh/authorized_keys
|
24
|
+
SH
|
25
|
+
|
26
|
+
puts "\nCreating #{filename}"
|
27
|
+
Dir.mkdir dirname unless File.exist? dirname
|
28
|
+
File.open(filename, 'w') do |f|
|
29
|
+
f.write sh
|
30
|
+
end
|
31
|
+
puts "\nAdd the following line to Vagrantfile:\nconfig.vm.provision :shell, :path => '.vagrant/shell_provisioner'"
|
32
|
+
end
|
33
|
+
|
34
|
+
task :uptime do
|
35
|
+
run "uptime"
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Upgrade packages and install puppet and build essentials"
|
39
|
+
task :bootstrap do
|
40
|
+
cmd = <<-SH
|
41
|
+
echo 'deb http://apt.puppetlabs.com precise main dependencies' | sudo tee /etc/apt/sources.list.d/puppetlabs.list;
|
42
|
+
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 4BD6EC30;
|
43
|
+
sudo #{apt_get_cmd} update;
|
44
|
+
sudo #{apt_get_cmd} upgrade;
|
45
|
+
sudo #{apt_get_cmd} install #{packages};
|
46
|
+
sudo gem install bundler --no-ri --no-rdoc
|
47
|
+
SH
|
48
|
+
run cmd
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Upgrade packages"
|
52
|
+
task :upgrade do
|
53
|
+
cmd = <<-SH
|
54
|
+
sudo #{apt_get_cmd} update;
|
55
|
+
sudo #{apt_get_cmd} upgrade;
|
56
|
+
SH
|
57
|
+
run cmd
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'malkovich/capistrano/version'
|
3
|
+
require 'malkovich/capistrano/puppet'
|
4
|
+
|
5
|
+
if Capistrano::Configuration.instance
|
6
|
+
require 'malkovich/capistrano/defaults'
|
7
|
+
require 'malkovich/capistrano/fact'
|
8
|
+
require 'malkovich/capistrano/tasks'
|
9
|
+
end
|
data/malkovich.gemspec
ADDED
@@ -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 'malkovich/capistrano/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "malkovich"
|
8
|
+
spec.version = Malkovich::Capistrano::VERSION
|
9
|
+
spec.authors = ["Steve Masterman"]
|
10
|
+
spec.email = ["steve@vermonster.com"]
|
11
|
+
spec.description = %q{Capistrano tasks and settings for Puppet, Vagrant/EC2, Ubuntu}
|
12
|
+
spec.summary = %q{Capistrano tasks and settings for Puppet, Vagrant/EC2, Ubuntu}
|
13
|
+
|
14
|
+
spec.homepage = "https://github.com/vermonster/malkovich"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_dependency "capistrano"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: malkovich
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Masterman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-16 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: capistrano
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Capistrano tasks and settings for Puppet, Vagrant/EC2, Ubuntu
|
56
|
+
email:
|
57
|
+
- steve@vermonster.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/malkovich/capistrano.rb
|
68
|
+
- lib/malkovich/capistrano/defaults.rb
|
69
|
+
- lib/malkovich/capistrano/fact.rb
|
70
|
+
- lib/malkovich/capistrano/puppet.rb
|
71
|
+
- lib/malkovich/capistrano/tasks.rb
|
72
|
+
- lib/malkovich/capistrano/version.rb
|
73
|
+
- malkovich.gemspec
|
74
|
+
homepage: https://github.com/vermonster/malkovich
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.0.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Capistrano tasks and settings for Puppet, Vagrant/EC2, Ubuntu
|
98
|
+
test_files: []
|