Dependencies

如何使用 resolvconf/dnsmasq 安裝腳本解決我的依賴問題?

  • August 11, 2012

我有以下木偶模組:

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']
   }
}

但是,當我執行配置時,我收到以下錯誤:

錯誤:/階段

$$ main $$/Resolvconf/文件$$ /etc/resolvconf/resolv.conf.d/base $$/確保:從不存在更改為文件失敗:無法設置’文件確保:沒有這樣的文件或目錄 - /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

我需要在模組或清單中進行哪些更改以允許腳本第一次正確執行?

添加一行以要求文件資源中的包,如下所示:

file { '/etc/resolvconf/resolv.conf.d/base':
   ensure  => file,
   owner   => root,
   group   => root,
   content => '...
   require => Package['resolvconf'],
}

使用 require 基本上是強制 puppet 先執行包安裝。

這當然假設 resolvconf 包的安裝創建了所需的目錄,我相信它確實發生了。

引用自:https://serverfault.com/questions/416464