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

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

主站蜘蛛池模板: 龙门县| 安陆市| 九龙坡区| 沙洋县| 平塘县| 新竹县| 苏尼特右旗| 寿阳县| 洮南市| 城口县| 鸡泽县| 海伦市| 阿坝| 神农架林区| 锦州市| 高邑县| 夏邑县| 延庆县| 荥经县| 东丰县| 郸城县| 镇赉县| 盈江县| 东兴市| 万载县| 普安县| 寿阳县| 武夷山市| 洱源县| 金平| 乌拉特中旗| 慈利县| 屏山县| 巴里| 江川县| 万荣县| 日照市| 常德市| 武乡县| 金坛市| 云和县|