我想避免(或至少隐藏)木偶上的“失败的依赖项”日志。
只有当 exec 要求为真时,我才想部署文件。它正在工作,但 puppet 显示了很多错误/警告日志:
Error: /usr/bin/test -e /home/USER returned 1 instead of one of [0]
Error: /Stage[main]/Users::Config/Exec[/usr/bin/test -e /home/USER]/returns: change from notrun to 0 failed: /usr/bin/test -e /home/USER returned 1 instead of one of [0]
Notice: /Stage[main]/Users::Config/Exec[check_ssh_dir]: Dependency Exec[/usr/bin/test -e /home/USER] has failures: true
Warning: /Stage[main]/Users::Config/Exec[check_ssh_dir]: Skipping because of failed dependencies
Notice: /Stage[main]/Users::Config/File[/home/USER/.ssh]: Dependency Exec[/usr/bin/test -e /home/USER] has failures: true
Warning: /Stage[main]/Users::Config/File[/home/USER/.ssh]: Skipping because of failed dependencies
Notice: /Stage[main]/Users::Config/File[/home/USER/.bashrc]: Dependency Exec[/usr/bin/test -e /home/USER] has failures: true
Warning: /Stage[main]/Users::Config/File[/home/USER/.bashrc]: Skipping because of failed dependencies
Notice: /Stage[main]/Users::Config/File[/home/USER/.bash_profile]: Dependency Exec[/usr/bin/test -e /home/USER] has failures: true
Warning: /Stage[main]/Users::Config/File[/home/USER/.bash_profile]: Skipping because of failed dependencies
Notice: /Stage[main]/Users::Config/File[/home/USER/.ssh/authorized_keys]: Dependency Exec[/usr/bin/test -e /home/USER] has failures: true
Warning: /Stage[main]/Users::Config/File[/home/USER/.ssh/authorized_keys]: Skipping because of failed dependencies
这是我的 config.pp :
class users::config ($user) {
exec {"/usr/bin/test -e /home/${user}":
}
exec {"check_ssh_dir":
command => '/bin/true',
onlyif => "/usr/bin/test -e /home/${user}/.ssh",
require => Exec["/usr/bin/test -e /home/${user}"],
}
file {"/home/${user}/.ssh":
ensure => directory,
owner => "${user}",
group => "domain users",
mode => "700",
require => Exec['check_ssh_dir'],
}
file {"/home/${user}/.bashrc":
source => [ "puppet:///modules/users/${user}/bashrc", "puppet:///modules/users/basics/bashrc"],
owner => "${user}",
group => "domain users",
mode => "640",
require => Exec["/usr/bin/test -e /home/${user}"],
}
file {"/home/${user}/.bash_profile":
source => [ "puppet:///modules/users/${user}/bash_profile", "puppet:///modules/users/basics/bash_profile"],
owner => "${user}",
group => "domain users",
mode => "640",
require => Exec["/usr/bin/test -e /home/${user}"],
}
file {"/home/${user}/.ssh/authorized_keys":
source => [ "puppet:///modules/users/${user}/ssh/authorized_keys", "puppet:///modules/users/basics/ssh/authorized_keys"],
owner => "${user}",
group => "domain users",
mode => "600",
require => Exec["check_ssh_dir"],
}
}
我正在使用木偶 4.3。
感谢您的帮助。
如果不使用事实或实现自定义提供程序,这实际上是不可能的。可以肯定的是,使用
exec
资源,您可以执行以下操作:但是您将无法根据
file
a 命令的结果获得条件资源。最简单的选择是创建一个事实。就像是:然后你可以检查是否在一个块
$user
的数组中。确保你没有。$::avail_users
if
stringify_facts
感谢@Artefacto,我找到了解决问题的方法:
我创建了一个仅列出房屋的新事实:
我已经修改了我的清单以在每个家庭上进行迭代:
现在我没有因为依赖而失败。