Ask Your Question
0

How do I create a swap file using puppetlabs/lvm

asked 2016-02-10 03:53:23 -0600

barkwayp gravatar image

updated 2016-02-10 04:27:25 -0600

This was my first attempt using v0.7.0 of the lvm class but I was getting an error with the mount:

Error: /Stage[main]/Ueit-swap/Mount[/swap]: Could not evaluate: Execution of '/bin/mount /swap' returned 32: mount: unknown filesystem type 'swap'

This is the code I wrote:

if $ueit_swapsize { $v_swapsize = $ueit_swapsize }
else {
  if $memorysize_mb < 2048 {
    $v_swapsize = ($memorysize_mb * 2) / 1024
  } elsif $memorysize_mb < 8192 {
    $v_swapsize = $memorysize_mb / 1024
  } else {
    $v_swapsize = 4
  }
}


class ueit-swap {
  file { '/swap': ensure => "directory" }

  logical_volume { 'lv_swap':
    ensure       => 'present',
    volume_group => 'rootvg',
    size         => $v_swapsize,
    require      => File['/swap'],
  }

  filesystem { '/dev/rootvg/lv_swap':
    ensure  => 'present',
    fs_type => 'swap',
    require => Logical_volume['lv_swap'],
  }

  mount { "/swap":
    device  => "/dev/rootvg/lv_swap",
    fstype  => "swap",
    ensure  => "mounted",
    options => "defaults",
    atboot  => "true",
    require => Filesystem['/dev/rootvg/lv_swap'],
  }
}
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-02-10 04:31:18 -0600

updated 2016-02-10 04:31:31 -0600

The error's coming from the OS and you can find the answer by googling, e.g. here. As explained in the docs, valid values for the fstype attribute depend on your operating system.

edit flag offensive delete link more
0

answered 2016-02-10 04:43:55 -0600

barkwayp gravatar image

updated 2016-02-10 11:47:45 -0600

Alex,

Thank you so much. exec swapon it is then :-)

I hope this helps someone. Below is my code for generating swap file space using the recommendations of sizes from Red Hat but allowing an override from a custom fact ($ueit_swapsize)

class lvmanager::lv-swap { if $ueitswapsize { $vswapsize = $ueitswapsize } else { $memcheck = scanf($memorysize, "%i") if $memcheck[0] < 2 { $vswapsize = $memcheck[0] * 2 } elsif $memcheck[0] < 8 { $vswapsize = $memcheck[0] } else { $vswapsize = 4 } }

notify {"Swap to be used: $v_swapsize": }

logicalvolume { 'lvswap': ensure => 'present', volumegroup => 'rootvg', size => "${vswapsize}G", }

filesystem { '/dev/rootvg/lvswap': ensure => 'present', fstype => 'swap', require => Logicalvolume['lvswap'], }

mount { "swap": device => "/dev/rootvg/lvswap", ensure => 'present', fstype => "swap", options => "defaults", atboot => "true", require => Filesystem['/dev/rootvg/lvswap'], }

exec { "create_swap": command => "/sbin/swapon -a", unless => "/bin/grep partition /proc/swaps", require => Mount['swap'], } }

edit flag offensive delete link more

Comments

You're welcome!

Alex Harvey gravatar imageAlex Harvey ( 2016-02-10 04:53:57 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-02-10 03:53:23 -0600

Seen: 438 times

Last updated: Feb 10 '16