r10k 1.3.5 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +1 -1
- data/CHANGELOG.mkd +210 -0
- data/CONTRIBUTING.mkd +105 -0
- data/Gemfile +2 -6
- data/README.mkd +97 -0
- data/doc/common-patterns.mkd +44 -0
- data/doc/dynamic-environments.mkd +12 -5
- data/doc/dynamic-environments/configuration.mkd +16 -1
- data/doc/dynamic-environments/{git-environments.markdown → git-environments.mkd} +13 -9
- data/doc/dynamic-environments/introduction.mkd +1 -2
- data/doc/dynamic-environments/master-configuration.mkd +70 -0
- data/doc/dynamic-environments/quickstart.mkd +241 -0
- data/doc/dynamic-environments/svn-environments.mkd +45 -0
- data/doc/dynamic-environments/usage.mkd +44 -5
- data/doc/dynamic-environments/workflow-guide.mkd +247 -0
- data/doc/faq.mkd +52 -0
- data/doc/puppetfile.mkd +203 -0
- data/lib/r10k/action/cri_runner.rb +75 -0
- data/lib/r10k/action/deploy.rb +9 -0
- data/lib/r10k/action/deploy/display.rb +104 -0
- data/lib/r10k/action/deploy/environment.rb +92 -0
- data/lib/r10k/action/deploy/module.rb +70 -0
- data/lib/r10k/action/puppetfile.rb +10 -0
- data/lib/r10k/action/puppetfile/check.rb +41 -0
- data/lib/r10k/action/puppetfile/cri_runner.rb +32 -0
- data/lib/r10k/action/puppetfile/install.rb +53 -0
- data/lib/r10k/action/puppetfile/purge.rb +37 -0
- data/lib/r10k/action/runner.rb +36 -0
- data/lib/r10k/action/visitor.rb +31 -0
- data/lib/r10k/cli/deploy.rb +14 -45
- data/lib/r10k/cli/puppetfile.rb +15 -53
- data/lib/r10k/deployment.rb +113 -58
- data/lib/r10k/deployment/basedir.rb +3 -38
- data/lib/r10k/deployment/config.rb +2 -1
- data/lib/r10k/deployment/source.rb +2 -0
- data/lib/r10k/environment/base.rb +40 -0
- data/lib/r10k/environment/git.rb +14 -17
- data/lib/r10k/environment/svn.rb +31 -15
- data/lib/r10k/errors.rb +33 -22
- data/lib/r10k/errors/formatting.rb +28 -0
- data/lib/r10k/execution.rb +2 -0
- data/lib/r10k/git/cache.rb +1 -6
- data/lib/r10k/git/errors.rb +1 -2
- data/lib/r10k/git/ref.rb +1 -1
- data/lib/r10k/module.rb +1 -1
- data/lib/r10k/module/base.rb +94 -2
- data/lib/r10k/module/forge.rb +33 -30
- data/lib/r10k/module/git.rb +13 -9
- data/lib/r10k/module/svn.rb +41 -28
- data/lib/r10k/puppetfile.rb +17 -1
- data/lib/r10k/semver.rb +2 -0
- data/lib/r10k/source/base.rb +8 -0
- data/lib/r10k/source/git.rb +1 -1
- data/lib/r10k/source/svn.rb +23 -5
- data/lib/r10k/svn/remote.rb +23 -3
- data/lib/r10k/svn/working_dir.rb +60 -9
- data/lib/r10k/task.rb +1 -0
- data/lib/r10k/task/deployment.rb +9 -1
- data/lib/r10k/task/environment.rb +2 -0
- data/lib/r10k/task/module.rb +1 -0
- data/lib/r10k/task/puppetfile.rb +3 -0
- data/lib/r10k/task_runner.rb +1 -0
- data/lib/r10k/util/attempt.rb +84 -0
- data/lib/r10k/util/basedir.rb +65 -0
- data/lib/r10k/util/purgeable.rb +55 -45
- data/lib/r10k/util/setopts.rb +53 -0
- data/lib/r10k/util/subprocess.rb +6 -30
- data/lib/r10k/util/subprocess/posix/runner.rb +29 -2
- data/lib/r10k/util/subprocess/result.rb +17 -4
- data/lib/r10k/util/subprocess/subprocess_error.rb +24 -0
- data/lib/r10k/version.rb +1 -1
- data/r10k.gemspec +7 -29
- data/spec/fixtures/unit/puppetfile/invalid-syntax/Puppetfile +1 -0
- data/spec/fixtures/unit/puppetfile/load-error/Puppetfile +1 -0
- data/spec/matchers/exit_with.rb +28 -0
- data/spec/r10k-mocks.rb +3 -0
- data/spec/r10k-mocks/mock_config.rb +28 -0
- data/spec/r10k-mocks/mock_env.rb +7 -0
- data/spec/r10k-mocks/mock_source.rb +10 -0
- data/spec/shared-examples/git-ref.rb +7 -7
- data/spec/spec_helper.rb +17 -5
- data/spec/unit/action/cri_runner_spec.rb +76 -0
- data/spec/unit/action/puppetfile/cri_action_spec.rb +65 -0
- data/spec/unit/action/runner_spec.rb +64 -0
- data/spec/unit/action/visitor_spec.rb +39 -0
- data/spec/unit/deployment_spec.rb +142 -0
- data/spec/unit/environment/base_spec.rb +38 -0
- data/spec/unit/environment/git_spec.rb +40 -10
- data/spec/unit/environment/svn_spec.rb +41 -4
- data/spec/unit/errors/formatting_spec.rb +84 -0
- data/spec/unit/git/alternates_spec.rb +1 -1
- data/spec/unit/git/head_spec.rb +1 -1
- data/spec/unit/git/ref_spec.rb +1 -1
- data/spec/unit/git/working_dir_spec.rb +1 -1
- data/spec/unit/module/base_spec.rb +72 -0
- data/spec/unit/module/forge_spec.rb +49 -8
- data/spec/unit/module/git_spec.rb +78 -0
- data/spec/unit/module/svn_spec.rb +40 -4
- data/spec/unit/module_spec.rb +3 -3
- data/spec/unit/puppetfile_spec.rb +84 -0
- data/spec/unit/settings/container_spec.rb +1 -1
- data/spec/unit/source/base_spec.rb +31 -0
- data/spec/unit/source/git_spec.rb +7 -7
- data/spec/unit/source/svn_spec.rb +1 -1
- data/spec/unit/svn/working_dir_spec.rb +56 -0
- data/spec/unit/util/attempt_spec.rb +82 -0
- data/spec/unit/util/setopts_spec.rb +59 -0
- data/spec/unit/util/subprocess/result_spec.rb +36 -0
- data/spec/unit/util/subprocess/subprocess_error_spec.rb +26 -0
- data/spec/unit/util/subprocess_spec.rb +2 -7
- metadata +83 -100
- data/.nodeset.yml +0 -7
- data/.rspec +0 -1
- data/README.markdown +0 -276
- data/Rakefile +0 -1
- data/doc/puppetfile.markdown +0 -87
- data/spec/rspec-system-r10k/puppetfile.rb +0 -24
- data/spec/rspec-system-r10k/tmpdir.rb +0 -32
- data/spec/system-provisioning/el.rb +0 -38
- data/spec/system/module/forge/install_spec.rb +0 -51
- data/spec/system/module/git/install_spec.rb +0 -117
- data/spec/system/module/svn/install_spec.rb +0 -51
- data/spec/system/module/svn/update_spec.rb +0 -38
- data/spec/system/spec_helper.rb +0 -60
- data/spec/system/system-helpers.rb +0 -4
- data/spec/system/version_spec.rb +0 -7
@@ -0,0 +1,44 @@
|
|
1
|
+
Common Patterns
|
2
|
+
===============
|
3
|
+
|
4
|
+
This guide provides common patterns seen in the r10k community. These patterns
|
5
|
+
are, of course, simply a guide. Understand why you are or are not using a
|
6
|
+
specific pattern before implementing it.
|
7
|
+
|
8
|
+
Repository Setup
|
9
|
+
----------------
|
10
|
+
|
11
|
+
Use a [Control Repo](http://www.jeffmalnick.com/blog/2014/05/16/r10k-control-repos/)
|
12
|
+
to store your `Puppetfile`.
|
13
|
+
|
14
|
+
Hiera data should be in the Control repo OR as a separate source in
|
15
|
+
`r10k.yaml`. Any `hiera.yaml` in the Control repo will be ignored on a per
|
16
|
+
environment basis, locating it at `/etc/puppet/hiera.yaml` is prefered.
|
17
|
+
|
18
|
+
Each puppet module should be contained in its own independent forge module or
|
19
|
+
repository.
|
20
|
+
|
21
|
+
Editing modules
|
22
|
+
---------------
|
23
|
+
|
24
|
+
All environment content is checked out into `$environmentpath/modules` on the
|
25
|
+
node r10k is run on, either your puppet master or each masterless node. Edits
|
26
|
+
made directly to these files will be lost on the next deploy. It is best
|
27
|
+
practice not to edit code on the production system in the production paths.
|
28
|
+
|
29
|
+
You may clone upstream repositories in a regular user's directory, on the master
|
30
|
+
or on another machine. Create a new feature branch locally, make all required
|
31
|
+
edits, and push the new branch upstream when ready for testing. R10k will
|
32
|
+
deploy changes from the upstream repositories, eliminating the need for manual
|
33
|
+
updates of the `$environmentpath` contents.
|
34
|
+
|
35
|
+
Automated deploys
|
36
|
+
-----------------
|
37
|
+
|
38
|
+
To reduce manual intervention, use a post-receive hook on your control and
|
39
|
+
module repos to initiate an r10k deploy. You can develop your own or use a
|
40
|
+
publicly available hook. These include:
|
41
|
+
|
42
|
+
* [Reaktor](https://github.com/pzim/reaktor)
|
43
|
+
* [zack/r10k's Webhooks](https://forge.puppetlabs.com/zack/r10k#webhook-support)
|
44
|
+
(Puppet Enterprise only)
|
@@ -6,13 +6,19 @@ Dynamic environment deployment is the core functionality of r10k.
|
|
6
6
|
Table of contents
|
7
7
|
-----------------
|
8
8
|
|
9
|
-
* [Introduction](dynamic-environments/introduction
|
9
|
+
* [Introduction](dynamic-environments/introduction.mkd): A brief description of
|
10
10
|
what dynamic environments are and how they work.
|
11
|
-
* [
|
12
|
-
|
13
|
-
* [Configuration](dynamic-environments/configuration
|
11
|
+
* [Quickstart](dynamic-environments/quickstart.mkd): Getting started with the
|
12
|
+
essentials of dynamic environments and r10k.
|
13
|
+
* [Configuration](dynamic-environments/configuration.mkd) A reference of dynamic
|
14
14
|
environment configuration options and how they're used
|
15
|
-
* [
|
15
|
+
* [Git environments](dynamic-environments/git-environments.mkd) How r10k
|
16
|
+
implements dynamic environments using git
|
17
|
+
* [Master Configuration](dynamic-environments/master-configuration.mkd) How to
|
18
|
+
configure your Puppet masters to use dynamic environments
|
19
|
+
* [Workflow Guide](dynamic-environments/workflow-guide.mkd) A general-purpose
|
20
|
+
workflow guide for using r10k.
|
21
|
+
* [Usage](dynamic-environments/usage.mkd) A reference of r10k commands and how
|
16
22
|
they're used.
|
17
23
|
|
18
24
|
- - -
|
@@ -22,3 +28,4 @@ Community guides
|
|
22
28
|
|
23
29
|
* [Building a Functional Puppet Workflow Part 3: Dynamic Environments with R10k](http://garylarizza.com/blog/2014/02/18/puppet-workflow-part-3/)
|
24
30
|
* [Puppet Infrastructure with r10k](http://terrarum.net/blog/puppet-infrastructure-with-r10k.html)
|
31
|
+
* [Puppet for vSphere Admins](http://rnelson0.com/puppet-for-vsphere-admins/) Installing and using r10k in a vSphere environment
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Dynamic Environment Configuration
|
2
2
|
=================================
|
3
3
|
|
4
|
-
|
4
|
+
R10k uses a configuration file to determine how dynamic environments should be
|
5
5
|
deployed.
|
6
6
|
|
7
7
|
Config file location
|
@@ -41,6 +41,21 @@ Deployment options
|
|
41
41
|
|
42
42
|
The following options configure how r10k deploys dynamic environments.
|
43
43
|
|
44
|
+
### postrun
|
45
|
+
|
46
|
+
The `postrun` setting specifies an arbitrary command to run after deploying all
|
47
|
+
environments. The command must be an array of strings that will be used as an
|
48
|
+
argument vector. The exit code of the command is not currently used, but the
|
49
|
+
command should exit with a return code of 0 as the exit code may have semantics
|
50
|
+
in the future.
|
51
|
+
|
52
|
+
```yaml
|
53
|
+
---
|
54
|
+
postrun: ['/usr/bin/curl', '-F', 'deploy=done', 'http://my-app.site/endpoint']
|
55
|
+
```
|
56
|
+
|
57
|
+
The postrun setting can only be set once.
|
58
|
+
|
44
59
|
### sources
|
45
60
|
|
46
61
|
The `sources` setting specifies what repositories should be used for creating
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Git Based Dynamic Environments
|
2
2
|
==============================
|
3
3
|
|
4
|
-
|
4
|
+
R10k can use Git repositories to implement dynamic environments. You can create,
|
5
5
|
update, and delete Puppet environments automatically as part of your normal Git
|
6
6
|
workflow.
|
7
7
|
|
@@ -29,17 +29,21 @@ seamlessly reflected in Puppet environments. This means that creating a new Git
|
|
29
29
|
branch creates a new Puppet environment, updating a Git branch will update that
|
30
30
|
environment, and deleting a Git branch will remove that environment.
|
31
31
|
|
32
|
+
R10k supports both [directory and config file environments](https://docs.puppetlabs.com/puppet/latest/reference/environments.html).
|
33
|
+
Ensure that the basedir for your sources and your puppet config align.
|
34
|
+
|
32
35
|
How it works
|
33
36
|
------------
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
environments
|
38
|
+
R10k works by tracking the state of your Git repository or repositories. Each
|
39
|
+
repository's branches will be cloned into a directory with a matching name,
|
40
|
+
creating a Puppet environment for the branch. If a repository includes a
|
41
|
+
Puppetfile, such as the control repo, the Forge modules and Git/SVN
|
42
|
+
repositories described within will be cloned as well, into the same directories.
|
43
|
+
Subsequent changes to the branches will be kept in sync on the filesystem by
|
44
|
+
future r10k runs. Finally, if there are directories that do not match existing
|
45
|
+
branches, r10k will assume that the branches for those environments were delete
|
46
|
+
and will remove those environments.
|
43
47
|
|
44
48
|
Configuration
|
45
49
|
-------------
|
@@ -42,8 +42,7 @@ like modulepath, manifest, and so forth.
|
|
42
42
|
|
43
43
|
```ini
|
44
44
|
[master]
|
45
|
-
|
46
|
-
modulepath = '/etc/puppet/environments/$environment/modules'
|
45
|
+
environmentpath = $confdir/environments'
|
47
46
|
```
|
48
47
|
|
49
48
|
Running `puppet agent -t --environment myenv` will cause $environment to be
|
@@ -0,0 +1,70 @@
|
|
1
|
+
Puppet master configuration
|
2
|
+
===========================
|
3
|
+
|
4
|
+
In order to use dynamic environments, your Puppet masters will need to be
|
5
|
+
configured to load manifests and modules relative to the requested environment.
|
6
|
+
The following settings should be configured in puppet.conf.
|
7
|
+
|
8
|
+
## Puppet <= 3.4.x
|
9
|
+
|
10
|
+
In Puppet 3.4 and earlier, dynamic environments are achieved by interpolating
|
11
|
+
the `$environment` variable in the modulepath, manifestdir, and manifest
|
12
|
+
settings. When environments is loaded the settings are dynamically set based on
|
13
|
+
the name of the environment, thus allowing environments to be created on the
|
14
|
+
fly.
|
15
|
+
|
16
|
+
[master]
|
17
|
+
modulepath = /etc/puppet/environments/$environment/modules:/etc/puppet/environments/$environment/dist
|
18
|
+
|
19
|
+
# If you use a top level manifest dir
|
20
|
+
manifestdir = /etc/puppet/environments/$environment/manifests
|
21
|
+
# If you use a specific site wide manifest
|
22
|
+
manifest = /etc/puppet/environments/$environment/manifests/nodes.pp
|
23
|
+
|
24
|
+
## Puppet = 3.5.x
|
25
|
+
|
26
|
+
Puppet 3.5.0 adds initial support for "directory environments", where
|
27
|
+
environments are created by enumerating directories in `$environmentpath`.
|
28
|
+
This new configuration expect that all modules are in the root of the
|
29
|
+
directories in the environment path.
|
30
|
+
|
31
|
+
[master]
|
32
|
+
# None of modulepath, manifestdir, or manifest should be enabled
|
33
|
+
# See http://docs.puppetlabs.com/puppet/latest/reference/environments.html#enabling-directory-environments
|
34
|
+
# for more information on the changes
|
35
|
+
environmentpath = $confdir/environments
|
36
|
+
|
37
|
+
Note that these settings go into the `[master]` section; you don't need to
|
38
|
+
explicitly configure an environment section for each environment you want to
|
39
|
+
use. (But you can if you want.)
|
40
|
+
|
41
|
+
## Puppet >= 3.6.0
|
42
|
+
|
43
|
+
[environmentconf]: http://docs.puppetlabs.com/puppet/latest/reference/config_file_environment.html
|
44
|
+
|
45
|
+
Puppet 3.6.0 adds more fine grained control over how directory environments are
|
46
|
+
configured. Each directory based environment can have an
|
47
|
+
[`environment.conf`][environmentconf] file in the root of that environment that
|
48
|
+
can specify the manifest, modulepath, config_version, and environment_timeout
|
49
|
+
for that specific environment.
|
50
|
+
|
51
|
+
# puppet.conf
|
52
|
+
[master]
|
53
|
+
# None of modulepath, manifestdir, or manifest should be enabled
|
54
|
+
# See http://docs.puppetlabs.com/puppet/latest/reference/environments.html#enabling-directory-environments
|
55
|
+
# for more information on the changes
|
56
|
+
environmentpath = $confdir/environments
|
57
|
+
|
58
|
+
- - -
|
59
|
+
|
60
|
+
# environment.conf
|
61
|
+
manifest = site.pp
|
62
|
+
moduledir = modules:dist
|
63
|
+
|
64
|
+
A deployed environment with a Puppetfile will look something like this:
|
65
|
+
|
66
|
+
.
|
67
|
+
├── Puppetfile
|
68
|
+
├── environment.conf
|
69
|
+
├── dist
|
70
|
+
└── modules
|
@@ -0,0 +1,241 @@
|
|
1
|
+
# Overview
|
2
|
+
|
3
|
+
This intent of this document is to serve as a basic guide for getting started with r10k and a fresh Puppet installation, including the following:
|
4
|
+
|
5
|
+
* Installing Puppet and its dependencies
|
6
|
+
* Installing Hiera and its dependencies.
|
7
|
+
* Installing r10k and its dependencies
|
8
|
+
* Configuring all components to support r10k
|
9
|
+
* Configuring your git repository and initial files
|
10
|
+
|
11
|
+
# Pre-Requisites
|
12
|
+
|
13
|
+
* Clean install of CentOS 6.5 or Debian 7.0 with root access / sudo rights.
|
14
|
+
* Clean github repository with a deploy key generated by the server above.
|
15
|
+
|
16
|
+
# Installing Puppetmaster on Centos 6.5
|
17
|
+
|
18
|
+
Install and enable the official Puppet Labs package repositories.
|
19
|
+
|
20
|
+
```
|
21
|
+
rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm
|
22
|
+
```
|
23
|
+
|
24
|
+
Clean all yum data and rebuild the metadata cache.
|
25
|
+
|
26
|
+
```
|
27
|
+
yum clean all && yum makecache
|
28
|
+
```
|
29
|
+
|
30
|
+
Install the Puppet master.
|
31
|
+
|
32
|
+
```
|
33
|
+
yum install puppet-server
|
34
|
+
```
|
35
|
+
|
36
|
+
# Installing Puppetmaster on Debian 7
|
37
|
+
|
38
|
+
Install and enable the official Puppet Labs package repositories
|
39
|
+
|
40
|
+
```
|
41
|
+
wget http://apt.puppetlabs.com/puppetlabs-release-wheezy.deb
|
42
|
+
dpkg -i puppetlabs-release-wheezy.deb
|
43
|
+
apt-get update
|
44
|
+
```
|
45
|
+
|
46
|
+
Install the Pupppet master
|
47
|
+
```
|
48
|
+
apt-get install puppetmaster-passenger=3.7.1-1puppetlabs1
|
49
|
+
```
|
50
|
+
Above command will install 3.7.1-1puppetlabs but there are many versions to choose. To see available versions run: apt-cache show puppetmaster-passenger|grep ^Version
|
51
|
+
|
52
|
+
# Configuring Puppet
|
53
|
+
|
54
|
+
Configure the Puppet master by editing `/etc/puppet/puppet.conf` and ensuring it has the following contents:
|
55
|
+
|
56
|
+
```
|
57
|
+
[main]
|
58
|
+
# The Puppet log directory.
|
59
|
+
# The default value is '$vardir/log'.
|
60
|
+
logdir = /var/log/puppet
|
61
|
+
|
62
|
+
# Where Puppet PID files are kept.
|
63
|
+
# The default value is '$vardir/run'.
|
64
|
+
rundir = /var/run/puppet
|
65
|
+
|
66
|
+
# Where SSL certificates are kept.
|
67
|
+
# The default value is '$confdir/ssl'.
|
68
|
+
ssldir = $vardir/ssl
|
69
|
+
|
70
|
+
dns_alt_names = $_Insert FQDN of Puppet Master Here_$
|
71
|
+
|
72
|
+
environmentpath = $confdir/environments
|
73
|
+
|
74
|
+
[agent]
|
75
|
+
# The file in which puppetd stores a list of the classes
|
76
|
+
# associated with the retrieved configuratiion. Can be loaded in
|
77
|
+
# the separate ``puppet`` executable using the ``--loadclasses``
|
78
|
+
# option.
|
79
|
+
# The default value is '$confdir/classes.txt'.
|
80
|
+
classfile = $vardir/classes.txt
|
81
|
+
|
82
|
+
# Where puppetd caches the local configuration. An
|
83
|
+
# extension indicating the cache format is added automatically.
|
84
|
+
# The default value is '$confdir/localconfig'.
|
85
|
+
localconfig = $vardir/localconfig
|
86
|
+
|
87
|
+
server = $_Insert FQDN of Puppet Master Here_$
|
88
|
+
```
|
89
|
+
|
90
|
+
Restart the Puppet master service.
|
91
|
+
|
92
|
+
```
|
93
|
+
service puppetmaster restart
|
94
|
+
```
|
95
|
+
|
96
|
+
Ensure the certificate for the Puppet master was created.
|
97
|
+
|
98
|
+
```
|
99
|
+
# puppet cert list --all
|
100
|
+
|
101
|
+
+ "puppet-master.domain.local" (SHA256) 3F:F3:63:BB:EE:57:46:A4:7B:03:AB:9D:FD:97:0F:8F:73:87:40:3B:6D:E5:DC:FC:C3:49:F5:C9:B6:F4:DE:B8 (alt names: "DNS:puppet-master.domain.local")
|
102
|
+
```
|
103
|
+
|
104
|
+
Notice for Debian users: apt post-configure will build the certificate for the server BEFORE you configure it. Therefore you should rebuild your certs after done with /etc/puppet/puppet.conf configuration.
|
105
|
+
To do so you need to remove old certs and restart puppetmaster:
|
106
|
+
```
|
107
|
+
service puppetmaster stop
|
108
|
+
find $(puppet master --configprint ssldir) -name "$(puppet master --configprint certname).pem" -delete
|
109
|
+
puppet master --no-daemonize --verbose
|
110
|
+
```
|
111
|
+
|
112
|
+
# Install and Configure R10k
|
113
|
+
|
114
|
+
Install r10k via Ruby Gems.
|
115
|
+
|
116
|
+
```
|
117
|
+
gem install r10k
|
118
|
+
```
|
119
|
+
|
120
|
+
Configure r10k by editing `/etc/r10k.yaml` and ensuring it has the following contents:
|
121
|
+
|
122
|
+
```
|
123
|
+
# The location to use for storing cached Git repos
|
124
|
+
:cachedir: '/var/cache/r10k'
|
125
|
+
|
126
|
+
# A list of git repositories to create
|
127
|
+
:sources:
|
128
|
+
# This will clone the git repository and instantiate an environment per
|
129
|
+
# branch in /etc/puppet/environments
|
130
|
+
:my-org:
|
131
|
+
remote: 'git@github.com:$_Insert GitHub Organization Here_$/$_Insert GitHub Repository That Will Be Used For Your Puppet Code Here_$'
|
132
|
+
basedir: '/etc/puppet/environments'
|
133
|
+
```
|
134
|
+
# Install and Configure Hiera
|
135
|
+
|
136
|
+
Hiera is installed as part of the Puppet master installation.
|
137
|
+
|
138
|
+
Configure Hiera by editing `/etc/hiera.yaml` and ensuring it has the following contents:
|
139
|
+
|
140
|
+
```
|
141
|
+
---
|
142
|
+
:backends:
|
143
|
+
- yaml
|
144
|
+
:hierarchy:
|
145
|
+
- "nodes/%{fqdn}"
|
146
|
+
- common
|
147
|
+
|
148
|
+
:yaml:
|
149
|
+
:datadir: /etc/puppet/environments/%{environment}/hiera
|
150
|
+
```
|
151
|
+
|
152
|
+
Create a symlink to the Hiera configuration in the Puppet directory.
|
153
|
+
|
154
|
+
```
|
155
|
+
ln -s /etc/hiera.yaml /etc/puppet/hiera.yaml
|
156
|
+
```
|
157
|
+
|
158
|
+
# Configure Puppet Code Repository
|
159
|
+
|
160
|
+
Populate the repository by cloning it locally and performing each of the following actions within it:
|
161
|
+
|
162
|
+
```
|
163
|
+
mkdir -p {modules,site/profile/manifests,hiera}
|
164
|
+
touch hiera/common.yaml
|
165
|
+
touch site/profile/manifests/base.pp
|
166
|
+
touch environment.conf
|
167
|
+
touch Puppetfile
|
168
|
+
touch site.pp
|
169
|
+
```
|
170
|
+
|
171
|
+
Edit the `environment.conf` file and ensure it has the following contents:
|
172
|
+
|
173
|
+
```
|
174
|
+
manifest = site.pp
|
175
|
+
modulepath = modules:site
|
176
|
+
```
|
177
|
+
|
178
|
+
Edit the `site.pp` file and ensure it has the following contents:
|
179
|
+
|
180
|
+
```
|
181
|
+
hiera_include('classes')
|
182
|
+
```
|
183
|
+
|
184
|
+
Edit the `hiera/common.yaml file and ensure it has the following contents:
|
185
|
+
|
186
|
+
```
|
187
|
+
---
|
188
|
+
classes:
|
189
|
+
- 'profile::base'
|
190
|
+
|
191
|
+
ntp::servers:
|
192
|
+
- 0.us.pool.ntp.org
|
193
|
+
- 1.us.pool.ntp.org
|
194
|
+
```
|
195
|
+
|
196
|
+
Edit the `Puppetfile` file and ensure it has the following contents:
|
197
|
+
|
198
|
+
```
|
199
|
+
forge 'forge.puppetlabs.com'
|
200
|
+
|
201
|
+
# Forge Modules
|
202
|
+
mod 'puppetlabs/ntp', '3.0.3'
|
203
|
+
mod 'puppetlabs/stdlib'
|
204
|
+
```
|
205
|
+
|
206
|
+
Edit the `site/profile/manifests/base.pp` file and ensure it has the following contents:
|
207
|
+
|
208
|
+
```
|
209
|
+
class profile::base {
|
210
|
+
class { '::ntp': }
|
211
|
+
}
|
212
|
+
```
|
213
|
+
|
214
|
+
# Summary
|
215
|
+
|
216
|
+
We now have the following functional pieces:
|
217
|
+
|
218
|
+
1. Puppet master
|
219
|
+
2. Hiera
|
220
|
+
3. r10k
|
221
|
+
4. Puppet code repository
|
222
|
+
5. Initial 'profile' named 'base' that will configure NTP on our servers.
|
223
|
+
|
224
|
+
This base will allow us to do all sorts of useful things. Most interesting (to me and for the purposes of this tutorial) is the ability to now utilize Git branches to help manage infrastructure as part of your software development lifecycle. Now, when you want to test a new profile, you can do the following:
|
225
|
+
|
226
|
+
1. Create a new branch of the Puppet code repository
|
227
|
+
2. Create your Puppet code in this new branch
|
228
|
+
3. Push the new branch up to the repository
|
229
|
+
4. Deploy it as a new environment using the `r10k deploy environment -p` command.
|
230
|
+
|
231
|
+
From any agent node (including the master), you may run the agent against the new environment by specifying it on the command line. For example, if you create the branch `test`, run puppet as:
|
232
|
+
```
|
233
|
+
puppet agent -t --environment test
|
234
|
+
```
|
235
|
+
You can also modify the `/etc/puppet/puppet.conf` file on a node and add the environment setting to the agent section to make the change permanent:
|
236
|
+
```
|
237
|
+
...
|
238
|
+
[agent]
|
239
|
+
environment = test
|
240
|
+
```
|
241
|
+
Voila - you're testing code without impacting your production environment!
|