R10k uses a configuration file to determine how dynamic environments should be deployed.
An explicit configuration file location be specified by providing the --config
option to r10k deploy
, like so:
r10k deploy --config /srv/puppet/r10k.yaml [...]
If an explicit configuration file is not given, r10k will search the following locations for a configuration file.
{current working directory}/r10k.yaml
/etc/puppetlabs/r10k/r10k.yaml
(1.5.0 and later)/etc/r10k.yaml
(deprecated in 1.5.0)
In 1.5.0 r10k added /etc/puppetlabs/r10k/r10k.yaml
to the configuration search
path. The old location, /etc/r10k.yaml
has been deprecated in favor of the new
location. If both /etc/puppetlabs/r10k/r10k.yaml
and /etc/r10k.yaml
exist
and explicit configuration file has not been given, r10k will log a warning and
use /etc/puppetlabs/r10k/r10.yaml
.
The 'cachedir' setting specifies where r10k should keep cached information. Right now this is predominantly used for caching git repositories but will be expanded as other subsystems can take advantage of caching.
For example:
---
# Store all cache information in /var/cache
cachedir: '/var/cache/r10k'
The cachedir setting defaults to ~/.r10k
. If the HOME environment variable is
unset r10k will assume that r10k is being run with the Puppet [prerun_command
][prerun_command]
setting and will set the cachedir default to /root/.r10k
.
The 'git' setting is a hash that contains Git specific settings.
The provider option determines which Git provider should be used.
git:
provider: rugged # one of shellgit, rugged
See the git provider documentation for more information regarding Git providers.
The following options configure how r10k deploys dynamic environments.
The postrun
setting specifies an arbitrary command to run after deploying all
environments. The command must be an array of strings that will be used as an
argument vector. The exit code of the command is not currently used, but the
command should exit with a return code of 0 as the exit code may have semantics
in the future.
---
postrun: ['/usr/bin/curl', '-F', 'deploy=done', 'http://my-app.site/endpoint']
The postrun setting can only be set once.
The sources
setting specifies what repositories should be used for creating
dynamic environments. It is a hash where each key is the short name of a
specific repository (for instance, "qa" or "web" or "ops") and the value is a
hash of properties for that source.
---
sources:
main:
# Source settings follow
The following options are respected by all source implementations. Sources may implement other options in addition to the ones listed below; see the source specific documentation for more information.
The 'remote' setting specifies where the source repository should be fetched from. It may be any valid URL that the source may check out or clone. The remote must be able to be fetched without any interactive input, eg usernames or passwords cannot be prompted for in order to fetch the remote.
---
sources:
mysource:
remote: 'git://git-server.site/my-org/main-modules'
The 'basedir' setting specifies where environments will be created for this source. This directory will be entirely managed by r10k and any contents that r10k did not put there will be removed.
---
sources:
mysource:
basedir: '/etc/puppet/environments'
If two different sources have the same basedir, it's possible for them to create two separate environments with the same name and file path. If this occurs r10k will treat this as a fatal error and will abort. To avoid this, use prefixing on one or both of the sources to make sure that all environment names are unique. See also the prefix setting.
The prefix setting allows environment names to be prefixed with the short name of the given source. This prevents collisions when multiple sources are deployed into the same directory.
---
sources:
mysource:
basedir: '/etc/puppet/environments'
prefix: true # All environments will be prefixed with "mysource_"
- if
true
environment folder will be prefixed with the name of the source. - if
false
(default) environment folder will not be prefixed - if
String
environment folder will be prefixed with theprefix
value.
The majority of users will only have a single repository where all modules and hiera data files are kept. In this case you will specify a single source:
---
sources:
operations:
remote: 'git://git-server.site/my-org/org-modules'
basedir: '/etc/puppet/environments'
For more complex cases where you want to store hiera data in a different repository and your modules in another repository, you can specify two sources:
---
sources:
operations:
remote: 'git://git-server.site/my-org/org-modules'
basedir: '/etc/puppet/environments'
hiera:
remote: 'git://git-server.site/my-org/org-hiera-data'
basedir: '/etc/puppet/hiera-data'
Alternately you may want to create separate environments from multiple repositories. This is useful when you want two groups to be able to deploy Puppet modules but they should only have write access to their own modules and not the modules of other groups.
---
sources:
main:
remote: 'git://git-server.site/my-org/main-modules'
basedir: '/etc/puppet/environments'
prefix: false # Prefix defaults to false so this is only here for clarity
qa:
remote: 'git://git-server.site/my-org/qa-puppet-modules'
basedir: '/etc/puppet/environments'
prefix: true
dev:
remote: 'git://git-server.site/my-org/dev-puppet-modules'
basedir: '/etc/puppet/environments'
prefix: true
This will create the following directory structure:
/etc/puppet/environments
|-- production # main-modules repository, production branch
|-- upgrade_apache # main-modules repository, upgrade_apache branch
|-- qa_production # qa repository, production branch
|-- qa_jenkins_test # qa repository, jenkins_test branch
|-- dev_production # dev repository, production branch
`-- dev_loadtest # dev repository, loadtest branch
If hiera data is in a separate repository from your control repository, you
must override the prefix
so environment folders line up in both directories:
---
sources:
main:
app1_data:
remote: 'git://git-server.site/my-org/app1-hieradata'
basedir: '/etc/puppet/hieradata'
prefix: "app1"
app1_modules:
remote: 'git://git-server.site/my-org/app1-puppet-modules'
basedir: '/etc/puppet/environments'
prefix: "app1"
This will create the following directory structure:
/etc/puppet/environments
|-- app1_production # app1 modules repository, production branch
|-- app1_develop # app1 modules repository, develop branch
/etc/puppet/hieradata
|-- app1_production # app1 data repository, production branch
|-- app1_develop # app1 data repository, develop branch