puppet循环创建目录方法

业务需求:在特定目录下,判断某个目录是否存在,如果不存在就创建特定目录,存在啥事不做。不用DSL实现

site.pp文件定义,在/xx/7和/xx/8创建Recycle目录,如果存了Recycle,不覆盖

define mkdir_recycle() {
  file { "/xx/${title}/Recycle":
      ensure => directory,
      owner  => 'admin',
      group  => 'admin',
      mode   => 0775;
    }
}
mkdir_recycle{["7","8"]:}
 
# ls /xx/{7,8}/
/xx/7/:
 
/xx/8/:
 
puppet的日志:
notice: /Stage[main]//Mkdir_recycle[7]/File[/xx/7/Recycle]/ensure: created
notice: /Stage[main]//Mkdir_recycle[8]/File[/xx/8/Recycle]/ensure: created
notice: Finished catalog run in 0.05 seconds
 
# ls /xx/{7,8}/
/xx/7/:
Recycle
 
/xx/8/:
Recycle

Post a Comment