are there iterators and loops in puppet?

后端 未结 4 787
渐次进展
渐次进展 2020-12-23 14:06

When I define(?) a resource e.g. to ensure dir structure, are there any loops available?

Like that:

  for X in [app1,app2] do:
    file { \'/opt/app/         


        
4条回答
  •  清歌不尽
    2020-12-23 14:32

    Yes. "Ruby DSL" could help, just use file extension ".rb" instead of ".pp" in manifest and you can define puppet "type" like this:

    define 'myapps::structure', :applist do
       @applist.each do |app|
           file( @name+'/'+app, 
                 :ensure => directory,
                 :owner  => 'root',
                 :group  => 'root',
                 :mode   => '0644')
       end
    end
    

    Classes and nodes also can be defined in similar way. Notice however that this feature is deprecated since release 3

提交回复
热议问题