我在一个独立的系统上探索木偶,并且为了MySQL而复制一个configuration文件进入墙壁。 使用下面的清单,MySQL被安装,但my.cnf文件不被复制。
init.pp(主机名:dev_one.site.com)
class mysql { case $servername { "prod_one.site.com", "dev_one.site.com", "sandbox_one.site.com": { $conf_file = 'my.cnf.one' } "prod_two.site.com", "dev_two.site.com", "sandbox_two.site.com": { $conf_file = 'my.cnf.two' } } package { "mysql-server": ensure => present, } package { "mysql": ensure => present, } file { 'my.cnf': path => '/etc/', ensure => file, require => Package['mysql'], source => "puppet:///modules/mysql/${conf_file}" } service { "mysqld": ensure => running, enable => true, require => Package["mysql-server"] } }
结果如下:
[root@dev_one manifests]# puppet apply --verbose ./init.pp Info: Applying configuration version '1379018555' Notice: /Stage[main]/Mysql/Package[mysql-server]/ensure: created Notice: /Stage[main]/Mysql/Service[mysqld]/ensure: ensure changed 'stopped' to 'running' Info: /Stage[main]/Mysql/Service[mysqld]: Unscheduling refresh on Service[mysqld] Notice: Finished catalog run in 14.34 seconds [root@dev_one manifests]# ll /etc/my* total 0
没有错误,但my.cnf不被复制。 我究竟做错了什么?
首先, $servername被设置在哪里? 这不是一个标准的事实,所以要有内容,你需要有一个自定义的事实或清单variables。 你想要使用$clientcert或$fqdn吗?
在你的file资源..我想这应该是错误的,但也许不是,因为/etc/ exists ..问题是有声明的资源正试图pipe理/etc/而不是/etc/my.cnf 。 请在资源名称中声明文件的完整path,并省略path参数:
file { '/etc/my.cnf':
或者,将path参数设置为文件的完整path(名称无关紧要):
file { 'MySQL Config': path => '/etc/my.cnf',
但是..我真的build议不要在您的清单中硬编码“这个服务器得到哪个configuration文件”的逻辑。 改为使用具有参数化类的Hiera或节点定义。