]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/stdlib/lib/puppet/type/file_line.rb
upgrade to concat 2.0.0
[dsa-puppet.git] / modules / stdlib / lib / puppet / type / file_line.rb
1 Puppet::Type.newtype(:file_line) do
2
3   desc <<-EOT
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 add the line to
7     ensure the desired state.  Multiple resources may be declared to manage
8     multiple lines in the same file.
9
10     Example:
11
12         file_line { 'sudo_rule':
13           path => '/etc/sudoers',
14           line => '%sudo ALL=(ALL) ALL',
15         }
16         file_line { 'sudo_rule_nopw':
17           path => '/etc/sudoers',
18           line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
19         }
20
21     In this example, Puppet will ensure both of the specified lines are
22     contained in the file /etc/sudoers.
23
24   EOT
25
26   ensurable do
27     defaultto :present
28     newvalue(:present) do
29       provider.create
30     end
31   end
32
33   newparam(:name, :namevar => true) do
34     desc 'arbitrary name used as identity'
35   end
36
37   newparam(:line) do
38     desc 'The line to be appended to the path.'
39   end
40
41   newparam(:path) do
42     desc 'File to possibly append a line to.'
43     validate do |value|
44       unless (Puppet.features.posix? and value =~ /^\//) or (Puppet.features.microsoft_windows? and (value =~ /^.:\// or value =~ /^\/\/[^\/]+\/[^\/]+/))
45         raise(Puppet::Error, "File paths must be fully qualified, not '#{value}'")
46       end
47     end
48   end
49
50   validate do
51     unless self[:line] and self[:path]
52       raise(Puppet::Error, "Both line and path are required attributes")
53     end
54   end
55 end