- DevOps:Puppet,Docker,and Kubernetes
- Thomas Uphill John Arundel Neependra Khare Hideto Saito Hui Chuan Chloe Lee Ke Jou Carol Hsu
- 358字
- 2021-07-09 18:32:57
Using EPP templates
EPP templates are a new feature in Puppet 3.5 and newer versions. EPP templates use a syntax similar to ERB templates but are not compiled through Ruby. Two new functions are defined to call EPP templates, epp
, and inline_epp
. These functions are the EPP equivalents of the ERB functions template
and inline_template
, respectively. The main difference with EPP templates is that variables are referenced using the Puppet notation, $variable
instead of @variable
.
How to do it...
- Create an EPP template in
~/puppet/epp-test.epp
with the following content:This is <%= $message %>.
- Create an
epp.pp
manifest, which uses theepp
andinline_epp
functions:$message = "the message" file {'/tmp/epp-test': content => epp('/home/thomas/puppet/epp-test.epp') } notify {inline_epp('Also prints <%= $message %>'):}
- Apply the manifest making sure to use the future parser (the future parser is required for the
epp
andinline_epp
functions to be defined):t@mylaptop ~/puppet $ puppet apply epp.pp --parser=future Notice: Compiled catalog for mylaptop in environment production in 1.03 seconds Notice: /Stage[main]/Main/File[/tmp/epp-test]/ensure: defined content as '{md5}999ccc2507d79d50fae0775d69b63b8c' Notice: Also prints the message
- Verify that the template worked as intended:
t@mylaptop ~/puppet $ cat /tmp/epp-test This is the message.
How it works...
Using the future parser, the epp
and inline_epp
functions are defined. The main difference between EPP templates and ERB templates is that variables are referenced in the same way they are within Puppet manifests.
There's more...
Both epp
and inline_epp
allow for variables to be overridden within the function call. A second parameter to the function call can be used to specify values for variables used within the scope of the function call. For example, we can override the value of $message
with the following code:
file {'/tmp/epp-test': content => epp('/home/tuphill/puppet/epp-test.epp', { 'message' => "override $message"} ) } notify {inline_epp('Also prints <%= $message %>', { 'message' => "inline override $message"}):}
Now when we run Puppet and verify the output we see that the value of $message
has been overridden:
t@mylaptop ~/puppet $ puppet apply epp.pp --parser=future Notice: Compiled catalog for mylaptop.pan.costco.com in environment production in 0.85 seconds Notice: Also prints inline override the message Notice: Finished catalog run in 0.05 seconds t@mylaptop ~/puppet $ cat /tmp/epp-test This is override the message.
- Word 2003、Excel 2003、PowerPoint 2003上機(jī)指導(dǎo)與練習(xí)
- 輕輕松松自動(dòng)化測(cè)試
- Mastering Hadoop 3
- Mastering Spark for Data Science
- 火格局的時(shí)空變異及其在電網(wǎng)防火中的應(yīng)用
- PowerShell 3.0 Advanced Administration Handbook
- 計(jì)算機(jī)原理
- MicroPython Projects
- VMware Performance and Capacity Management(Second Edition)
- 計(jì)算機(jī)網(wǎng)絡(luò)技術(shù)實(shí)訓(xùn)
- Supervised Machine Learning with Python
- 網(wǎng)絡(luò)綜合布線設(shè)計(jì)與施工技術(shù)
- Practical Big Data Analytics
- 過(guò)程控制系統(tǒng)
- Linux內(nèi)核精析