我有以下 Puppet 模块:
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 at /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。
我需要在模块或清单中进行哪些更改才能使脚本第一次正确运行?
答案1
在文件资源中添加一行来要求包,如下所示:
file { '/etc/resolvconf/resolv.conf.d/base':
ensure => file,
owner => root,
group => root,
content => '...
require => Package['resolvconf'],
}
首先使用需要强制的 puppet 来执行包安装。
当然,这假设 resolvconf 包的安装会创建所需的目录,我相信确实会发生这种情况。