Puppet 的管理美學 – Roles and Profiles Pattern

2017-04-09 Puppet

由於身處的環境有非常大量而且複雜的主機類型需要管理,任何事情在大量的時候就會產生管理的議題,要怎麼樣才能讓管理有好的方式是一個很重要的議題。

 

在一開始我們會針對每個 node 去寫應該要安裝的東西以及參數,但是如果數量多的時候就會發現有許多事情會重複做

 

例如:

node site01 {
  include user
  include apache
  include php
  include mysql
}

node site02 {
  include user
  include apache
  include node
}

node site03 {
  include user
  include nginx
  include mysql
}

這只是有 include module 的部份,如果機器複雜度很高,就會發現每個 node 會寫的很長,然後量一多的話就會很可怕

 

然後 Puppet 就提出了 Roles and Profiles 的管理方式,Puppet 也很賊,把這個文件寫在 Enterprise 這邊,Roles and Profiles 的概念也可以套用在非 Enterprise 這邊使用,對於管理有很大的幫助

 

在 PuppetConf 2016 也有簡報  PuppetConf 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, Puppet

 

  • Role 用來定義角色,如 NTP server, Jenkins Server, SAMBA Server .. 等等
  • Profile 用來定義每個資源,如 base, nginx, apache, php, ntp .. 等等

 

而 Roles 和 Profiles 實際上都是我們自行定義的 module。

 

如果今天必須建立一個 web server 組態設定

我會先定義 Profile,用來表示一組 “設定”、”服務”

class profile::user {
  include users
  include ntp
}

class profile::apache2 {
  class { 'apache':
    apache_version = '2.4',
  }
}

class profile::apache2::php {
  include profile::apache2
  include php
}

 

然後定義 Role,用來表示一個 “角色”

class role::webserver {
  include profile::user
  include profile::apache2::php
}

 

在 node 你就只需要 include role

node site {
  include role::webserver
}

 

然後參數就用 Hiera 來處理。

 

在這樣的設計概念下,你的 node 會變得很簡潔,而你的設定也能夠很彈性的調整,不用每個 node 寫的非常的複雜

 

在使用 Roles and Profiles 有一個很重要的觀念:

  • 一個 node 只 include 一個 role。如果這兩個 role 很像,但又有些微不同,那就是一個新 role。
  • 一個 role include 一個或多個 profile,而且 只能 include profile 。

 

以上,希望能夠在 Puppet 的使用上更加簡單好管理。

 

 

 

參考:

Roles and Profiles Pattern in Puppet

給 Mr. 沙先生一點建議

彙整

分類

展開全部 | 收合全部

License

訂閱 Mr. 沙先生 的文章

輸入你的 email 用於訂閱