How to iterate over an array in Puppet

后端 未结 6 1760
南旧
南旧 2020-12-13 10:11

I would like to iterate over an array that is stored as a Facter fact, and for each element of the array create a new system user and a directory, and finally make API calls

6条回答
  •  失恋的感觉
    2020-12-13 10:34

    This might work, depending on what you are doing

    # Assuming fact my_env => [ shared1, shared2, shared3 ]
    
    define my_resource {
      file { "/var/tmp/$name":
        ensure => directory,
        mode   => '0600',
      }
      user { $name:
        ensure => present,
      }
    }
    my_resource { $my_env: }
    

    It will work if your requirements are simple, if not, Puppet makes this very hard to do. The Puppet developers have irrational prejudices against iteration based on a misunderstanding about how declarative languages work.

    If this kind of resource doesn't work for you, perhaps you could give a better idea of which resource properties you are trying to set from your array?

    EDIT:

    With Puppet 4, this lamentable flaw was finally fixed. Current state of affairs documented here. As the documentation says, you'll find examples of the above solution in a lot of old code.

提交回复
热议问题