我在 Puppet Master 上有以下 list :
exec { 'DatabaseCreation':
command => '/usr/bin/mysqladmin -u root --password="system" create gitHandson'
}
当我跑
puppet agent --test
在 Puppet Agent 上,它给出了以下错误:Notice: /Stage[main]/Deployment/Exec[DatabaseCreation]/returns: /usr/bin/mysqladmin: CREATE DATABASE failed; error: 'Can't create database 'gitHandson'; database exists'
Error: /usr/bin/mysqladmin -u root --password="system" create gitHandson returned 1 instead of one of [0]
它应该忽略错误而不是给出错误。为此,我们在 Chef 中有“ignore_failure”,在 Ansible 中有“ignore_errors”。它的 Puppet 等价物是什么?
最佳答案
简短的回答:没有。 Puppet 资源必须成功,没有办法忽略错误。
最简单(也是 hackyiest)的解决方案是添加一个 && true
到您的命令末尾,因此它将返回 0 并且不会失败。
但是,exec 的问题在于它不是幂等的。 Puppet 是关于描述状态并确保事情只需要运行一次。
因此,对于您的示例,最好扩展 exec 以添加 unless
或 onlyif
参数,因此该命令仅在数据库不存在时运行。
exec { 'DatabaseCreation':
command => '/usr/bin/mysqladmin -u root --password="system" create gitHandson',
unless => 'Some command that exits 0 if the gitHandson database exists'
}
更多详情here.
更好 ,有一个Puppetlabs MySQL module ,它允许您安装 mysql、设置 root 密码和创建 MySQL 数据库。
例子:
mysql::db { 'mydb':
user => 'myuser',
password => 'mypass',
host => 'localhost',
grant => ['SELECT', 'UPDATE'],
}
关于puppet - 什么是 Puppet 相当于 Chef 中的 'ignore_failure' 或 Ansible 中的 'ignore_errors'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36077643/