Forge Home


Edit files the easy way using Puppet - like magic


5,999 latest version

3.8 quality score

Version information

  • 0.6.1 (latest)
  • 0.6.0
  • 0.5.2
  • 0.5.1
  • 0.5.0
  • 0.4.1
  • 0.4.0
  • 0.3.0
  • 0.2.0
  • 0.1.0
released Aug 28th 2018

Start using this module

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

Add this module to your Puppetfile:

mod 'geoffwilliams-filemagic', '0.6.1'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add geoffwilliams-filemagic
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install geoffwilliams-filemagic --version 0.6.1

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.



geoffwilliams/filemagic — version 0.6.1 Aug 28th 2018

Build Status


Table of Contents

  1. Description
  2. Setup - The basics of getting started with filemagic
  3. Usage - Configuration options and additional functionality
  4. Limitations - OS compatibility, etc.
  5. Development - Guide for contributing to the module


Do you like files? Do you like magic? If so, this is the module for you! Puppet is a great language but out-of-the-box it expects and demands that you do things The Puppet Way which isn't always possible.

Take for example the following situations:

  • Your maintaining a fleet of brownfield production machines with an unknown state
  • You must follow your installation orders and they say to edit, not replace files
  • Files shared between multiple 'owners' e.g., modules, people, programs, etc
  • You don't want to fully template a file in order to receive upstream fixes
  • You need to do really simple edit(s)!



  • Make a file 'sandwich' (insert data into a point inside the file)
  • Un-make a file 'sandwich'
  • Delete
  • Comment (not *ML)



  • Append data to a file
  • Un-append data to a file
  • Specify match_start - The first line of input to append from, for cases where some data already exists


  • Replace a regular expression
  • Delete a regular expression


  • Prepend data to a file
  • Un-prepend data to a file
  • Specify match_end - The last line of input to prepend to, for cases where some data already exists


  • Find and replace lines of data in a file
  • Un-replace (delete) matching lines
  • Matches all instances of the match regexp and replaces/deletes as requested


  • There is no setup and FileMagic is cross platform! Please create an issue if you find this not to be the case.


See reference and examples


  • Not supported by Puppet, Inc.
  • Not intended for use with 'large' files - entire file to be edited is presently read into memory


PRs accepted :)


This module supports testing using PDQTest.

Test can be executed with:

bundle install

See .travis.yml for a working CI example