作者名:Thomas Uphill John Arundel Neependra Khare Hideto Saito Hui Chuan Chloe Lee Ke Jou Carol Hsu
本章字?jǐn)?shù):512字
更新時(shí)間:2021-07-09 18:32:56
Building config files using snippets
Sometimes you can't deploy a whole config file in one piece, yet making line by line edits isn't enough. Often, you need to build a config file from various bits of configuration managed by different classes. You may run into a situation where local information needs to be imported into the file as well. In this example, we'll build a config file using a local file as well as snippets defined in our manifests.
Getting ready
Although it's possible to create our own system to build files from pieces, we'll use the puppetlabs supported concat module. We will start by installing the concat module, in a previous example we installed the module to our local machine. In this example, we'll modify the Puppet server configuration and download the module to the Puppet server.
In your Git repository create an environment.conf file with the following contents:
On the node, create /etc/hosts.allow.local with the following contents:
in.tftpd: .example.com
Run Puppet to have the file created:
[root@cookbook ~]# puppet agent -tInfo: Caching catalog for cookbook.example.comInfo: Applying configuration version '1412138600'Notice: /Stage[main]/Base/Concat[hosts.allow]/File[hosts.allow]/ensure: defined content as '{md5}b151c8bbc32c505f1c4a98b487f7d249'Notice: Finished catalog run in 0.29 seconds
Verify the contents of the new file as:
[root@cookbook ~]# cat /etc/hosts.allow# File managed by puppetin.tftpd: .example.comin.ftpd: .example.com
How it works...
The concat resource defines a container that will hold all the subsequent concat::fragment resources. Each concat::fragment resource references the concat resource as the target. Each concat::fragment also includes an order attribute. The order attribute is used to specify the order in which the fragments are added to the final file. Our /etc/hosts.allow file is built with the header line, the contents of the local file, and finally the in.tftpd line we defined.