一、模板的应用
到目前为止,资源申报、定义类、声明类等所有功能都只能一个manifest文件中实现,但这却非有效的基于puppet管理IT资源架构的方式。实践 中,一般需要把manifest文件分解成易于理解的结构,例如将类文件、配置文件甚至包括后面讲提到的模板文件等分类存放,并且通过某种机制在...
时间 : 2013-06-09|
栏目 : linux运维|
浏览 : 946 次|
暂无评论
标签:content =>template('nginx/conf.erb'), enable => true, files, lib} [root@node1 ~]# cd /etc/puppet/modules/nginx/ [root@node1 nginx]# cd manifests/ [root@node1 manifests]# vi init.pp class nginx { package {'nginx': ensure => installed, name => nginx, notify => Service['nginx'], path => '/etc/nginx/nginx.conf', puppet自动化运维精讲, require => Package['nginx'], require => Package['nginx'] } } [root@node1 manifests]# puppet apply -e 'include nginx::web' notice: /Stage[main]/Nginx/Package[nginx]/ensure: created notice: /Stage[main]/Nginx::Web/File[web.conf], require => Package['nginx'] } } [root@node1 manifests]# puppet apply -e 'include nginx::web' notice: /Stage[main]/Nginx/Package[nginx]/ensure: created notice: /Stage[main]/Nginx::Web/Service[nginx], source => "puppet:///modules/nginx/web.conf", templates, } file{'web.conf': ensure =>file, } } [root@node1 manifests]# vi web.pp class nginx::web inherits nginx { service {'nginx': ensure => true, 一, 关于模板文件详细信息,后文有介绍 tests目录:当前模板的使用帮助或使用范例文件,类似如何声明当前模板中的类及定义的类型等 spec目录:类似于tests目录的功能,只不过,其是为lib目录定义的各插件提供使用范例的 复制代码 [root@node1 ~]# mkdir -p /etc/puppet/modules/nginx/{manifests, 声明类等所有功能都只能一个manifest文件中实现,但这却非有效的基于puppet管理IT资源架构的方式。实践 中,一般需要把manifest文件分解成易于理解的结构,例如将类文件, 定义类, 层次化的方式使用puppet,而puppet则基于“模块自动装载器”完成模块装载 从另一个角度来说,模板实际上就是一个按约定的, 数字和下划线,但不能使用“main”和“settings”作为模块名 manifests目录:包含当前模块的所有manifest文件:每个manifest文件包含了一个类或一个定义的类型,此文件访问路径格式为“Modulename::[SubDirectoryName::]ManifestFileName”。 init.pp:只能包含一个单独的类定义,且类的名称必须与模块名称相同 files目录:, 模板的应用 到目前为止,资源申报, 设定变量以及在输出之前对数据进行处理 :注释信息 <%%: 输出:输出%> 如上面的案例,在使用模板后 复制代码 [root@node1 manifests]# cp /etc/puppet/modules/nginx/files/web.conf /etc/puppet/modules/nginx/templates/conf.erb [root@node1 manifests]# , 配置文件甚至包括后面讲提到的模板文件等分类存放,并且通过某种机制在必要时将 他们整合起来。这种机制即成为“模板”,它有助于结构化, 预定义的机构存放了多个文件或子目录的目录,目录里的这些文件或子目录必须遵循其命名规范。 puppet会按照这种规范在特定位置查找所需的模块文件,不过,这些特定目录页可以通过puppet的配置参数modulepath定义 只要在某模块中定于了一个类,就可以在任何manifest文件中使用它,puppet会自动去查找并装载包含了这个类的定义的manifest文件任 意使用它们。于是,基于模块机制的pu
|
[阅读全文] |