官术网_书友最值得收藏!

Using the create and destroy methods

The existence state of a resource is modified with reference to the declaration of the resource with the ensure property by the user in the Puppet DSL by using the create and destroy methods.

The create method is called when both of the following criteria have been met:

  • The ensure property has been set to present in the resource declaration
  • The false value is returned by the exists? method (to indicate that the resource doesn't already exist)

The destroy method is called when both of the following criteria have been met:

  • The ensure property has been set as absent in the resource declaration
  • The true value is returned by the exists? method (to indicate that the resource already exists)

The following code shows how you can use these methods:

Puppet::Type.type(:mynewtype).provide(:yum) do
...
def create
package=resource[:version] ?
“#{resource[:name]}-#{resource[:version]}]” : resource[:name]
yum(‘install', ‘-y, package')
end
...
def destroy
yum(‘erase', ‘-y', resource[:name])
end
...
end

主站蜘蛛池模板: 永泰县| 绵阳市| 建宁县| 屯昌县| 沁阳市| 大余县| 长子县| 屏南县| 莲花县| 津南区| 夏河县| 杭锦后旗| 宝鸡市| 尼勒克县| 武冈市| 紫金县| 上思县| 博白县| 洛南县| 五原县| 陵水| 绥滨县| 越西县| 淳化县| 乐昌市| 兴文县| 宜兰县| 金沙县| 临沂市| 淮南市| 景宁| 吉安县| 都兰县| 上犹县| 天等县| 镇宁| 凤山市| 隆尧县| 方山县| 寿光市| 玉林市|