簡體   English   中英

在Ubuntu 11.04上安裝Nginx 1.0.5時如何使用Puppet依賴項

[英]How to work with Puppet dependencies when installing Nginx 1.0.5 on Ubuntu 11.04

我是Puppet的新手,對使用依賴項有疑問。

我正在使用Puppet在Ubuntu 11.04上安裝Nginx 1.0.5。 它需要添加一個新的apt存儲庫,因為natty通常帶有Nginx 0.8。 在命令行,安裝如下:

# apt-get install python-software-properties
# add-apt-repository ppa:nginx/stable
# apt-get update
# apt-get install nginx

所以我寫了這個Puppet腳本:

class nginx::install {
  package { "nginx":
    ensure => present,
    require => Exec["nginx_repository"],
  }

  exec { "add-apt-repository ppa:nginx/stable && apt-get update":
    alias => "nginx_repository",
    require => Package["python-software-properties"],
  }

  package { "python-software-properties":
    ensure => installed,
  }
}

該腳本有效,但exec {}指令每次都運行,而不是僅在實際安裝nginx時運行。 理想情況下,我希望“apt”命令只能在實際的nginx安裝之前運行,而不是在簡單地檢查nginx安裝時。

我對通知/訂閱模型有基本的了解,但我不確定如何讓nginx指令僅在實際安裝nginx時發送“通知”信號。

以下是解決此問題的兩種方法:

1)

exec { "add-apt-repository ppa:nginx/stable && apt-get update":
    alias => "nginx_repository",
    require => Package["python-software-properties"],
    creates => "/etc/apt/sources.list.d/nginx-stable-natty.list",
}

這將告訴exec僅在該文件不存在時才運行。 如果還有其他方法可以檢查exec是否已成功運行,則可以使用onlyif =>unless =>來指定要檢查的命令。

2)

  exec { "add-apt-repository ppa:nginx/stable && apt-get update":
    alias => "nginx_repository",
    require => Package["python-software-properties"],
    refreshonly => true,
    subscribe => Package["python-software-properties"],
  }

這將告訴exec僅在通知時才運行,並將告訴該程序包通知exec它應該運行。 (您可以在python-software-properties包節中指定notify => Exec["nginx_repository"] ;通知對關系一端的影響與關系另一端的訂閱相同。)

第二種方法的缺點是,如果出現任何問題,木偶將永遠不會弄明白,如果包裝是通過其他方式安裝而不是通過木偶規則(例如作為依賴性在其他地方拉入),它將永遠不會運行exec (並且nginx包安裝將繼續失敗)。

換句話說,讓執行官有一些檢查它是否已經運行的方法是非常可取的。

您可以通過使用Facter變量lsbdistcodename來確保版本獨立性,如以下對freiheit代碼中的creates屬性的修改:

exec { "add-apt-repository ppa:nginx/stable && apt-get update":
  alias => "nginx_repository",
  require => Package["python-software-properties"],
  creates => "/etc/apt/sources.list.d/nginx-stable-${lsbdistcodename}.list",
}

對於Ubuntu 12.04 Lucid,這擴展到:

creates => "/etc/apt/sources.list.d/nginx-stable-lucid.list",

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM