我让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
中的变量---
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';"',
您在'hiera('project_db)'
中的引号有问题(即您在括号之前没有关闭,因此hiera('project_db')
应该是正确的)
通常我之前会从层次中声明变量所以像这样
$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],
}