puppet简单的custum type

1./etc/puppet/puppet.conf 文件

添加

[main]
pluginsync = true


2.创建一个module

# cd /etc/puppet/modules
# mkdir custom


3.创建lib文件夹

# cd custom
# mkdir -p lib/puppet/type


4.在type目录下面创建一个文件,文件名wws.rb。内容如下:

Puppet::Type.newtype(:wws) do
    ensurable
    newparam(:source) do
        isnamevar
    end
    newparam(:path) do
    end
end

如何工作的:

Puppet::Type.newtype(:wws) do

注册一个type


ensurable

ensurable函数,让type有一个ensure属性。


newparam(:source) do
     isnamevar
end

设置一些参数。就目前而言,我们设置了一个Git源URL和路径参数的参数,告诉puppet应建立在文件系统中。



5.创建provider

# mkdir -p lib/puppet/provider/wws

创建wws.rb文件 内容如下

Puppet::Type.type(:wws).provide(:wws) do
    def create
        p  resource[:source]
    end
    def exists?
        p  resource[:source]
    end

    def  destroy

    end

end

如何工作的:

Puppet::Type.type(:wws).provide(:wws) do

为wws这个type定义一个provider


 def exists?
        p  resource[:source]
 end

当你声明一个实例的类型在你的manifest中,puppet首先检查该实例是否已经存在,也就是调用exists?这个方法,如果返回true说明存在。


def create
        p  resource[:source]
end
如果存在的话吗?返回true,则的puppet不会采取任何进一步的行动。如果不是,puppet尽量通过调用create方法创建资源.这与你ensure设置的值有关,如是设置absent,则表示相反。返回存在,则调用destroy,不存在则不调用。


6.编写site.pp文件

node default{
        wws { "git://github.com/puppetlabs/puppet.git":
                path => "/home/john/work/puppet",

                ensure => present,

        }
}
这样就能使用自己定义的type。

7.重要注意点

Custom Type & Provider development

err: Could not retrieve catalog: Invalid parameter ‘foo’ for type ‘bar’


When you are developing new custom types, you should restart boththe puppetmasterd and the puppetd before running the configurationusing the new custom type. The pluginsync feature will thensynchronise the files and the new code will be loaded when bothdaemons are restarted.

大概意思是:当重新添加了param,需要重启master,否则会报错
下载链接

http://download.csdn.net/detail/a420478805/4522533

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值