Defined Type: lvm::volume

Defined in:
vendor_modules/lvm/manifests/volume.pp

Overview

Define: lvm::volume

This defined type will create a logical_volume with the name of the define and ensure a physical_volume, volume_group, and filesystem resource have been created on the block device supplied.

Parameters

ensure

Can only be set to cleaned, absent or

present. A value of present will ensure that the 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 use it with caution. A value of absent will remove only the logical_volume resource from the system.

pv

The block device to ensure a physical_volume has been

created on. [vg] The volume_group to ensure is created on the physical_volume provided by the pv parameter.

fstype

The type of filesystem to create on the logical

volume. [size] The size the logical_voluem should be.

createonly

If set, it will not try to create any physical volumes if

the given volum group already exists (preventing data loss).

Examples

Provide some examples on how to use this type:

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

See README.markdown for the module author information.

License

This file is part of the puppetlabs/lvm puppet module.

puppetlabs/lvm is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2 of the License.

puppetlabs/lvm is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with puppetlabs/lvm. If not, see www.gnu.org/licenses/.

Parameters:

  • ensure (Any)
  • pv (Any)
  • vg (Any)
  • fstype (Any) (defaults to: undef)
  • size (Any) (defaults to: undef)
  • extents (Any) (defaults to: undef)
  • initial_size (Any) (defaults to: undef)
  • createonly (Boolean) (defaults to: false)


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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'vendor_modules/lvm/manifests/volume.pp', line 57

define lvm::volume (
  $ensure,
  $pv,
  $vg,
  $fstype  = undef,
  $size    = undef,
  $extents = undef,
  $initial_size = undef,
  Boolean $createonly = false,
) {

  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.
      if $createonly {
        ensure_resource('physical_volume', $pv, { 'ensure' => $ensure, 'unless_vg' => $vg })
      } else {
        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,
          createonly       => $createonly,
          require          => Physical_volume[$pv],
        }
      }

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

      if ($fstype != undef and ! $createonly) {
        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') )
    }
  }
}