- Puppet 3 Cookbook
- John Arundel
- 530字
- 2021-04-09 23:52:27
Using standard naming conventions
Choosing appropriate and informative names for your modules and classes will be a big help when it comes to maintaining your code. This is even truer if other people need to read and work on your manifests.
How to do it…
Here are some tips on how to name things in your manifests:
- Name modules after the software or service they manage, for example,
apache
orhaproxy
. - Name classes within modules after the function or service they provide to the module, for example,
apache::vhosts
orrails::dependencies
. - If a class within a module disables the service provided by that module, name it
disabled
. For example, a class which disables Apache should be namedapache::disabled
. - If a node provides multiple services, have the node definition include one module or class named for each service, for example:
node 'server014' inherits 'server' { include puppet::server include mail::server include repo::gem include repo::apt include zabbix }
- The module that manages users should be named
user
. - Within the
user
module, declare your virtual users within the classuser::virtual
(for more about virtual users and other resources, see the Using virtual resources section in Chapter 5, Users and virtual resources). - Within the
user
module, subclasses for particular groups of users should be named after the group, for example,user::sysadmins
oruser::contractors
. - Where you need to override a class for some specific node or service, inherit that class and prefix the name of the subclass with the node, for example, if your node
cartman
needs a special SSH configuration, and you want to override thessh
class, perform the function as follows:class cartman_ssh inherits ssh { [ override config here ] }
- When using Puppet to deploy the config files for different services, name the file after the service, but with a suffix indicating what kind of file it is, for example:
- Apache init script:
apache.init
- Logrotate config snippet for Rails:
rails.logrotate
- Nginx vhost file for
mywizzoapp
:mywizzoapp.vhost.nginx
- MySQL config for standalone server:
standalone.mysql
- Apache init script:
- If you need to deploy a different version of a file depending on the operating system release, for example, you can use a naming convention like this one:
memcached.lucid.conf memcached.precise.conf
- You can have Puppet automatically select the appropriate version with:
source = > "puppet:///modules/memcached /memcached.${::lsbdistrelease}.conf",
- If you need to manage, for example, different Ruby versions, name the class after the version it is responsible for, for example,
ruby192
orruby186
.
There's more…
The Puppet community maintains a set of best practice guidelines for your Puppet infrastructure which includes some hints on naming conventions:
http://docs.puppetlabs.com/guides/best_practices.html
Some people prefer to include multiple classes on a node by using a comma-separated list, rather than separate include
statements, for example:
node 'server014' inherits 'server' { include mail::server, repo::gem, repo::apt, zabbix }
This is a matter of style, but I prefer to use separate include
statements, one to a line, because it makes it easier to copy and move around class inclusions between nodes, without having to tidy up the commas and indentation every time.
I mentioned inheritance in a couple of the preceding examples; if you're not sure what this is, don't worry, I'll explain this in detail in the next chapter.
- JBoss AS 5 Development
- 做好PPT就靠這幾招:圖解力+吸引力+說服力
- Midjourney AI繪畫藝術創作教程:關鍵詞設置、藝術家與風格應用175例
- Photoshop CC摳圖+修圖+調色+合成+特效標準培訓教程(全視頻微課版)
- BPEL Cookbook: Best Practices for SOA/based integration and composite applications development
- Authorware應用案例教程
- UG NX 9.0中文版基礎與實例教程
- Windows Phone 7 Silverlight Cookbook
- Photoshop圖形圖像處理實用教程
- PHP應用開發與實踐
- 零基礎學數碼攝影后期
- SolidWorks快速入門教程(2022中文版)
- 零基礎學會聲會影2018(全視頻教學版)
- 神奇的中文版Photoshop CC 2017入門書
- Photoshop+CorelDRAW 字體設計與創意:草圖/實現/包裝(微課版)