Search code examples
puppet

Create multiple directory via Puppet


How do I create multiple file via Puppet?

For example I can run:

touch abc{1,2,3,4,5,6,7,8} to create abc1,abc2,abc3....abc8

How do I run the same via Puppet?


Solution

  • At its simplest, you can specify a list of files by passing an array to a file resource:

    $numbered_files = ["/abc1", "/abc2", "/abc3"]
    file { $numbered_files:
      ensure => file,
    }
    

    To automatically build an array of filenames with a certain prefix, then the range function from stdlib can do this trivially:

    $numbered_files = range("/abc1", "/abc8")
    file { $numbered_files:
      ensure => file,
    }