Defined Type: sensu::write_json

Defined in:
manifests/write_json.pp

Summary

Writes arbitrary hash data to a config file.

Overview

Writes arbitrary hash data to a config file. Note: you must manually notify any Sensu services to restart them when using this defined resource type.

[notify_list] Array. A listing of resources to notify upon changes to the target JSON file. Default: []

Examples:

sensu::write_json { '/etc/sensu/conf.d/check.json':
  content => {"config" => {"key" => "value"}},
  notify  => [
    Service['sensu-client'],
    Service['sensu-server'],
  ],
}

Parameters:

  • ensure (Enum['present', 'absent']) (defaults to: 'present')

    Whether the file should be present or not.

  • owner (String) (defaults to: 'sensu')

    The file owner.

  • group (String) (defaults to: 'sensu')

    The file group.

  • mode (Stdlib::Filemode) (defaults to: '0775')

    The file mode.

  • pretty (Boolean) (defaults to: true)

    Write the json with "pretty" indenting & formating.

  • content (Hash) (defaults to: {})

    The hash content that will be converted to json and written into the target config file.

  • notify_list (Array[Variant[Data,Type]]) (defaults to: [])


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
# File 'manifests/write_json.pp', line 32

define sensu::write_json (
  Enum['present', 'absent'] $ensure = 'present',
  String                    $owner = 'sensu',
  String                    $group = 'sensu',
  Stdlib::Filemode          $mode = '0775',
  Boolean                   $pretty = true,
  Hash                      $content = {},
  Array[Variant[Data,Type]] $notify_list = [],
) {

  # ensure we have a properly formatted file path for our target OS
  case $::kernel {
    'windows': {
      assert_type(Stdlib::Windowspath, $title)
    }
    default: {
      assert_type(Stdlib::Unixpath, $title)
    }
  }

  # Write the config file, using the native file resource and the
  # sensu_sorted_json function to format/sort the json.
  file { $title :
    ensure  => $ensure,
    owner   => $owner,
    group   => $group,
    mode    => $mode,
    content => sensu_sorted_json($content, $pretty),
    notify  => $notify_list,
  }
}