- Extending Puppet(Second Edition)
- Alessandro Franceschi Jaime Soriano Pastor
- 502字
- 2021-07-02 16:29:53
Chapter 2. Managing Puppet Data with Hiera
The history of Puppet is an interesting example of how best practices have evolved with time, following new usage patterns and contributions from the community.
Once people started to write manifests with Puppet's DSL and express the desired state of their systems, they found themselves placing custom variables and parameters that expressed various resources of their infrastructures (IP addresses, hostnames, paths, URLs, names, properties, lists of objects, and so on) inside the code used to create the needed resource types.
At times, variables were used to classify and categorize nodes (systems' roles, operational environments, and so on), other times facts (such as $::operatingsystem
) were used to provide resources with the right names and paths according to the underlying OS.
Variables could be defined in different places; they could be set via an External Node Classifier (ENC), inside node declarations or inside classes.
There was not (and actually there isn't) any strict rule on how and where users data could be placed, but the general outcome was that we found ourselves having our custom data defined inside our manifests.
Now, in my very personal and definitely non-orthodox opinion, this is not necessarily or inherently a bad thing; looking at the data we provide when we define our resources gives us clearer visibility on how things are done and doesn't compel us to look in different places to understand what our code is doing.
Nevertheless, such an approach may fit relatively simple setups where we don't need to cope with large chunks of data, which might come from different sources and change a lot according to different factors.
Also, we might need to have different people working on Puppet—who write the code and design its logic and those who need to apply configurations, mostly dealing with data.
More generally, the concept of separating data from code is a well-established and sane development practice that also makes sense in the Puppet world.
The person who faced this issue in the most resolute way is R.I.Pienaar. First, he developed the extlookup
function (included in Puppet core for a long time), which allows to read data from external CSV files, then he took a further step—developing Hiera, a key-value lookup tool where data used by our manifests can be placed and evaluated differently according to a custom hierarchy from different data sources.
One of the greatest features of Hiera is its modular pluggable design that allows the usage of different backends that may retrieve data from different sources: YAML or JSON files, Puppet classes, MySQL, Redis, REST services, and more.
In this chapter, we will cover the following topics:
- Installing and configuring Hiera
- Defining custom hierarchies and backends
- Using the
hiera
command-line tool - Using the
hiera()
,hiera_array()
, andhiera_hash()
functions inside our Puppet manifests - Integrating Hiera in Puppet 3
- Providing files via Hiera with the
hiera-file
backend - Encrypting our data with the
hiera-gpg
andhiera-eyaml
backends - Using Hiera as an ENC with
hiera_include()
function
- Learning Real-time Processing with Spark Streaming
- .NET 4.0面向對象編程漫談:基礎篇
- Learning Data Mining with Python
- Python Data Analysis(Second Edition)
- C#程序設計
- 編程菜鳥學Python數據分析
- RealSenseTM互動開發實戰
- Scratch3.0趣味編程動手玩:比賽訓練營
- 細說Python編程:從入門到科學計算
- SQL Server 入門很輕松(微課超值版)
- Mastering jQuery Mobile
- Go語言從入門到精通
- 計算機系統解密:從理解計算機到編寫高效代碼
- Apache Solr for Indexing Data
- Swift 2 Design Patterns