Puppet Function: simplib::assert_metadata

Defined in:
functions/assert_metadata.pp
Function type:
Puppet Language

Overview

simplib::assert_metadata(String[1] $module_name, Optional[Struct[{ enable => Optional[Boolean], os => Optional[Struct[{ validate => Optional[Boolean], options => Optional[Struct[{ release_match => Enum['none','full','major'] }]] }]] }]] $options = simplib::lookup('simplib::assert_metadata::options', { 'default_value' => undef }))None

Fails a compile if the client system is not compatible with the module’s ‘metadata.json`

NOTE: New capabilities will be added to the simplib::module_metadata::assert function instead of here but this will remain to preserve backwards compatibility

Parameters:

  • module_name (String[1])

    The name of the module that should be checked

  • options (Optional[Struct[{ enable => Optional[Boolean], os => Optional[Struct[{ validate => Optional[Boolean], options => Optional[Struct[{ release_match => Enum['none','full','major'] }]] }]] }]]) (defaults to: simplib::lookup('simplib::assert_metadata::options', { 'default_value' => undef }))

    Behavior modifiers for the function

    • Can be set using ‘simplib::assert_metadata::options` in the `lookup` stack

    Options

    • enable => If set to ‘false` disable all validation

    • os

      * validate => Whether or not to validate the OS settings
      * options
          * release_match
            * none  -> No match on minor release (default)
            * full  -> Full release must match
            * major -> Only the major release must match
      

Returns:

  • (None)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'functions/assert_metadata.pp', line 29

function simplib::assert_metadata (
  String[1] $module_name,
  Optional[Struct[{
    enable    => Optional[Boolean],
    os        => Optional[Struct[{
      validate => Optional[Boolean],
      options  => Optional[Struct[{
        release_match => Enum['none','full','major']
      }]]
    }]]
  }]]       $options = simplib::lookup('simplib::assert_metadata::options', { 'default_value' => undef }),
) {

  $_default_options = {
    'enable'    => true,
    'os'        => {
      'validate' => true,
      'options'  => {
        'release_match' => 'none'
      }
    }
  }

  if $options {
    $_tmp_options = deep_merge($_default_options, $options)
  }
  else {
    $_tmp_options = $_default_options
  }

  $_options = {
    'enable'        => $_tmp_options['enable'],
    'os_validation' => {
      'enable'  => $_tmp_options['os']['validate'],
      'options' => $_tmp_options['os']['options']
    }
  }

  if $_options['enable'] {
    $_module_metadata = load_module_metadata($module_name)

    if empty($_module_metadata) {
      fail("Could not find metadata for module '${module_name}'")
    }

    if $_options['os_validation']['enable'] {
      unless simplib::module_metadata::os_supported($_module_metadata, $_options['os_validation']['options']) {
        fail("OS '${facts['os']['name']} ${facts['os']['release']['full']}' is not supported by '${module_name}'")
      }
    }
  }
}