0

我让 Hiera 与 puppet/vagrant 结合运行。

假设我有一个木偶执行官在做以下事情

      exec { create-project-database:
    command => 'mysql -u root -e "CREATE DATABASE project_db DEFAULT CHARACTER SET = \'utf8\';"',
    unless  => 'mysql -u root information_schema -e "select * from information_schema.schemata;" | grep "project_db"',
    require => Package[mysql-server],
  }

我想用"project_db"common.yaml的 hiera中的变量替换字符串

---
machine_message: 'This is the dev machine!'
codes_path: '/vagrant/code/laravel/'
project_db: 'project_db'

我该怎么做?语法对我来说不清楚,这样的事情会带来错误:

    command => 'mysql -u root -e "CREATE DATABASE 'hiera('project_db)' DEFAULT CHARACTER SET = \'utf8\';"',
4

1 回答 1

1

你的引号有问题'hiera('project_db)'(即你没有在括号前结束,所以hiera('project_db')应该是正确的)

通常我之前确实从 hiera 声明变量,所以像这样

$DB_NAME = hiera('project_db')
exec { create-project-database:
  command => "mysql -u root -e \"CREATE DATABASE $DB_NAME DEFAULT CHARACTER SET = 'utf8';\"",
  unless  => 'mysql -u root information_schema -e "select * from information_schema.schemata;" | grep "project_db"',
  require => Package[mysql-server],
}
于 2015-09-08T07:39:30.810 回答