- Puppet 5 Essentials(Third Edition)
- Martin Alfke Felix Frank
- 281字
- 2021-07-02 18:22:22
Variable types
As of Puppet 3.x, there are only four variable types: strings, arrays, hashes, and Booleans. Puppet 4 introduces a rich data type system. The new data type system will be explained at the end of, Chapter 7, New Features from Puppet 4 and 5. The basic variable types work much like their respective counterparts in other languages. Depending on your background, you might be familiar with using associative arrays or dictionaries as semantic equivalents to Puppet's hash type:
$a_bool = true
$a_string = 'This is a string value'
$an_array = [ 'This', 'forms', 'an', 'array' ]
$a_hash = {
'subject' => 'Hashes',
'predicate' => 'are written',
'object' => 'like this',
'note' => 'not actual grammar!',
'also note' => [ 'nesting is',
{ 'allowed' => ' of course' } ],
}
Accessing the values is equally simple. Note that the hash syntax is similar to that of Ruby, not Perl:
$x = $a_string
$y = $an_array[1]
$z = $a_hash['object']
Strings can be used as resource attribute values, but it's worth noting that a resource title can also be a variable reference:
package { $apache_package:
ensure => 'installed'
}
It's intuitively clear what a string value means in this context. But you can also pass arrays here to declare a whole set of resources in one statement. The following manifest manages three packages, making sure that they are all installed:
$packages = [
'apache2',
'libapache2-mod-php5',
'libapache2-mod-passenger',
]
package { $packages:
ensure => 'installed'
}
You will learn how to make efficient use of hash values in later chapters.
The array does not need to be stored in a variable to be used, but it is a good practice in some cases.
- Dynamics 365 for Finance and Operations Development Cookbook(Fourth Edition)
- Hands-On JavaScript High Performance
- Building Cross-Platform Desktop Applications with Electron
- 差分進化算法及其高維多目標優化應用
- 微信公眾平臺開發:從零基礎到ThinkPHP5高性能框架實踐
- Mastering AndEngine Game Development
- MongoDB權威指南(第3版)
- 從Excel到Python:用Python輕松處理Excel數據(第2版)
- 劍指大數據:企業級數據倉庫項目實戰(在線教育版)
- 零基礎學C語言第2版
- Hands-On Kubernetes on Windows
- 從0到1:HTML5 Canvas動畫開發
- Angular Design Patterns
- Vue.js 3.x高效前端開發(視頻教學版)
- HTML5 Game Development by Example:Beginner's Guide(Second Edition)