Article written: April 2016
Platform used in example: PE 2015.3
Before you start:
full tutorial here: http://garylarizza.com/blog/2014/08/31/r10k-plus-directory-environments/
#1 configure R10K with a path to the Control Repo
#2 create branches in your remote Control Repo (Prod, Dev, Stage, etc)
#2 configure Puppetfile for each branch
#3 run "r10k deploy environment -pv" to sync your modules
this is the location where you define what modules go into what environment, using the Puppetfile
create a new R10K Control location, for example: /var/puppet/puppet_r10k,
clone this repository https://github.com/glarizza/puppet_repository to the R10K control location
configure 'configure_r10k.pp' and add your own remote git repo, push all your files in /var/puppet/puppet_r10k to this remote repo
class { 'r10k':
version => '1.3.2',
sources => {
'puppet' => {
'remote' => 'https://github.com/perfecto25/puppet_code_manager.git',
'basedir' => "${::settings::confdir}/code/environments",
'prefix' => false,
}
},
purgedirs => ["${::settings::confdir}/code/environments"],
manage_modulepath => false,
}
Git init your R10K control location (this will be your environment controller). Create 3 new branches (development, production, stage). Git checkout to "production" branch and open the Puppetfile, and add any modules you want your Prod environment,
[root@puppetmaster3 puppet_r10k]# git branch
development
* production
testing
[root@puppetmaster3 puppet_r10k]# ls
configure_directory_environments.pp configure_r10k.pp environment.conf hieradata manifests Puppetfile README.md scripts
[root@puppetmaster3 puppet_r10k]# cat Puppetfile
# -- PRODUCTION BRANCH --
forge 'forgeapi.puppet.com'
mod 'puppetlabs/git'
mod 'puppetlabs/dism'
mod 'puppetlabs/stdlib'
mod 'chocolatey/chocolatey'
mod 'puppetlabs/acl'
mod 'puppetlabs/concat'
mod 'badgerious/windows_env'
mod 'puppetlabs/powershell'
mod 'puppetlabs/reboot'
mod 'nginx',
:git => 'https://github.com/perfecto25/perfecto25-nginx.git',
:ref => 'master'
mod 'perfecto25-base',
:git => 'https://github.com/perfecto25/perfecto25-base.git',
:ref => 'master'
mod 'perfecto25-various',
:git => 'https://github.com/perfecto25/perfecto25-various.git',
:ref => 'master'
4. Git branch to dev branch and add modules to Dev env Puppetfile, do same for stage branch
5. Your Github R10K control repo should now have 3 branches with 3 separate Puppetfiles controlling which modules get installed
configure /etc/puppetlabs/r10k/r10k.yaml (or whatever r10k.yaml is controlling your R10K setup)
---
cachedir: /opt/puppetlabs/server/data/puppetserver/r10k
sources:
puppet:
basedir: /etc/puppetlabs/code/environments
remote: git@github.com:perfecto25/puppet_code_manager.git
git:
private_key: /etc/puppetlabs/puppetserver/ssh/id-control_repo.rsa
provider: rugged
make sure to turn off Code Manager Automanage in the Puppet Console
PE Master class >
code_manager_auto_configure
=
false
check the /etc/puppetlabs/puppet/puppet.conf file to make sure environmentpath and basemodulepath are correct
[root@puppetmaster3 puppet]# cat puppet.conf
[main]
certname = puppetmaster3
server = puppetmaster3
user = pe-puppet
group = pe-puppet
archive_files = true
archive_file_server = puppetmaster3
module_groups = base+pe_only
environmentpath = /etc/puppetlabs/code/environments
basemodulepath = $confdir/code/environments/production/modules:$confdir/code/environments/development/modules
[agent]
graph = true
[master]
app_management = true
node_terminus = classifier
storeconfigs = true
storeconfigs_backend = puppetdb
reports = puppetdb
certname = puppetmaster3
always_cache_features = true
to sync the environments from Git, run r10k deploy command
r10k deploy environment -pv
to sync the environments from Git, run r10k deploy command
r10k deploy environment -pv