我让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],
}
我想用my "project_db"
中的变量替换字符串common.yaml
---
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\';"',
答案 0 :(得分: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],
}