snd (search and destroy)
Table of Contents
Description
This snd (search and destroy) module can be used to search a string within a file and perform 2 types of actions if found:
-
Return true so puppet registers an action has been performed (default).
-
Delete the file.
This module can be used to detect problems in a file where deleting it is the easiest fix. I mainly use it for files automatically generated by other programs. By example DUID file for DHCPv6 clients.
Setup
What snd affects
The snd module only affects file(s) if specified.
Beginning with snd
There are 2 ways you can obtain this module.
-
Git clone or download the module from the git repository.
-
Download from puppet forge.
Usage
You can use the module by including it:
include snd
Doing so won't have any effect until data hash is provided via hiera in the following format:
snd::params::search_items:
[file_name]:
search_str: '[search_string]'
display_only: true/false
By example, to delete the file /tmp/foo if a line contains a line with 'answer is 42':
snd::params::search_items:
/tmp/foo:
search_str: '^answer is 42$'
display_only: false
Reference
The reference of this module can be generated by puppet strings. There are 3 ways you can access the content:
-
Refer it in the official documentation.
-
Git checkout the gh-pages branch of the module repository.
-
Re-generate the reference locally by running puppet strings within the module directory.
Limitations
This module is tested on Ubuntu LTS against Puppet 5, but it'll probably work on other Linux distributions.
Development
Please feel free to clone, use, play, comment and create pull requests. Let's see how it goes.