0

我想使用现有的木偶模块在服务器上提供多组东西,最简单的例子是:

file { "/var/www/MYVARIABLEHERE":
    ensure => "directory",
}
mysql::db { MYVARIABLEHERE:
    user     => MYVARIABLEHERE,
    password => MYVARIABLEHERE,
    host     => 'localhost',
    grant    => ['all'],
}

有没有办法把它抽象出来,这样我就可以说一组预定义的选项,然后将它们传递到现有的 puppet 模块中,这样我就不会得到一个数千行长的清单文件?

根据下面的答案,我已经设置:

define mySites {
  mysql::db { $name:
    user     => $name,
    password => $name,
    host     => 'localhost',
    grant    => ['all'],
  }

  file { "/var/www/${name}.drupal.dev":
    ensure => "directory",
  }
}

然后我打电话给:

mySites {"site": $name => "test", }

并得到以下错误:

Could not parse for environment production: Syntax error at 'name'; expected '}'
4

1 回答 1

1

您可以使用一种define类型来简化:

define mydef( $usern, $passn) {
  file { "/var/www/$usern":
     ensure => "directory",
  }
  mysql::db { $usern :
      user => $usern,
      password => $passn,
      host => "localhost",
      grant => ['all'],
  }
}

# You have to call the define type for each cases.
mydef{"u1": usern => "john", password => "pass", }

# It might be possible to provide multiple arrays to a define
# type if you use puppet's future parser
于 2013-08-30T18:40:51.583 回答