Resource Type: file_line

Defined in:
puppet/modules/stdlib/lib/puppet/type/file_line.rb
Providers:
ruby

Overview

Ensures that a given line is contained within a file. The implementation matches the full line, including whitespace at the beginning and end. If the line is not contained in the given file, Puppet will append the line to the end of the file to ensure the desired state. Multiple resources may be declared to manage multiple lines in the same file.

Example:

file_line { 'sudo_rule':
  path => '/etc/sudoers',
  line => '%sudo ALL=(ALL) ALL',
}

file_line { 'sudo_rule_nopw':
  path => '/etc/sudoers',
  line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
}

In this example, Puppet will ensure both of the specified lines are contained in the file /etc/sudoers.

Match Example:

file_line { 'bashrc_proxy':
  ensure => present,
  path   => '/etc/bashrc',
  line   => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
  match  => '^export\ HTTP_PROXY\=',
}

In this code example match will look for a line beginning with export followed by HTTP_PROXY and replace it with the value in line.

Match Example With `ensure => absent`:

file_line { 'bashrc_proxy':
  ensure            => absent,
  path              => '/etc/bashrc',
  line              => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
  match             => '^export\ HTTP_PROXY\=',
  match_for_absence => true,
}

In this code example match will look for a line beginning with export followed by HTTP_PROXY and delete it. If multiple lines match, an error will be raised unless the `multiple => true` parameter is set.

*Autorequires:* If Puppet is managing the file that will contain the line being managed, the file_line resource will autorequire that file.

Properties

  • ensure (defaults to: present)

    The basic property that the resource should be in.

    Supported values:
    • present
    • absent

Parameters

  • after
  • line

    The line to be appended to the file or used to replace matches found by the match attribute.

  • match
  • match_for_absence (defaults to: false)
    Supported values:
    • true
    • false
  • multiple
    Supported values:
    • true
    • false
  • name (namevar)

    An arbitrary name used as the identity of the resource.

  • path

    The file Puppet will ensure contains the line specified by the line parameter.

  • replace (defaults to: true)

    If true, replace line that matches. If false, do not write line if a match is found

    Supported values:
    • true
    • false