Skip to content

Instantly share code, notes, and snippets.

@raphink
Last active June 4, 2020 16:48
Show Gist options
  • Save raphink/d441e1cc686b542fcdf5 to your computer and use it in GitHub Desktop.
Save raphink/d441e1cc686b542fcdf5 to your computer and use it in GitHub Desktop.

File Manipulation Approaches

Full configurations

Static content

  • Software/script => have you considered packaging it?
  • binary/large data file => add metadata (git + vcsrepo type, maybe even git-annex or git-lfs?)
  • Puppet >= 3.7:
file { 'foo':
  content => file('<module>/<file>')
}
  • Puppet < 3.7:
file { 'foo':
  source => 'puppet:///modules/<module>/<file>'
}

Dynamic content

  • there exists a Puppet purgeable type for the format (host, mailalias, augeasproviders, etc.) => use it with purge:
host { 'foo':
  ensure => present,
}
resources { 'host':
  purge => true
}
  • content from one scope:
file { 'foo':
  content => template(),
}
  • content from various scopes:
    • the application supports conf.d directory/includes => conf.d/ directory + purge
    • otherwise => concat module (puppetlabs or theforeman)
  • content from example file on the agent + modifications => augeas_file

Partial configurations

  • there is a Puppet type for the format (host, mailalias, augeasproviders, etc.) => use it!
  • the application supports conf.d directory/includes => conf.d/ directory with file resources
  • it is an IniFile type of file => use ini_setting
  • there is an Augeas lens for the format => use the augeas type
  • are you actually trying to patch a script? => you should fork/patch/repackage it, really!
  • you only want to modify one line of a file format nobody else knows about => file_line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment