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.
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”
Our init.pp file is a simple one, which will create a test file.We will assign the module to the node.
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.
To setup the Directory environments, we need to make some changes to the default puppet.conf file.
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
[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 |
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”
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
etc/puppet/environments/staging | |
tree | |
. | |
├── environment.conf | |
├── manifests | |
│ └── site.pp | |
└── modules | |
└── mytestmodule | |
└── manifests | |
└── init.pp |
Our init.pp file is a simple one, which will create a test file.We will assign the module to the node.
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
[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 | |
} |
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