<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 指定資源的依賴關系 > Remove wrapper, open mouth, insert muffin, eat. > > — Instructions on 7-11 muffin packaging 為確保事物以正確的順序發生,你可以在 Puppet 中指定一個資源依賴另一個資源, 例如:你必須先安裝軟件包 X 然后再啟動它提供的服務,因此應該標記這項服務依賴于軟件包 X。 Puppet 會按要求的順序排出它遇到的所有依賴。 在一些配置管理系統中,資源按照你的書寫順序被應用,換句話說,資源被應用的順序是隱式的。 Puppet 則不是這種情況,資源或多或少以一種隨機(但一致)順序被應用, 除非你明確地使用依賴關系指出應用的順序。 一些人更喜歡隱式的方式,因為你可以按照你需要的執行順序書寫資源定義, 并且這就是它們被執行的方式。 另一方面,許多情況下資源的順序無關緊要。使用隱式風格的系統時, 你不能明確地告訴系統,資源 B 是否被寫在了資源 A 之后,由于資源 B 依賴于 A; 或者說書寫的順序是否正確,即資源 A 寫在了資源 B 之前。 這使得重構更加困難,因為移動資源有可能會打破一些隱式的依賴關系。 雖然 Puppet 會讓你多做一點兒工作,就是預先指定依賴關系, 但是這樣產生的代碼會更清晰且更易于維護。讓我們看一個例子。 #### 操作步驟 1. 使用如下的內容創建一個新文件 /etc/puppet/modules/admin/manifests/ntp.pp: ``` class admin::ntp { package { "ntp": ensure =&gt; installed, } service { "ntp": ensure =&gt; running, require =&gt; Package["ntp"], } file { "/etc/ntp.conf": source =&gt; "puppet:///modules/admin/ntp.conf", notify =&gt; Service["ntp"], require =&gt; Package["ntp"], } } ``` 2. 復制已經存在的 ntp.conf 文件到 Puppet 的如下目錄: ``` # cp /etc/ntp.conf /etc/puppet/modules/admin/files ``` 3. 在 nodes.pp 中將 admin::ntp 類添加到你的服務器: ``` node cookbook { include admin::ntp } ``` 4. 現在刪除系統中已存在的 ntp.conf 文件: ``` # rm /etc/ntp.conf ``` 5. 運行 Puppet: ``` # puppet agent --test info: Retrieving plugin info: Caching catalog for cookbook.bitfieldconsulting.com info: Applying configuration version '1302960655' notice: /Stage[main]/Admin::Ntp/File[/etc/ntp.conf]/ensure: defined content as '{md5}3386aaad98dd5e0b28428966dac9e1f5' info: /Stage[main]/Admin::Ntp/File[/etc/ntp.conf]: Scheduling refresh of Service[ntp] notice: /Stage[main]/Admin::Ntp/Service[ntp]: Triggered 'refresh' from 1 events notice: Finished catalog run in 2.36 seconds ``` #### 工作原理 在本例中演示了兩種類型的依賴: require 和 notify。在第一種情況中, ntp 服務要求 ntp 包資源首先被應用: ``` service { "ntp": ensure => running, require => Package["ntp"], } ``` 在第二種情況中,NTP 的配置文件設置成了 notify(通知)ntp 服務;換句話說, 一旦發現配置文件有變化,Puppet 就應該使用新的配置文件重新啟動 ntp 服務: ``` file { "/etc/ntp.conf": source => "puppet:///modules/admin/ntp.conf", notify => Service["ntp"], require => Package["ntp"], } ``` 這意味著服務依賴于配置文件以及所安裝的軟件包,Puppet 會按照如下的正確順序來應用這三個資源: ``` Package["ntp"] -> File["/etc/ntp.conf"] ~> Service["ntp"] ``` 事實上,這是指定相同依賴關系鏈的另一種方法。添加上面這行到你的配置清單中, 就會產生和上例中使用 require 和 notify 參數的同樣效果 (-&gt; 表示 require,~&gt; 表示 notify)。然而,我更喜歡使用 require 和 notify, 因為依賴關系被定義成了資源的一部分,因此更容易看清將會發生什么。 不過,對于復雜的依賴關系鏈,你可能想使用 -&gt; 符號來代替。 #### 更多用法 你也可以指定一個資源依賴于某個類: ``` require => Class["my-apt-repo"] ``` 你不僅可以指定資源和類之間的依賴關系,甚至可以指定 **collections** 之間的依賴關系: ``` Yumrepo <| |> -> Package <| provider == yum |> ``` 這是一種功能強大的表達方式,所有 provider 是 yum 的 package 資源被應用之前, 所有的 yumrepo 資源首先都應該被應用。 > ![注記](https://box.kancloud.cn/2016-05-12_5733eec619643.png) 歷史說明: > 在 Puppet 2.7 版本之前, 所有資源編目都以非確定性的方式被應用, 這意味著每次 Puppet 運行資源的順序都會不同。這可能會導致一些有趣的問題, 比如一個 Puppet 配置清單在一臺機器上能運行成功而在另一臺機器上卻運行失敗。 經過 Puppet Labs 的努力,現在這種情況已經不會發生。現在 Puppet 既保證可靠成功,又保證可靠失敗("either succeed reliably, or fail reliably")。 如果你還在使用早期版本并且遇到了這種問題,請更新到新版本。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看