Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are several ways to modify the content of a file.

Create a template

 file { '/etc/fstab':
   ensure => present, 
   content => template(foo/fstab.erb),
}

This is simple, however you will quickly find that it won't scale if every machine requires different files.


Use a module

While I haven't tried it, it looks like over 1000 other people have downloaded this module

https://forge.puppetlabs.com/AlexCline/fstab


Use an augeas provider

Augeas is a create way to manage a single line of files. The plugin to edit key value pairs, xml, json files are called lenses. Puppet ships with many Augeas lenses built in.

augeas { 'new_hostname':
  context   =>  '/files/etc/sysconfig/network/',
  changes   =>  "set HOSTNAME foobar",
}

Here is a more complex example

 augeas { 'nppcu':
    incl    =>  '/var/spool/torque/server_priv/serverdb',
    context =>  '/files/var/spool/torque/server_priv/serverdb/server_db/attributes',
    lens   =>  "Xml.lns",
    changes =>  [
      "ins nppcu after /files/var/spool/torque/server_priv/serverdb/server_db/attributes/cray_enabled",
      "set /files/var/spool/torque/server_priv/serverdb/server_db/attributes/nppcu/#text 1",
    ]
  }

From what you are describing, an fstab will likely be the best option, followed by augeas.

There are several ways to modify the content of a file.

Create a template

 file { '/etc/fstab':
   ensure => present, 
   content => template(foo/fstab.erb),
}

This is simple, however you will quickly find that it won't scale if every machine requires different files. its own template.


Use a module

While I haven't tried it, it looks like over 1000 other people have downloaded this module

https://forge.puppetlabs.com/AlexCline/fstabhttps://forge.puppetlabs.com/AlexCline/fstab There are several other listed on the puppet forge which look promising.


Use an augeas provider

Augeas is a create great way to manage a single line of files. The plugin inside a file. It thrives on editing key value pairs but has many plugins to edit key value pairs, xml, json files everything from json, to xml. These plugins are called lenses. Puppet ships with many Augeas lenses built in.

augeas { 'new_hostname':
  context   =>  '/files/etc/sysconfig/network/',
  changes   =>  "set HOSTNAME foobar",
}

Here is a more complex example

 augeas { 'nppcu':
    incl    =>  '/var/spool/torque/server_priv/serverdb',
    context =>  '/files/var/spool/torque/server_priv/serverdb/server_db/attributes',
    lens   =>  "Xml.lns",
    changes =>  [
      "ins nppcu after /files/var/spool/torque/server_priv/serverdb/server_db/attributes/cray_enabled",
      "set /files/var/spool/torque/server_priv/serverdb/server_db/attributes/nppcu/#text 1",
    ]
  }

From what you are describing, an fstab will likely be the best option, followed by augeas.

There are several ways to modify the content of a file.

Create a template

 file { '/etc/fstab':
   ensure => present, 
   content => template(foo/fstab.erb),
}

This is simple, however you will quickly find that it won't scale if every machine requires its own template.


Use a module

While I haven't tried it, it looks like over 1000 other people have downloaded this module

https://forge.puppetlabs.com/AlexCline/fstab https://forge.puppetlabs.com/AlexCline/fstab
There are several other listed on the puppet forge which look promising.


Use an augeas provider

Augeas is a great way to manage a single line inside a file. It thrives on editing key value pairs but has many plugins to edit everything from json, to xml. These plugins are called lenses.

augeas { 'new_hostname':
  context   =>  '/files/etc/sysconfig/network/',
  changes   =>  "set HOSTNAME foobar",
}

Here is a more complex example

 augeas { 'nppcu':
    incl    =>  '/var/spool/torque/server_priv/serverdb',
    context =>  '/files/var/spool/torque/server_priv/serverdb/server_db/attributes',
    lens   =>  "Xml.lns",
    changes =>  [
      "ins nppcu after /files/var/spool/torque/server_priv/serverdb/server_db/attributes/cray_enabled",
      "set /files/var/spool/torque/server_priv/serverdb/server_db/attributes/nppcu/#text 1",
    ]
  }

From what you are describing, an fstab will likely be the best option, followed by augeas.

There are several ways to modify the content of a file.

Create a template

 file { '/etc/fstab':
   ensure => present, 
   content => template(foo/fstab.erb),
template(foo/templates/fstab.erb),
}

This is simple, however you will quickly find that it won't scale if every machine requires its own template.


Use a module

While I haven't tried it, it looks like over 1000 other people have downloaded this module

https://forge.puppetlabs.com/AlexCline/fstab
There are several other listed on the puppet forge which look promising.


Use an augeas provider

Augeas is a great way to manage a single line inside a file. It thrives on editing key value pairs but has many plugins to edit everything from json, to xml. These plugins are called lenses.

augeas { 'new_hostname':
  context   =>  '/files/etc/sysconfig/network/',
  changes   =>  "set HOSTNAME foobar",
}

Here is a more complex example

 augeas { 'nppcu':
    incl    =>  '/var/spool/torque/server_priv/serverdb',
    context =>  '/files/var/spool/torque/server_priv/serverdb/server_db/attributes',
    lens   =>  "Xml.lns",
    changes =>  [
      "ins nppcu after /files/var/spool/torque/server_priv/serverdb/server_db/attributes/cray_enabled",
      "set /files/var/spool/torque/server_priv/serverdb/server_db/attributes/nppcu/#text 1",
    ]
  }

From what you are describing, an fstab will likely be the best option, followed by augeas.

There are several ways to modify the content of a file.

Create a template

 file { '/etc/fstab':
   ensure => present, 
   content => template(foo/templates/fstab.erb),
}

This is simple, the simple answer, however you will quickly find that it won't scale could become hard to manage if every machine server requires its own template. template.


Use a module

While I haven't tried it, it looks like over 1000 other people have downloaded this module

https://forge.puppetlabs.com/AlexCline/fstab
There are several other listed on the puppet forge which look promising.


Use an augeas provider

Augeas is a great way to manage a single line inside a file. It thrives on editing key value pairs but has many plugins to edit everything from json, to xml. These plugins are called lenses.

Change just the HOSTNAME line inside /etc/sysconfig/network

augeas { 'new_hostname':
  context   =>  '/files/etc/sysconfig/network/',
  changes   =>  "set HOSTNAME foobar",
}

Or change the sshd config file

augeas { 'disable root':
  context   =>  '/files/etc/sshd/config',
  changes   =>  "set PermitRootLogin no",
}

Here is a more complex example

 augeas { 'nppcu':
    incl    =>  '/var/spool/torque/server_priv/serverdb',
    context =>  '/files/var/spool/torque/server_priv/serverdb/server_db/attributes',
    lens   =>  "Xml.lns",
    changes =>  [
      "ins nppcu after /files/var/spool/torque/server_priv/serverdb/server_db/attributes/cray_enabled",
      "set /files/var/spool/torque/server_priv/serverdb/server_db/attributes/nppcu/#text 1",
    ]
  }

From what you are describing, an fstab will likely be the best option, followed by augeas.

There are several ways to modify the content of a file.

Create a template

 file { '/etc/fstab':
   ensure => present, 
   content => template(foo/templates/fstab.erb),
}

This is the simple answer, however it could become hard to manage if every server requires its own template.


Use a module

While I haven't tried it, it looks like over 1000 other people have downloaded this module

https://forge.puppetlabs.com/AlexCline/fstab
There are several other listed on the puppet forge which look promising.


Use an augeas provider

Augeas is a great way to manage a single line inside a file. It thrives on editing key value pairs but has many plugins to edit everything from json, to xml. These plugins are called lenses.

Change just the HOSTNAME line inside /etc/sysconfig/network

augeas { 'new_hostname':
  context   =>  '/files/etc/sysconfig/network/',
  changes   =>  "set HOSTNAME foobar",
}

Or change the sshd config file

augeas { 'disable root':
  context   =>  '/files/etc/sshd/config',
  changes   =>  "set PermitRootLogin no",
}

Here is a more complex example

 augeas { 'nppcu':
    incl    =>  '/var/spool/torque/server_priv/serverdb',
    context =>  '/files/var/spool/torque/server_priv/serverdb/server_db/attributes',
    lens   =>  "Xml.lns",
    changes =>  [
      "ins nppcu after /files/var/spool/torque/server_priv/serverdb/server_db/attributes/cray_enabled",
      "set /files/var/spool/torque/server_priv/serverdb/server_db/attributes/nppcu/#text 1",
    ]
  }

From what you are describing, an a fstab module will likely be the best option, followed by augeas.