# frozen_string_literal: true Puppet::Parser::Functions::newfunction( :defined, :type => :rvalue, :arity => -2, :doc => < present, } $is_defined_after = defined(File['/tmp/file']) # $is_defined_before returns false, but $is_defined_after returns true. ~~~ This order requirement only refers to evaluation order. The order of resources in the configuration graph (e.g. with `before` or `require`) does not affect the `defined` function's behavior. > **Warning:** Avoid relying on the result of the `defined` function in modules, as you > might not be able to guarantee the evaluation order well enough to produce consistent > results. This can cause other code that relies on the function's result to behave > inconsistently or fail. If you pass more than one argument to `defined`, the function returns `true` if _any_ of the arguments are defined. You can also match resources by type, allowing you to match conditions of different levels of specificity, such as whether a specific resource is of a specific data type. **Example**: Matching multiple resources and resources by different types with `defined` ~~~ puppet file { "/tmp/file1": ensure => file, } $tmp_file = file { "/tmp/file2": ensure => file, } # Each of these statements return `true` ... defined(File['/tmp/file1']) defined(File['/tmp/file1'],File['/tmp/file2']) defined(File['/tmp/file1'],File['/tmp/file2'],File['/tmp/file3']) # ... but this returns `false`. defined(File['/tmp/file3']) # Each of these statements returns `true` ... defined(Type[Resource['file','/tmp/file2']]) defined(Resource['file','/tmp/file2']) defined(File['/tmp/file2']) defined('$tmp_file') # ... but each of these returns `false`. defined(Type[Resource['exec','/tmp/file2']]) defined(Resource['exec','/tmp/file2']) defined(File['/tmp/file3']) defined('$tmp_file2') ~~~ - Since 2.7.0 - Since 3.6.0 variable reference and future parser types - Since 3.8.1 type specific requests with future parser - Since 4.0.0 includes all future parser features DOC ) do |vals| Puppet::Parser::Functions::Error.is4x('defined') end