1 Puppet::Type.newtype(:file_line) do
4 Ensures that a given line is contained within a file. The implementation
5 matches the full line, including whitespace at the beginning and end. If
6 the line is not contained in the given file, Puppet will append the line to
7 the end of the file to ensure the desired state. Multiple resources may
8 be declared to manage multiple lines in the same file.
12 file_line { 'sudo_rule':
13 path => '/etc/sudoers',
14 line => '%sudo ALL=(ALL) ALL',
17 file_line { 'sudo_rule_nopw':
18 path => '/etc/sudoers',
19 line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
22 In this example, Puppet will ensure both of the specified lines are
23 contained in the file /etc/sudoers.
27 file_line { 'bashrc_proxy':
29 path => '/etc/bashrc',
30 line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
31 match => '^export\ HTTP_PROXY\=',
34 In this code example match will look for a line beginning with export
35 followed by HTTP_PROXY and replace it with the value in line.
37 **Autorequires:** If Puppet is managing the file that will contain the line
38 being managed, the file_line resource will autorequire that file.
47 newparam(:name, :namevar => true) do
48 desc 'An arbitrary name used as the identity of the resource.'
52 desc 'An optional ruby regular expression to run against existing lines in the file.' +
53 ' If a match is found, we replace that line rather than adding a new line.' +
54 ' A regex comparisson is performed against the line value and if it does not' +
55 ' match an exception will be raised. '
58 newparam(:multiple) do
59 desc 'An optional value to determine if match can change multiple lines.' +
60 ' If set to false, an exception will be raised if more than one line matches'
61 newvalues(true, false)
65 desc 'An optional value used to specify the line after which we will add any new lines. (Existing lines are added in place)'
69 desc 'The line to be appended to the file or used to replace matches found by the match attribute.'
73 desc 'The file Puppet will ensure contains the line specified by the line parameter.'
75 unless (Puppet.features.posix? and value =~ /^\//) or (Puppet.features.microsoft_windows? and (value =~ /^.:\// or value =~ /^\/\/[^\/]+\/[^\/]+/))
76 raise(Puppet::Error, "File paths must be fully qualified, not '#{value}'")
81 # Autorequire the file resource if it's being managed
87 unless self[:line] and self[:path]
88 raise(Puppet::Error, "Both line and path are required attributes")