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

  • DevOps:Puppet,Docker,and Kubernetes
  • Thomas Uphill John Arundel Neependra Khare Hideto Saito Hui Chuan Chloe Lee Ke Jou Carol Hsu
  • 226字
  • 2021-07-09 18:32:53

Using arrays of resources

Anything that you can do to a resource, you can do to an array of resources. Use this idea to refactor your manifests to make them shorter and clearer.

How to do it…

Here are the steps to refactor using arrays of resources:

  1. Identify a class in your manifest where you have several instances of the same kind of resource, for example, packages:
      package { 'sudo' : ensure => installed }
      package { 'unzip' : ensure => installed }
      package { 'locate' : ensure => installed }
      package { 'lsof' : ensure => installed }
      package { 'cron' : ensure => installed }
      package { 'rubygems' : ensure => installed }
  2. Group them together and replace them with a single package resource using an array:
      package
      {
        [ 'cron',
        'locate',
        'lsof',
        'rubygems',
        'sudo',
        'unzip' ]:
        ensure => installed,
      }

How it works…

Most of Puppet's resource types can accept an array instead of a single name, and will create one instance for each of the elements in the array. All the parameters you provide for the resource (for example, ensure => installed) will be assigned to each of the new resource instances. This shorthand will only work when all the resources have the same attributes.

See also

  • The Iterating over multiple items recipe in Chapter 1, Puppet Language and Style
主站蜘蛛池模板: 涟水县| 泸西县| 海安县| 南丰县| 炉霍县| 荃湾区| 温宿县| 靖边县| 天水市| 凤台县| 马边| 南皮县| 冷水江市| 梁平县| 满洲里市| 错那县| 广德县| 红河县| 田林县| 西乡县| 济南市| 西盟| 响水县| 武清区| 滨州市| 全州县| 上林县| 平利县| 噶尔县| 阿图什市| 承德县| 大化| 正定县| 昭通市| 兴业县| 静乐县| 松潘县| 天峻县| 芦山县| 即墨市| 紫阳县|