
- Puppet 教程
- Puppet - 首頁
- Puppet 基礎
- Puppet - 概述
- Puppet - 架構
- Puppet - 安裝
- Puppet - 配置
- Puppet - 環境配置
- Puppet - Master(主控端)
- Puppet - Agent 設定(代理端設定)
- Puppet - SSL 證書設定
- r10K 的安裝與配置
- Puppet - 設定驗證
- Puppet - 編碼風格
- Puppet - 清單檔案(Manifest 檔案)
- Puppet - 模組
- Puppet - 檔案伺服器
- Puppet - Facter 和事實(Facts)
- 高階 Puppet
- Puppet - 資源
- Puppet - 資源抽象層
- Puppet - 模板
- Puppet - 類
- Puppet - 函式
- Puppet - 自定義函式
- Puppet - 環境
- Puppet - 型別和提供程式
- Puppet - RESTful API
- Puppet - 即時專案
- Puppet 有用資源
- Puppet - 快速指南
- Puppet - 有用資源
- Puppet - 討論
Puppet - 資源
資源是 Puppet 的關鍵基礎單元之一,用於設計和構建任何特定的基礎設施或機器。它們主要用於建模和維護系統配置。Puppet 有多種型別的資源,可用於定義系統架構,使用者也可以利用它們來構建和定義新的資源。
清單檔案或任何其他檔案中的 Puppet 程式碼塊稱為資源宣告。程式碼塊是用宣告式建模語言 (DML) 編寫的。下面是一個示例。
user { 'vipin': ensure => present, uid => '552', shell => '/bin/bash', home => '/home/vipin', }
在 Puppet 中,任何特定資源型別的資源宣告都在程式碼塊中完成。在下面的示例中,使用者主要由四個預定義的引數組成。
資源型別 - 在上面的程式碼片段中,它是使用者。
資源引數 - 在上面的程式碼片段中,它是 Vipin。
屬性 - 在上面的程式碼片段中,它是 ensure、uid、shell、home。
值 - 這些是與每個屬性對應的值。
每種資源型別都有自己定義定義和引數的方式,使用者有權選擇他希望資源的樣子。
資源型別
Puppet 中有不同型別的資源,它們具有自己的功能方式。可以使用“describe”命令和“-list”選項檢視這些資源型別。
[root@puppetmaster ~]# puppet describe --list These are the types known to puppet: augeas - Apply a change or an array of changes to the ... computer - Computer object management using DirectorySer ... cron - Installs and manages cron jobs exec - Executes external commands file - Manages files, including their content, owner ... filebucket - A repository for storing and retrieving file ... group - Manage groups host - Installs and manages host entries interface - This represents a router or switch interface k5login - Manage the ‘.k5login’ file for a user macauthorization - Manage the Mac OS X authorization database mailalias - .. no documentation .. maillist - Manage email lists mcx - MCX object management using DirectoryService ... mount - Manages mounted filesystems, including puttin ... nagios_command - The Nagios type command nagios_contact - The Nagios type contact nagios_contactgroup - The Nagios type contactgroup nagios_host - The Nagios type host nagios_hostdependency - The Nagios type hostdependency nagios_hostescalation - The Nagios type hostescalation nagios_hostextinfo - The Nagios type hostextinfo nagios_hostgroup - The Nagios type hostgroup nagios_service - The Nagios type service nagios_servicedependency - The Nagios type servicedependency nagios_serviceescalation - The Nagios type serviceescalation nagios_serviceextinfo - The Nagios type serviceextinfo nagios_servicegroup - The Nagios type servicegroup nagios_timeperiod - The Nagios type timeperiod notify - .. no documentation .. package - Manage packages resources - This is a metatype that can manage other reso ... router - .. no documentation .. schedule - Define schedules for Puppet scheduled_task - Installs and manages Windows Scheduled Tasks selboolean - Manages SELinux booleans on systems with SELi ... service - Manage running services ssh_authorized_key - Manages SSH authorized keys sshkey - Installs and manages ssh host keys stage - A resource type for creating new run stages tidy - Remove unwanted files based on specific crite ... user - Manage users vlan - .. no documentation .. whit - Whits are internal artifacts of Puppet's curr ... yumrepo - The client-side description of a yum reposito ... zfs - Manage zfs zone - Manages Solaris zones zpool - Manage zpools
資源標題
在上面的程式碼片段中,我們的資源標題是 vipin,它對於程式碼同一檔案中使用的每個資源都是唯一的。這是此使用者資源型別的唯一標題。我們不能擁有相同名稱的資源,因為這會導致衝突。
可以使用資源命令檢視使用型別 user 的所有資源的列表。
[root@puppetmaster ~]# puppet resource user user { 'abrt': ensure => 'present', gid => '173', home => '/etc/abrt', password => '!!', password_max_age => '-1', password_min_age => '-1', shell => '/sbin/nologin', uid => '173', } user { 'admin': ensure => 'present', comment => 'admin', gid => '444', groups => ['sys', 'admin'], home => '/var/admin', password => '*', password_max_age => '99999', password_min_age => '0', shell => '/sbin/nologin', uid => '55', } user { 'tomcat': ensure => 'present', comment => 'tomcat', gid => '100', home => '/var/www', password => '!!', password_max_age => '-1', password_min_age => '-1', shell => '/sbin/nologin', uid => '100', }
列出特定使用者的資源
[root@puppetmaster ~]# puppet resource user tomcat user { 'apache': ensure => 'present', comment => 'tomcat', gid => '100', home => '/var/www', password => '!!', password_max_age => '-1', password_min_age => '-1', shell => '/sbin/nologin', uid => '100’, }
屬性和值
任何資源的主體都是由屬性-值對的集合組成的。在這裡,可以為給定資源的屬性指定值。每種資源型別都有自己的一組可以使用鍵值對配置的屬性。
describe 子命令可用於獲取有關特定資源屬性的更多詳細資訊。在下面的示例中,我們有關於使用者資源及其所有可配置屬性的詳細資訊。
[root@puppetmaster ~]# puppet describe user user ==== Manage users. This type is mostly built to manage system users, so it is lacking some features useful for managing normal users. This resource type uses the prescribed native tools for creating groups and generally uses POSIX APIs for retrieving information about them. It does not directly modify ‘/etc/passwd’ or anything. **Autorequires:** If Puppet is managing the user's primary group (as provided in the ‘gid’ attribute), the user resource will autorequire that group. If Puppet is managing any role accounts corresponding to the user's roles, the user resource will autorequire those role accounts. Parameters ---------- - **allowdupe** Whether to allow duplicate UIDs. Defaults to ‘false’. Valid values are ‘true’, ‘false’, ‘yes’, ‘no’. - **attribute_membership** Whether specified attribute value pairs should be treated as the **complete list** (‘inclusive’) or the **minimum list** (‘minimum’) of attribute/value pairs for the user. Defaults to ‘minimum’. Valid values are ‘inclusive’, ‘minimum’. - **auths** The auths the user has. Multiple auths should be specified as an array. Requires features manages_solaris_rbac. - **comment** A description of the user. Generally the user's full name. - **ensure** The basic state that the object should be in. Valid values are ‘present’, ‘absent’, ‘role’. - **expiry** The expiry date for this user. Must be provided in a zero-padded YYYY-MM-DD format --- e.g. 2010-02-19. If you want to make sure the user account does never expire, you can pass the special value ‘absent’. Valid values are ‘absent’. Values can match ‘/^\d{4}-\d{2}-\d{2}$/’. Requires features manages_expiry. - **forcelocal** Forces the mangement of local accounts when accounts are also being managed by some other NSS - **gid** The user's primary group. Can be specified numerically or by name. This attribute is not supported on Windows systems; use the ‘groups’ attribute instead. (On Windows, designating a primary group is only meaningful for domain accounts, which Puppet does not currently manage.) - **groups** The groups to which the user belongs. The primary group should not be listed, and groups should be identified by name rather than by GID. Multiple groups should be specified as an array. - **home** The home directory of the user. The directory must be created separately and is not currently checked for existence. - **ia_load_module** The name of the I&A module to use to manage this user. Requires features manages_aix_lam. - **iterations** This is the number of iterations of a chained computation of the password hash (http://en.wikipedia.org/wiki/PBKDF2). This parameter is used in OS X. This field is required for managing passwords on OS X >= 10.8. Requires features manages_password_salt. - **key_membership** - **managehome** Whether to manage the home directory when managing the user. This will create the home directory when ‘ensure => present’, and delete the home directory when ‘ensure => absent’. Defaults to ‘false’. Valid values are ‘true’, ‘false’, ‘yes’, ‘no’. - **membership** Whether specified groups should be considered the **complete list** (‘inclusive’) or the **minimum list** (‘minimum’) of groups to which the user belongs. Defaults to ‘minimum’. Valid values are ‘inclusive’, ‘minimum’. - **name** The user name. While naming limitations vary by operating system, it is advisable to restrict names to the lowest common denominator, which is a maximum of 8 characters beginning with a letter. Note that Puppet considers user names to be case-sensitive, regardless of the platform's own rules; be sure to always use the same case when referring to a given user. - **password** The user's password, in whatever encrypted format the local system requires. * Most modern Unix-like systems use salted SHA1 password hashes. You can use Puppet's built-in ‘sha1’ function to generate a hash from a password. * Mac OS X 10.5 and 10.6 also use salted SHA1 hashes. Windows API for setting the password hash. [stdlib]: https://github.com/puppetlabs/puppetlabs-stdlib/ Be sure to enclose any value that includes a dollar sign ($) in single quotes (') to avoid accidental variable interpolation. Requires features manages_passwords. - **password_max_age** The maximum number of days a password may be used before it must be changed. Requires features manages_password_age. - **password_min_age** The minimum number of days a password must be used before it may be changed. Requires features manages_password_age. - **profile_membership** Whether specified roles should be treated as the **complete list** (‘inclusive’) or the **minimum list** (‘minimum’) of roles of which the user is a member. Defaults to ‘minimum’. Valid values are ‘inclusive’, ‘minimum’. - **profiles** The profiles the user has. Multiple profiles should be specified as an array. Requires features manages_solaris_rbac. - **project** The name of the project associated with a user. Requires features manages_solaris_rbac. - **uid** The user ID; must be specified numerically. If no user ID is specified when creating a new user, then one will be chosen automatically. This will likely result in the same user having different UIDs on different systems, which is not recommended. This is especially noteworthy when managing the same user on both Darwin and other platforms, since Puppet does UID generation on Darwin, but the underlying tools do so on other platforms. On Windows, this property is read-only and will return the user's security identifier (SID).
廣告