Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Wrapper #40

Merged
merged 2 commits into from
Feb 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.*.sw?
pkg
spec/fixtures
.rspec_system
.vagrant/
log/
junit/
.yar*
doc/

# Puppet
coverage/
spec/fixtures/modules/*
spec/fixtures/manifests/*
Gemfile.lock
88 changes: 81 additions & 7 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* [What swap_file affects](#what-swap_file-affects)
4. [Usage](#usage)
5. [Limitations](#limitations)
6. [Development](#development)
6. [Upgrading from 1.0.1 Release](#upgrading-from-101-release)
7. [Development](#development)

##Overview

Expand Down Expand Up @@ -53,7 +54,7 @@ swap_file::files { 'tmp file swap':
swapfile => '/tmp/swapfile',
cmd => 'fallocate',
}

```
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guessing this was intended


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

Expand All @@ -63,20 +64,93 @@ swap_file::files { 'tmp file swap':
}
```

## Previous to 1.0.1 Release
### hiera
You can also use hiera to call this module and set the configuration.

Previously you would create swapfiles with the `swap_file` class:
The simplest use of the module is this:

```yaml
classes:
- swap_file

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

The module will:
* create a file using /bin/dd atr `/mnt/swap.1` with the default size taken from the `$::memorysizeinbytes` and creates a `mount` for it.

You can use all customizations mentioned above like this:

```yaml
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'
```

The module will:
* create a file `/tmp/swapfile.custom` using /bin/dd with the default size taken from the `$::memorysizeinbytes` without creating a `mount` for it.
* create a file `/tmp/swapfile.fallocate` using /usr/bin/fallocate with the default size taken from the `$::memorysizeinbytes` 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 usefull for specifying swap files at different levels of the hierachy and having them all includid in the catalog.

##Upgrading from 1.0.1 Release

Previously you would create swapfiles with the `swap_file` class:

```puppet
class { 'swap_file':
swapfile => '/mount/swapfile',
swapfilesize => '100 MB',
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:

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

You can also safely declare mutliple swap file definitions:

This is now removed from 2.x.x onwards.
```puppet
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

Expand Down
12 changes: 12 additions & 0 deletions examples/hiera/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
classes:
- swap_file

swap_file::files:
'from_common':
ensure: 'present'
swapfile: '/mnt/swap.common'

# This will:
# - call the class swap_file
# - create a file '/mnt/swap.common' using /bin/dd with the default size taken from the $::memorysizeinbytes and create a mount for it.
13 changes: 13 additions & 0 deletions examples/hiera/fqdn/merge_disabled.domain.local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
swap_file::files_hiera_merge: false
swap_file::files:
'from_fqdn':
ensure: 'present'
swapfile: '/mnt/swap.fqdn'
swapfilesize: '2 GB'
cmd: 'fallocate'

# Because files_hiera_merge is set to false, this will create only the swapfiles specified in the most specific hiera level.

# This will:
# - create a file '/mnt/swap.fqdn' using /usr/bin/fallocate with size set to '2 GB' and creates mount for it.
16 changes: 16 additions & 0 deletions examples/hiera/fqdn/merge_enabled.domain.local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
swap_file::files_hiera_merge: true
swap_file::files:
'from_fqdn':
ensure: 'present'
swapfile: '/mnt/swap.fqdn'
swapfilesize: '2 GB'
cmd: 'fallocate'

# Because files_hiera_merge is set to true, this will create all swapfiles specified in different hiera levels.

# This will:
# - create a file '/mnt/swap.common' using /bin/dd with the default size taken from the $::memorysizeinbytes and create a mount for it.
# - create a file '/mnt/swap.fqdn' using /usr/bin/fallocate with size set to '2 GB' and creates mount for it.


6 changes: 6 additions & 0 deletions examples/hiera/hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
:backends:
- yaml
:hierarchy:
- fqdn/%{fqdn}
- common
17 changes: 17 additions & 0 deletions examples/multiple_swaps.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
node default {
class { 'swap_file':
files => {
'swapfile' => {
ensure => 'present',
},
'use fallocate' => {
swapfile => '/tmp/swapfile.fallocate',
cmd => 'fallocate',
},
'remove swap file' => {
ensure => 'absent',
swapfile => '/tmp/swapfile.old',
},
},
}
}
71 changes: 71 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# == Class: swap_file
#
# == Parameters
# [*files*]
# Hash of swap files to ensure with swap_file::files
# [*files_hiera_merge*]
# 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.
# Defaults to false
#
# == Examples
#
# class { 'swap_file':
# 'files' => {
# 'resource_name' => {
# ensure => present,
# swapfile => '/mnt/swap',
# },
# },
# }
# Will create one swapfile in /mnt/swap using the defaults.
#
# 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 create two swapfile with the given parameters
#
# class { 'swap_file':
# files_hiera_merge: true,
# }
# Will merge all found instances of swap_file::files found in hiera and
# create resources for these.
#

class swap_file (
$files = {},
$files_hiera_merge = false,
) {

# variable handling
if is_bool($files_hiera_merge) == true {
$files_hiera_merge_bool = $files_hiera_merge
} else {
$files_hiera_merge_bool = str2bool($files_hiera_merge)
}
validate_bool($files_hiera_merge_bool)

# functionality
if $files_hiera_merge_bool == true {
$files_real = hiera_hash('swap_file::files', {})
} else {
$files_real = $files
}
if $files_real != undef {
validate_hash($files_real)
create_resources('swap_file::files', $files_real)
}
}
Loading