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

  • 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
主站蜘蛛池模板: 当雄县| 邵阳县| 孙吴县| 嘉黎县| 朝阳县| 碌曲县| 思茅市| 陇南市| 康定县| 股票| 湖南省| 乐业县| 阳新县| 乌什县| 凤翔县| 桑日县| 万年县| 修文县| 晋城| 平江县| 阜南县| 德昌县| 米林县| 那坡县| 阿尔山市| 彰武县| 昭觉县| 新营市| 雅安市| 灵台县| 河东区| 将乐县| 北流市| 潼南县| 孟州市| 霸州市| 滕州市| 深圳市| 吉安市| 合肥市| 英德市|