Sunday, February 15, 2015

Daily Puppet - Puppet Environment Directories

Puppet environments can help to differentiate between the level of code, like production, staging, development. 

To setup the Directory environments, we need to make some changes to the default puppet.conf file.


[main]
# The Puppet log directory.
# The default value is '$vardir/log'.
logdir = /var/log/puppet
# Where Puppet PID files are kept.
# The default value is '$vardir/run'.
rundir = /var/run/puppet
# Where SSL certificates are kept.
# The default value is '$confdir/ssl'.
ssldir = $vardir/ssl
confdir = /etc/puppet
environmentpath = $confdir/environments
default_manifest = $confdir/manifests
[agent]
# The file in which puppetd stores a list of the classes
# associated with the retrieved configuratiion. Can be loaded in
# the separate ``puppet`` executable using the ``--loadclasses``
# option.
# The default value is '$confdir/classes.txt'.
classfile = $vardir/classes.txt
# Where puppetd caches the local configuration. An
# extension indicating the cache format is added automatically.
# The default value is '$confdir/localconfig'.
localconfig = $vardir/localconfig
view raw gistfile1.pp hosted with ❤ by GitHub


Once these changes are applied, we will need to restart the puppet master service. 

We have set the environment folders to be searched in the path “/etc/puppet/environments”, by using the configuration directive,
environmentpath = $confdir/environments


We will now create a staging environment for a test module “mytestmodule”

etc/puppet/environments/staging
tree
.
├── environment.conf
├── manifests
│   └── site.pp
└── modules
└── mytestmodule
└── manifests
└── init.pp
view raw gistfile1.sh hosted with ❤ by GitHub



Our init.pp file is a simple one, which will create a test file.We will assign the module to the node.

[root@centos staging]# cat modules/mytestmodule/manifests/init.pp
class mytestmodule {
file { "/home/testingenv.txt":
ensure => present,
}
}
[root@centos staging]# cat manifests/site.pp
node centos {
include mytestmodule
}
view raw gistfile1.txt hosted with ❤ by GitHub


Now, we test our environment,

puppet agent --noop --test --server centos  --environment=staging
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for centos
Info: Applying configuration version '1424034120'
Notice: /Stage[main]/Mytestmodule/File[/home/testingenv.txt]/ensure: current_value absent, should be present (noop)
Notice: Class[Mytestmodule]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.03 seconds

This kind of set up is very helpful, when we want to separate our production code from the testing code. 










No comments:

Post a Comment