Defined Type: lvm::volume

Defined in:
manifests/volume.pp

Summary

Manage a logical_volume.

Overview

Ensures a physical_volume, volume_group, and filesystem resource have been created on the block device supplied in the pv parameter.

physical_volume, volume_group, logical_volume, and filesystem resources are present for the volume. A value of cleaned will ensure that all of the resources are absent. Warning: this has a high potential for unexpected harm, so use it with caution. A value of absent will remove only the logical_volume resource from the system.

volume.

Set to undef to use all available space

This will only apply to newly-created volumes

Examples:

Basic usage


lvm::volume { 'lv_example0':
  vg     => 'vg_example0',
  pv     => '/dev/sdd1',
  fstype => 'ext4',
  size   => '100GB',
}

Parameters:

  • ensure (Enum['present', 'absent', 'cleaned'])

    Can only be set to cleaned, absent or present. A value of present will ensure that the

  • fstype (Optional[String[1]]) (defaults to: undef)

    The type of filesystem to create on the logical

  • pv (Stdlib::Absolutepath)

    path to physcial volume

  • vg (String[1])

    value of volume group

  • size (Optional[String[1]]) (defaults to: undef)

    The size the logical_voluem should be.

  • extents (Optional[Variant[String[1], Integer]]) (defaults to: undef)

    The number of logical extents to allocate for the new logical volume.

  • initial_size (Optional[String[1]]) (defaults to: undef)

    The initial size of the logical volume.



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'manifests/volume.pp', line 37

define lvm::volume (
  Enum['present', 'absent', 'cleaned'] $ensure,
  Stdlib::Absolutepath $pv,
  String[1] $vg,
  Optional[String[1]] $fstype                     = undef,
  Optional[String[1]] $size                       = undef,
  Optional[Variant[String[1], Integer]] $extents  = undef,
  Optional[String[1]] $initial_size               = undef
) {
  if ($name == undef) {
    fail("lvm::volume \$name can't be undefined")
  }

  case $ensure {
    #
    # Clean up the whole chain.
    #
    'cleaned': {
      # This may only need to exist once
      if ! defined(Physical_volume[$pv]) {
        physical_volume { $pv: ensure => present }
      }
      # This may only need to exist once
      if ! defined(Volume_group[$vg]) {
        volume_group { $vg:
          ensure           => present,
          physical_volumes => $pv,
          before           => Physical_volume[$pv],
        }

        logical_volume { $name:
          ensure       => present,
          volume_group => $vg,
          size         => $size,
          initial_size => $initial_size,
          before       => Volume_group[$vg],
        }
      }
    }
    #
    # Just clean up the logical volume
    #
    'absent': {
      logical_volume { $name:
        ensure       => absent,
        volume_group => $vg,
        size         => $size,
      }
    }
    #
    # Create the whole chain.
    #
    'present': {
      # This may only need to exist once.  Requires stdlib 4.1 to
      # handle $pv as an array.
      ensure_resource('physical_volume', $pv, { 'ensure' => $ensure })

      # This may only need to exist once
      if ! defined(Volume_group[$vg]) {
        volume_group { $vg:
          ensure           => present,
          physical_volumes => $pv,
          require          => Physical_volume[$pv],
        }
      }

      logical_volume { $name:
        ensure       => present,
        volume_group => $vg,
        size         => $size,
        extents      => $extents,
        require      => Volume_group[$vg],
      }

      if $fstype != undef {
        filesystem { "/dev/${vg}/${name}":
          ensure  => present,
          fs_type => $fstype,
          require => Logical_volume[$name],
        }
      }
    }
    default: {
      fail ( sprintf('%s%s', 'puppet-lvm::volume: ensure parameter can only ',
      'be set to cleaned, absent or present') )
    }
  }
}