comparison modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb @ 275:d9352a684e62

Mass update of modules to remove deprecation warnings
author IBBoard <dev@ibboard.co.uk>
date Sun, 26 Jan 2020 11:36:07 +0000
parents c42fb28cff86
children adf6fe9bbc17
comparison
equal deleted inserted replaced
274:b2571c28fc27 275:d9352a684e62
1 # Test whether a given class or definition is defined 1 # Test whether a given class or definition is defined
2 require 'puppet/parser/functions' 2 require 'puppet/parser/functions'
3 3
4 Puppet::Parser::Functions.newfunction(:ensure_resource, 4 Puppet::Parser::Functions.newfunction(:ensure_resource,
5 :type => :statement, 5 :type => :statement,
6 :doc => <<-'DOC' 6 :doc => <<-DOC
7 @summary
7 Takes a resource type, title, and a list of attributes that describe a 8 Takes a resource type, title, and a list of attributes that describe a
8 resource. 9 resource.
9 10
10 user { 'dan': 11 user { 'dan':
11 ensure => present, 12 ensure => present,
12 } 13 }
13 14
14 This example only creates the resource if it does not already exist: 15 @return
16 created or recreated the passed resource with the passed type and attributes
15 17
16 ensure_resource('user', 'dan', {'ensure' => 'present' }) 18 @example Example usage
19
20 Creates the resource if it does not already exist:
21
22 ensure_resource('user', 'dan', {'ensure' => 'present' })
17 23
18 If the resource already exists but does not match the specified parameters, 24 If the resource already exists but does not match the specified parameters,
19 this function will attempt to recreate the resource leading to a duplicate 25 this function will attempt to recreate the resource leading to a duplicate
20 resource definition error. 26 resource definition error.
21 27
22 An array of resources can also be passed in and each will be created with 28 An array of resources can also be passed in and each will be created with
23 the type and parameters specified if it doesn't already exist. 29 the type and parameters specified if it doesn't already exist.
24 30
25 ensure_resource('user', ['dan','alex'], {'ensure' => 'present'}) 31 ensure_resource('user', ['dan','alex'], {'ensure' => 'present'})
26 32
27 DOC 33 DOC
28 ) do |vals| 34 ) do |vals|
29 type, title, params = vals 35 type, title, params = vals
30 raise(ArgumentError, 'Must specify a type') unless type 36 raise(ArgumentError, 'Must specify a type') unless type