Forge Home

swap_file

Create swap files for Linux systems with Puppet

747,677 downloads

127,513 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Support the Puppet Community by contributing to this module

You are welcome to contribute to this module by suggesting new features, currency updates, or fixes. Every contribution is valuable to help ensure that the module remains compatible with the latest Puppet versions and continues to meet community needs. Complete the following steps:

  1. Review the module’s contribution guidelines and any licenses. Ensure that your planned contribution aligns with the author’s standards and any legal requirements.
  2. Fork the repository on GitHub, make changes on a branch of your fork, and submit a pull request. The pull request must clearly document your proposed change.

For questions about updating the module, contact the module’s author.

Version information

  • 4.0.2 (latest)
  • 4.0.0
  • 3.1.4
  • 3.1.3
  • 3.0.2
  • 3.0.1
  • 3.0.0
  • 2.5.0
  • 2.4.1
  • 2.4.0 (deleted)
  • 2.3.0
  • 2.2.2
  • 2.2.1
  • 2.2.0
  • 2.1.0
  • 2.0.0
  • 1.1.1
  • 1.1.0
  • 1.0.1
  • 1.0.0
  • 0.1.2
  • 0.1.1
  • 0.1.0
released Mar 19th 2019
This version is compatible with:
  • Puppet Enterprise 2023.8.x, 2023.7.x, 2023.6.x, 2023.5.x, 2023.4.x, 2023.3.x, 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x, 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x, 2017.3.x, 2017.2.x, 2017.1.x, 2016.5.x, 2016.4.x
  • Puppet >= 4.0.0
  • , , ,

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'petems-swap_file', '4.0.2'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add petems-swap_file
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install petems-swap_file --version 4.0.2

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

petems/swap_file — version 4.0.2 Mar 19th 2019

swap_file

Puppet
Forge Build Status Puppet Forge
Downloads Puppet Forge
Endorsement

Table of Contents

  1. Overview
  2. Module Description
  3. Setup
  4. Usage
  5. Limitations
  6. Upgrading from 1.0.1 Release
  7. Development

Overview

Manage swap files for your Linux environments. This is based on the gist by @Yggdrasil, with a few changes and added specs.

Setup

What swap_file affects

  • Creating a swap-file on disk. This uses dd by default, but can use fallocate optionally for performance reasons. Note: Using fallocate to create a ZFS file system will fail: https://bugzilla.redhat.com/show_bug.cgi?id=1129205
  • Swapfiles on the system
  • Any mounts of swapfiles

Usage

The simplest use of the module is this:

swap_file::files { 'default':
  ensure   => present,
}

By default, the module it will:

  • create a file using /bin/dd at /mnt/swap.1 with the default size taken from the $::memorysize fact in megabytes (eg. 8GB RAM will create an 8GB swap file)
  • A mount for the swapfile created

For a custom setup, you can do something like this:

swap_file::files { 'tmp file swap':
  ensure    => present,
  swapfile  => '/tmp/swapfile',
  add_mount => false,
}

To use fallocate for swap file creation instead of dd:

swap_file::files { 'tmp file swap':
  ensure    => present,
  swapfile  => '/tmp/swapfile',
  cmd       => 'fallocate',
}

To remove a prexisting swap, you can use ensure absent:

swap_file::files { 'tmp file swap':
  ensure   => absent,
}

To choose the size of the swap file instead of defaulting to memory size:

swap_file::files { '5GB Swap':
  ensure       => present,
  swapfile     => '/mnt/swap.5gb',
  swapfilesize => '5GB',
}

hiera

You can also use hiera to call this module and set the configuration.

The simplest use of the module with hiera is this:

classes:
  - swap_file

swap_file::files:
  'default':
    ensure: 'present'

This hiera setup will create a file using /bin/dd atr /mnt/swap.1 with the default size taken from the $::memorysize fact and add a mount resource for it.

You can use all customizations mentioned above in hiera like this:

classes:
  - swap_file

swap_file::files:
  'custom setup':
    ensure: 'present'
    swapfile: '/tmp/swapfile.custom'
    add_mount: false
  'use fallocate':
    swapfile: '/tmp/swapfile.fallocate'
    cmd: 'fallocate'
  'remove swap file'
    ensure: 'absent'
    swapfile: '/tmp/swapfile.old'

This hiera config will respectively:

  • create a file /tmp/swapfile.custom using /bin/dd with the default size taken from the $::memorysize fact without creating a mount for it.
  • create a file /tmp/swapfile.fallocate using /usr/bin/fallocate with the default size taken from the $::memorysize fact and creating a mount for it.
  • deactivates the swapfile /tmp/swapfile.old, deletes it and removes the mount.

Set $files_hiera_merge to true to merge all found instances of swap_file::files in Hiera. This is useful for specifying swap files at different levels of the hierachy and having them all included in the catalog.

##Upgrading from 1.0.1 Release

Previously you would create swapfiles with the swap_file class:

class { 'swap_file':
  ensure => 'present',
}

However, this had many problems, such as not being able to declare more than one swap_file because of duplicate class errors. Since 2.x.x the swapfiles are created by a defined type instead. The swap_file class is now a wrapper and can handle multiple swap_files.

You can now use:

class { 'swap_file':
  files => {
    'freetext resource name' => {
      ensure => 'present',
    },
  },
}

You can also safely declare mutliple swap file definitions:

class { 'swap_file':
  files => {
    'swapfile' => {
      ensure => 'present',
    },
    'use fallocate' => {
      swapfile => '/tmp/swapfile.fallocate',
      cmd      => 'fallocate',
    },
    'remove swap file' => {
      ensure   => 'absent',
      swapfile => '/tmp/swapfile.old',
    },
  },
}

Limitations

Primary support is for Debian and RedHat, but should work on all Linux flavours.

Right now there is no BSD support, but I'm planning on adding it in the future

Development

Follow the CONTRIBUTING guidelines! :)