puppethiera

Puppet data array


I got a module that creating some directories depending of server:

class linux_sftp::sftp_mount ($sftp_mount_ip, $sftp_mount_username, $sftp_mount_password, $sftp_mount_point) {

  file { "/mnt/${sftp_mount_point}":
    ensure => directory,
    subscribe => Exec['sftp_remount'],
  }

in data.yml

sftp_mount_point: "stcontent1"

I want to add to data more folders like: stcontent2, stcontent3. Is it a way to add this and loop thru data?

sftp_mount_point: 
  - "stcontent1"
  - "stcontent2" ...

Solution

  • Yes you can use lambda method (can also be invoked as functions if desired) iteration to accomplish this task. The most common for your use case is each. It can be easily invoked on type Array[String] like you have in your question.

    $sftp_mount_point.each |String $mount| {
      file { "/mnt/${mount}":
        ensure => directory,
      }
    }
    

    Note that the file type does not have a subscribable property, so subscribe is not a valid attribute and I therefore removed it above.