官术网_书友最值得收藏!

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(), and hiera_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 and hiera-eyaml backends
  • Using Hiera as an ENC with hiera_include() function
主站蜘蛛池模板: 湟中县| 澜沧| 黄龙县| 霍城县| 铅山县| 清远市| 乌鲁木齐市| 淮安市| 安达市| 瑞金市| 兴山县| 夏津县| 水城县| 天柱县| 宝山区| 常州市| 安义县| 深泽县| 临夏市| 凤翔县| 德安县| 谢通门县| 郧西县| 海门市| 柳江县| 龙江县| 甘谷县| 桐城市| 台南县| 灵宝市| 垫江县| 崇明县| 育儿| 张家界市| 隆尧县| 姜堰市| 美姑县| 内丘县| 麦盖提县| 张家川| 清水县|