Skip to content

Commit d4af4bf

Browse files
committed
Update our boxen template with the latest and greatest
1 parent 92dd6a9 commit d4af4bf

26 files changed

+247
-42
lines changed

Gemfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
source "http://rubygems.org"
1+
source "https://rubygems.org"
22

3-
gem "boxen", "~> 0.7"
3+
gem "boxen", "0.7.3"
44

55
group :development do
66
gem "aws-sdk"
7+
gem "net-ssh"
8+
gem "rbvmomi"
79
end

Gemfile.lock

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
GEM
2-
remote: http://rubygems.org/
2+
remote: https://rubygems.org/
33
specs:
44
addressable (2.3.2)
55
ansi (1.4.3)
66
aws-sdk (1.8.1.2)
77
json (~> 1.4)
88
nokogiri (>= 1.4.4)
99
uuidtools (~> 2.1)
10-
boxen (0.7.1)
10+
boxen (0.7.3)
1111
ansi (~> 1.4)
1212
hiera (~> 1.0.0)
1313
highline (~> 1.6)
1414
json_pure (~> 1.7)
1515
librarian-puppet (~> 0.9)
1616
octokit (~> 1.15)
1717
puppet (~> 3.0)
18+
builder (3.1.4)
1819
facter (1.6.17)
1920
faraday (0.8.5)
2021
multipart-post (~> 1.1)
@@ -24,16 +25,17 @@ GEM
2425
hiera (1.0.0)
2526
highline (1.6.15)
2627
json (1.7.6)
27-
json_pure (1.7.6)
28+
json_pure (1.7.7)
2829
librarian-puppet (0.9.7)
2930
json
3031
puppet
3132
thor (~> 0.15)
32-
multi_json (1.5.0)
33+
multi_json (1.6.0)
3334
multipart-post (1.1.5)
35+
net-ssh (2.6.5)
3436
netrc (0.7.7)
3537
nokogiri (1.5.6)
36-
octokit (1.22.0)
38+
octokit (1.23.0)
3739
addressable (~> 2.2)
3840
faraday (~> 0.8)
3941
faraday_middleware (~> 0.9)
@@ -43,12 +45,19 @@ GEM
4345
puppet (3.1.0)
4446
facter (~> 1.6)
4547
hiera (~> 1.0)
48+
rbvmomi (1.6.0)
49+
builder
50+
nokogiri (>= 1.4.1)
51+
trollop
4652
thor (0.17.0)
53+
trollop (2.0)
4754
uuidtools (2.1.3)
4855

4956
PLATFORMS
5057
ruby
5158

5259
DEPENDENCIES
5360
aws-sdk
54-
boxen (~> 0.7)
61+
boxen (= 0.7.3)
62+
net-ssh
63+
rbvmomi

Puppetfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# This file manages Puppet module dependencies.
2+
#
13
# It works a lot like Bundler. We provide some core modules by
24
# default. This ensures at least the ability to construct a basic
35
# environment.
@@ -28,7 +30,7 @@ github "inifile", "0.9.0", :repo => "cprice-puppet/puppetlabs-inifile"
2830
github "nginx", "0.2.1"
2931
github "nodejs", "0.0.2"
3032
github "nvm", "0.0.5"
31-
github "ruby", "0.5.1"
33+
github "ruby", "0.7.1"
3234
github "stdlib", "3.0.0", :repo => "puppetlabs/puppetlabs-stdlib"
3335
github "sudo", "0.0.1"
3436

Puppetfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ GITHUBTARBALL
4646
GITHUBTARBALL
4747
remote: boxen/puppet-ruby
4848
specs:
49-
ruby (0.5.1)
49+
ruby (0.7.1)
5050

5151
GITHUBTARBALL
5252
remote: boxen/puppet-sudo
@@ -74,7 +74,7 @@ DEPENDENCIES
7474
nginx (= 0.2.1)
7575
nodejs (= 0.0.2)
7676
nvm (= 0.0.5)
77-
ruby (= 0.5.1)
77+
ruby (= 0.7.1)
7878
stdlib (= 3.0.0)
7979
sudo (= 0.0.1)
8080

docs/personal-configuration.md

+47-17
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,59 @@ per-user configurations.
77

88
How? The personal manifest.
99

10+
## What even is a personal manifest?
11+
1012
Personal manifests live in `modules/people/manifests/<name>.pp`,
1113
where `<name>` is your GitHub username.
12-
A basic personal manifest might look like so:
14+
15+
The simplest personal manifest looks like this:
1316

1417
``` puppet
1518
class people::wfarr {
1619
notify { 'hello world': }
1720
}
1821
```
1922

20-
Now, each time `wfarr` runs Boxen it'll automatically print out "hello world"
21-
somewhere during the run.
22-
You can even run `boxen-my-config` to generate a default template for you
23-
and open it up in your editor.
24-
When you're done, you can simply run `boxen` and it'll include your changes
25-
in your personal manifest.
26-
**You should always keep your manifest committed and pushed to your repository**.
27-
Otherwise, auto-updates won't work!
28-
29-
The whole point of these personal manifest are they are _your_ manifest.
30-
You shouldn't worry if the things in here are work-related or not.
31-
This is about full automation.
32-
Want to install Minecraft and Rdio by default?
33-
Do it in your personal manifest.
34-
35-
You can check out the [projects README](../modules/projects/README.md) for further examples.
23+
Ah, the good old "Hello World".
24+
It's boring, but you can see there's really not much boilerplate involved.
25+
Let's try something *real* this time:
26+
27+
``` puppet
28+
class people::wfarr {
29+
include boxen::development
30+
}
31+
```
32+
33+
So what does this do?
34+
It clones every repo in the Boxen org to `~/src/boxen/<repo>`.
35+
How?
36+
Well, we can refer to [the source code](https://github.com/boxen/puppet-boxen/blob/master/manifests/development.pp)!
37+
If you're new to Puppet, or are unsure of what that class is doing, check out
38+
the [intro to puppet](./puppet.md) we've put together.
39+
40+
## Running different code on multiple machines
41+
42+
Puppet has conditionals and switching.
43+
Typically, the most reliable way to ensure some code runs on one machine but not
44+
others is to use the `case` statement on the `hostname` fact.
45+
Example:
46+
47+
``` puppet
48+
case $::hostname {
49+
'scruffy': {
50+
notify { "I'm Scruffy. The Janitor.": }
51+
}
52+
53+
'bender': {
54+
notify { "My full name is Bender Bending Rodriguez": }
55+
}
56+
57+
default: {
58+
notify { "Wha?": }
59+
}
60+
}
61+
```
62+
63+
One thing to note here is that Puppet always **requires** a default path
64+
on a case statement.
65+
Default is equivalent to "anything that isn't matched above".

docs/puppet.md

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# wtf is a puppet?
2+
3+
Puppet is configuration management tool, written in Ruby, that compiles
4+
and runs code written in the Puppet language.
5+
6+
But what does that actually mean in words a human can understand?
7+
Puppet is a tool that runs some code and that code can do all sorts of
8+
really powerful things to configure computers for you.
9+
10+
Why do I want code mucking about with my laptop though?
11+
For the exact same reasons you want code configuring your server.
12+
In particular, homogeneity, reproducibility, reusability, and automation.
13+
When you use code to express how a machine should be configured,
14+
you know that all of your machines are configured the same way,
15+
that you can repeat that configuration any number of times,
16+
and that you don't have to do it manually each time.
17+
18+
## How does Puppet work?
19+
20+
A Puppet run has two main steps: compilation and application.
21+
22+
The compilations step starts with reading in what's called the site manifest.
23+
The site manifest is a single file that contains Puppet code that is responsible
24+
for telling the compiler what other Puppet code it should compile.
25+
26+
Here are the first few lines of the default site manifest for Boxen:
27+
28+
```
29+
include boxen::environment
30+
include homebrew
31+
include gcc
32+
```
33+
34+
This tells the Puppet compiler that it must include the classes
35+
`boxen::environment`, `homebrew`, and `gcc`.
36+
Puppet will look for those classes on the modulepath.
37+
Typically, these files would be located at
38+
`$modulepath/boxen/manifests/environment.pp` and
39+
`$modulepath/homebrew/manifests/init.pp`.
40+
41+
These might include other classes as well, or define **resources**.
42+
Resources are the building blocks of Puppet.
43+
A resource is an abstract description about a **thing** and the **state**
44+
that thing should be in.
45+
Every resource has a **type**, which is just a classification of resources.
46+
For example, we might have a resource `Package[mysql]` and its type would be
47+
`Package`.
48+
Puppet also supports multiple providers for types which act as pluggable
49+
backends depending on the operating system it's running on or the tools
50+
available on a particular system (in the case of the `Package` type,
51+
we might have providers for `yum` and for `aptget`).
52+
53+
So now the Puppet compiler has finished tracking down and loading all the
54+
classes and resources it needs.
55+
Assuming we haven't encountered any compile-time errors, Puppet then begins
56+
the next phase of a run: applying the catalog.
57+
58+
All of the resources Puppet has collected into the catalog have formed a
59+
DAG (directed, acyclic graph) that represents the order in which all these
60+
resources can be applied in a correct order.
61+
Puppet simply grabs the first "node" in this graph and traverses all nodes
62+
in the graph, applying each resource as it goes.
63+
64+
Application of an individual resource starts with Puppet asking "is this
65+
resource in the state requested?" If the answer is yes, Puppet moves onto the
66+
next node and repeats this process. If the answer is no, Puppet will make
67+
whatever changes it can to reconcile the current state of the resource with
68+
what it should be, and then continues on.
69+
70+
Once all resources have been applied, the Puppet run is complete.
71+
72+
## Declarative by nature
73+
74+
One of the most confusing parts of the Puppet language to many newcomers is
75+
how the Puppet catalog orders and applies resources.
76+
The key thing to remember is that Puppet is a **declarative** language rather
77+
than a procedural one.
78+
In human words, the only order that matters in Puppet is order specified by
79+
relationships between resources.
80+
81+
Here's an example of how someone new to Puppet might write a class:
82+
83+
``` puppet
84+
class mysql {
85+
file { '/etc/my.cnf': source => 'puppet:///modules/mysql/my.cnf.erb' ; }
86+
package { 'mysql': }
87+
service { 'mysql': }
88+
}
89+
```
90+
91+
Someone expecting Puppet to be procedural would read this manifest as a list
92+
saying:
93+
94+
* First create the my.cnf file
95+
* Then install the mysql package
96+
* Then start the mysql service
97+
98+
The problem is, they would be **wrong**.
99+
There is no guarantee Puppet will apply these resources in that order,
100+
and it's quite likely that it won't.
101+
102+
The proper way to ensure ordering in Puppet is to use one of the four
103+
**relationship metaparameters**:
104+
105+
* before - Run this resource before another resource
106+
* notify - Same as before, but triggers a refresh on that resource
107+
* require - Run this resource after another resource
108+
* subscribe - Same as require, but triggers a refresh on that resource
109+
110+
The behavior of these metaparameters should be pretty clear.
111+
Triggering a resource simply means that a resource will "refresh" itself.
112+
That typically means something like a `Service` resource restarting itself.
113+
It's important to remember that these metaparameters are valid on **any** resource.
114+
115+
So, let's rewrite our example properly:
116+
117+
``` puppet
118+
class mysql {
119+
file { '/etc/my.cnf':
120+
source => 'puppet:///modules/mysql/my.cnf.erb',
121+
notify => Service['mysql']
122+
}
123+
124+
package { 'mysql':
125+
notify => Service['mysql']
126+
}
127+
128+
service { 'mysql': }
129+
}
130+
```
131+
132+
Now we're telling Puppet what order to apply these resources in:
133+
134+
* Make sure /etc/my.cnf is in place before we start the mysql service
135+
* If /etc/my.cnf changes, tell mysql to restart
136+
* Make sure the mysql package is in place before we start the mysql service
137+
* If the mysql package changes, tell mysql to restart
138+
139+
It's important to note that we didn't tell Puppet if `File[/etc/my.cnf]`
140+
should come before or after `Package[mysql]`.
141+
This is intentional.
142+
Most package managers won't overwrite a configuration file that already exists
143+
at package install-time, so in this case, we can assume installing the mysql
144+
package won't clobber our custom `/etc/my.cnf` file.

docs/rails.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class projects::rails_app {
1818
include phantomjs
1919
2020
boxen::project { 'rails_app':
21-
source => 'mycompany/rails_app',
2221
ruby => '1.9.3',
2322
mysql => true,
2423
redis => true,
2524
nginx => true,
25+
source => 'username/rails_app'
2626
}
2727
}
2828
```

manifests/site.pp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require boxen::environment
2-
require homebrew::repo
2+
require homebrew
3+
require gcc
34

45
Exec {
56
group => 'staff',
@@ -8,6 +9,8 @@
89

910
path => [
1011
"${boxen::config::home}/rbenv/shims",
12+
"${boxen::config::hime}/rbenv/bin",
13+
"${boxen::config::hime}/rbenv/plugins/ruby-build/bin",
1114
"${boxen::config::home}/homebrew/bin",
1215
'/usr/bin',
1316
'/bin',
@@ -16,7 +19,7 @@
1619
],
1720

1821
environment => [
19-
"HOMEBREW_CACHE=${homebrew::cachedir}",
22+
"HOMEBREW_CACHE=${homebrew::config::cachedir}",
2023
"HOME=/Users/${::luser}"
2124
]
2225
}
@@ -43,6 +46,8 @@
4346
provider => ghlaunchd
4447
}
4548

49+
Homebrew::Formula <| |> -> Package <| |>
50+
4651
node default {
4752
# core modules, needed for most things
4853
include dnsmasq

script/bootstrap

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ set -e
1313
rm -rf .bundle/config
1414
rm -rf .librarian/puppet/config
1515

16-
# Export CC to explicitly set the compiler used for cexts.
17-
18-
export CC=gcc
19-
2016
# Bundle install unless we're already up to date.
2117

18+
export PATH=$(pwd)/vendor/shims:$PATH
2219
bundle install --binstubs bin --path .bundle --quiet "$@"

0 commit comments

Comments
 (0)