Using file_line Resource (from Puppet's stdlib Module)

Using file_line Resource (from Puppet's stdlib Module)

Last updated:

This is useful if you want to make sure a file contains a given line; it is commonly used to add configuration directives to configuration files.

In order to use this, you must install Puppet module puppetlabs/stdlib

Example usage: add the following to a manifest file if you want to include a directory to a user's $PATH:

file_line{"add a directory to some user's path":
    path => "/home/jdoe/.bashrc",
    line => 'PATH=$PATH:/path/to/some/directory',
}

The default behaviour is to make sure the line you've provided is present in said file. If you want to make sure some line is absent from a file, you can use ensure => "absent";

Example: you want to make sure that your ssh server does not allow password-based user login:

file_line{'disable password login':
    path => '/etc/ssh/sshd_config',
    line => 'PasswordAuthentication yes',
    ensure => 'absent',
}

Dialogue & Discussion