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

  • Mastering Puppet 5
  • Ryan Russell Yates Jason Southgate
  • 169字
  • 2021-07-16 17:46:18

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

主站蜘蛛池模板: 且末县| 辽宁省| 凉山| 陇川县| 新野县| 长宁区| 朝阳区| 松阳县| 远安县| 岚皋县| 辽中县| 德安县| 乌什县| 涞源县| 永善县| 富川| 通许县| 鹤峰县| 德保县| 和龙市| 永昌县| 浏阳市| 防城港市| 婺源县| 互助| 休宁县| 宾川县| 贵溪市| 阳曲县| 泰顺县| 海城市| 莱西市| 桦甸市| 宕昌县| 房产| 稻城县| 西盟| 利辛县| 沁阳市| 渭南市| 蒙阴县|