Puppet Class: swap_file

Defined in:
manifests/init.pp

Overview

Main class to allow passing required swapfiles as hashes

Examples:

Will create one swapfile in /mnt/swap using the defaults.

class { '::swap_file':
  'files' => {
    'resource_name' => {
      ensure   => present,
      swapfile => '/mnt/swap',
    },
  },
}

Will create two swapfile with the given parameters

class { 'swap_file':
  'files' => {
    'swap1' => {
      ensure       => present,
      swapfile     => '/mnt/swap.1',
      swapfilesize => '1 GB',
    },
    'swap2' => {
      ensure       => present,
      swapfile     => '/mnt/swap.2',
      swapfilesize => '2 GB',
      cmd          => 'fallocate',
    },
  },
}

Will merge all found instances of swap_file::files found in hiera and create resources for these.

class { '::swap_file':
  files_hiera_merge: true,
}

Parameters:

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

    Hash of swap files to ensure with swap_file::files

  • files_hiera_merge (Variant[Boolean,Enum['true','false']]) (defaults to: false)

    Boolean to merge all found instances of swap_file::files in Hiera. This can be used to specify swap files at different levels an have them all included in the catalog.

Author:

    • Peter Souter



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'manifests/init.pp', line 42

class swap_file (
  Hash $files                                              = {},
  Variant[Boolean,Enum['true','false']] $files_hiera_merge = false,
) {
  # variable handling
  if $files_hiera_merge =~ Boolean {
    $files_hiera_merge_bool = $files_hiera_merge
  } else {
    $files_hiera_merge_bool = str2bool($files_hiera_merge)
  }

  # functionality
  if $files_hiera_merge_bool == true {
    $files_real = lookup('swap_file::files', Hash, 'deep', {})
  } else {
    $files_real = $files
  }
  if $files_real != undef {
    create_resources('swap_file::files', $files_real)
  }
}