我有以下人偶模块:
class resolvconf {
$packages = ['resolvconf', 'dnsmasq']
package { $packages: ensure => installed, }
file { '/etc/resolvconf/resolv.conf.d/base':
ensure => file,
owner => root,
group => root,
content => '
nameserver 127.0.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4',
}
service { 'dnsmasq':
require => Package[resolvconf],
ensure => running,
subscribe => File['/etc/resolvconf/resolv.conf.d/base']
}
}
但是,当我运行配置时,出现以下错误:
错误:/Stage[main]/Resolvconf/File[/etc/resolvconf/resolv.conf.d/base]/ensure:从不存在更改为文件失败:无法在确保上设置“文件:没有这样的文件或目录 - / etc/resolvconf/resolv.conf.d/base.puppettmp_4012 在/tmp/vagrant-puppet/modules-0/resolvconf/manifests/init.pp:13
我理解这意味着/etc/resolvconf/resolv.conf.d/base尚不存在,或无法创建。在多次重新配置或重新启动后,这个问题似乎最终会消失,所以它似乎是某种依赖问题,我可以使用适当的依赖或 exec 语句来解决。
此外,由于这个失败的依赖项,以下将无限期挂起:
notice: /Stage[main]/Resolvconf/Service[dnsmasq]: Dependency File[/etc/resolvconf/resolv.conf.d/base] has failures: true
warning: /Stage[main]/Resolvconf/Service[dnsmasq]: Skipping because of failed dependencies
或者至少直到我点击CTRL-C。
我需要在模块或清单中更改什么才能让脚本在第一次通过时正确运行?
添加一行以在文件资源中要求包,如下所示:
使用 require 基本上强制 puppet 首先执行包安装。
这当然假设 resolvconf 包的安装创建了所需的目录,我相信它确实发生了。