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

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

主站蜘蛛池模板: 汝阳县| 家居| 秭归县| 昌黎县| 萨迦县| 永宁县| 突泉县| 同仁县| 濉溪县| 繁昌县| 莒南县| 湖州市| 砚山县| 河西区| 任丘市| 齐河县| 蓝山县| 亚东县| 开远市| 祁连县| 溧水县| 濮阳县| 阳信县| 肇庆市| 错那县| 息烽县| 谢通门县| 博野县| 永康市| 淮阳县| 鄄城县| 承德市| 海淀区| 财经| 宣武区| 凤凰县| 新泰市| 武宁县| 阳信县| 琼中| 靖西县|