Puppet – Create a Custom Resource Type

We can define our own Puppet Resource Type. Here is an simple example which will takes create new folders from a existing folder.

class eureka::ykyuen ($new_folder) {
  define copy_folder {
    file { "/home/ykyuen/$name":
      source => "/home/ykyuen/src_folder",
      recurse => "true",
      group => "ykyuen",
      owner => "ykyuen",
      ensure  => directory,
      replace => "false", # Create new folder only if it doesn't exist
    }
  }

  copy_folder { ["new_folder_1", "new_folder_2"]: }
}

 

Please note that the $name parameters is a synonym of $title. After the Puppet apply, you could find the 2 new folders with name new_folder_1 and new_folder_2.

Done =)

Reference: Learning Puppet — Defined Types

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s