作者名:Thomas Uphill John Arundel Neependra Khare Hideto Saito Hui Chuan Chloe Lee Ke Jou Carol Hsu
本章字數:388字
更新時間:2021-07-09 18:32:52
Setting up the environment
Environments in Puppet are directories holding different versions of your Puppet manifests. Environments prior to Version 3.6 of Puppet were not a default configuration for Puppet. In newer versions of Puppet, environments are configured by default.
Whenever a node connects to a Puppet master, it informs the Puppet master of its environment. By default, all nodes report to the production environment. This causes the Puppet master to look in the production environment for manifests. You may specify an alternate environment with the --environment setting when running puppet agent or by setting environment = newenvironment in /etc/puppet/puppet.conf in the [agent] section.
Getting ready
Set the environmentpath function of your installation by adding a line to the [main] section of /etc/puppet/puppet.conf as follows:
Create a production directory at /etc/puppet/environments that contains both a modules and manifests directory. Then create a site.pp which creates a file in /tmp as follows:
root@puppet:~# cd /etc/puppet/environments/root@puppet:/etc/puppet/environments# mkdir -p production/{manifests,modules}root@puppet:/etc/puppet/environments# vim production/manifests/site.ppnode default { file {'/tmp/production': content => "Hello World!\nThis is production\n", }}
Run puppet agent on the master to connect to it and verify that the production code was delivered:
root@puppet:~# puppet agent -vtInfo: Retrieving pluginfactsInfo: Retrieving pluginInfo: Caching catalog for puppetInfo: Applying configuration version '1410415538'Notice: /Stage[main]/Main/Node[default]/File[/tmp/production]/ensure: defined content as '{md5}f7ad9261670b9da33a67a5126933044c'Notice: Finished catalog run in 0.04 seconds# cat /tmp/productionHello World!This is production
Configure another environment devel. Create a new manifest in the devel environment:
Apply the new environment by running the --environment devel puppet agent using the following command:
root@puppet:/etc/puppet/environments# puppet agent -vt --environment develInfo: Retrieving pluginfactsInfo: Retrieving pluginInfo: Caching catalog for puppetInfo: Applying configuration version '1410415890'Notice: /Stage[main]/Main/Node[default]/File[/tmp/devel]/ensure: defined content as '{md5}b6313bb89bc1b7d97eae5aa94588eb68'Notice: Finished catalog run in 0.04 secondsroot@puppet:/etc/puppet/environments# cat /tmp/develGood-bye! Development
Tip
You may need to restart apache2 to enable your new environment, this depends on your version of Puppet and the environment_timeout parameter of puppet.conf.