This repository has been archived by the owner on Dec 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0aceb65
Showing
10 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vagrant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Reusable Puppet config for Vagrant | ||
|
||
This provides a very simple example that shows how you can reuse | ||
[Puppet][puppet] configuration between [Vagrant][vagrant] and your non-Vagrant | ||
systems, including data lookup via Hiera. | ||
|
||
Tested with Puppet 3.0.2. | ||
|
||
## Vagrant | ||
|
||
The Vagrant-specific configuration is captured in the `Vagrantfile`. The | ||
resulting Puppet invocation is | ||
|
||
cd /tmp/vagrant-puppet/manifests \ | ||
&& FACTER_is_vagrant='true' puppet apply \ | ||
--hiera_config hiera.yaml \ | ||
--modulepath '/tmp/vagrant-puppet/modules-0' \ | ||
/tmp/vagrant-puppet/manifests/default.pp | ||
|
||
When provisioned (via `vagrant up` or `vagrant provision`) you will see the | ||
following on the console: | ||
|
||
Notice: role::ui configured for vagrant; hostname: 192.168.42.42 | ||
|
||
## Other environments | ||
|
||
A sample `puppet_apply.sh` script is included in the `puppet` directory. All | ||
that is required is to clone this repository (or otherwise make the files | ||
available on the target system). | ||
|
||
## Tweaks | ||
|
||
### `is_vagrant` fact | ||
|
||
This could be replaced with the direct definition of a `data_center` fact. | ||
|
||
### Vagrant shell provisioner | ||
|
||
Vagrant takes care of providing mounts for the manifests and modules, so the | ||
configuration would only get shuffled around a bit, but it's possible to | ||
directly invoke `puppet_apply.sh` from Vagrant. | ||
|
||
### `hieradata` path messiness | ||
|
||
There's no way to provide variables to Hiera for path expansion other than via | ||
Puppet itself. It's a bit chicken-and-eggy. The provided `hiera.yaml` uses a | ||
relative path to the `hieradata` directory that is compatible with the Vagrant | ||
invocation of Puppet, and the example `puppet_apply.sh` similarly takes care of | ||
the path munging, but it doesn't feel all that clean to me. | ||
|
||
[puppet]: http://puppetlabs.com | ||
[vagrant]: http://vagrantup.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- mode: ruby -*- | ||
|
||
Vagrant::Config.run do |config| | ||
# Every Vagrant virtual environment requires a box to build off of. | ||
config.vm.box = "CentOS-6.3-x86_64-reallyminimal" | ||
|
||
# The url from where the 'config.vm.box' box will be fetched if it | ||
# doesn't already exist on the user's system. | ||
config.vm.box_url = "https://s3.amazonaws.com/1412126a-vagrant/CentOS-6.3-x86_64-reallyminimal.box" | ||
|
||
# Assign this VM to a host-only network IP, allowing you to access it | ||
# via the IP. | ||
config.vm.network :hostonly, "192.168.42.42" | ||
|
||
# Enable provisioning with Puppet stand alone. | ||
config.vm.provision :puppet do |puppet| | ||
## tell Puppet where to find the hiera config | ||
puppet.options = "--hiera_config hiera.yaml" | ||
|
||
## boilerplate Vagrant/Puppet config | ||
puppet.manifests_path = "puppet/manifests" | ||
puppet.manifest_file = "default.pp" | ||
puppet.module_path = "puppet/modules" | ||
|
||
## custom facts provided to Puppet | ||
puppet.facter = { | ||
## tells default.pp that we're running in Vagrant | ||
"is_vagrant" => true, | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## common entry-point into Puppet config. | ||
|
||
## if is_vagrant is defined, then we're running under Vagrant. Use other | ||
## logic/facts to detect environmental stuff. | ||
if $::is_vagrant { | ||
$data_center = 'vagrant' | ||
} else { | ||
$data_center = 'amazon' | ||
} | ||
|
||
include role::ui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
:hierarchy: | ||
- %{::data_center} | ||
- common | ||
|
||
:backends: | ||
- json | ||
|
||
:json: | ||
# @todo replace with absolute path for non-Vagrant use | ||
# alternatively set a top-level variable in default.pp and do %{::var_name} | ||
:datadir: 'hieradata' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"role::ui::public_hostname": "%{::ec2_public_hostname}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"role::ui::public_hostname": "%{::ipaddress_eth1}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# public_hostname will be looked up in hiera as role::ui::public_hostname | ||
class role::ui ( | ||
$public_hostname | ||
) { | ||
notify {'role::ui::notify': | ||
message => "role::ui configured for ${::data_center}; hostname: $public_hostname", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
basedir="$( dirname $( readlink -f "${0}" ) )" | ||
|
||
## required for the relative datadir path in hiera.yaml | ||
cd ${basedir}/manifests | ||
|
||
exec puppet apply \ | ||
--hiera_config ${basedir}/manifests/hiera.yaml \ | ||
--modulepath ${basedir}/modules \ | ||
${basedir}/manifests/default.pp |