Skip to content

Commit ad173f2

Browse files
committed
(MODULES-2421) improve description of file_line
This mostly needed extraction of the existing doc strings from the type.
1 parent 4e62223 commit ad173f2

File tree

2 files changed

+57
-20
lines changed

2 files changed

+57
-20
lines changed

README.markdown

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,70 @@ The `stdlib::stages` class declares various run stages for deploying infrastruct
7676
### Types
7777

7878
#### `file_line`
79-
Ensures that a given line, including whitespace at the beginning and end, is contained within a file. If the line is not contained in the given file, Puppet will add the line. Multiple resources can be declared to manage multiple lines in the same file. You can also use `match` to replace existing lines.
8079

81-
~~~
82-
file_line { 'sudo_rule':
83-
path => '/etc/sudoers',
84-
line => '%sudo ALL=(ALL) ALL',
85-
}
86-
file_line { 'sudo_rule_nopw':
87-
path => '/etc/sudoers',
88-
line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
89-
}
90-
~~~
80+
Ensures that a given line is contained within a file. The implementation
81+
matches the full line, including whitespace at the beginning and end. If
82+
the line is not contained in the given file, Puppet will append the line to
83+
the end of the file to ensure the desired state. Multiple resources may
84+
be declared to manage multiple lines in the same file.
85+
86+
Example:
87+
88+
file_line { 'sudo_rule':
89+
path => '/etc/sudoers',
90+
line => '%sudo ALL=(ALL) ALL',
91+
}
92+
93+
file_line { 'sudo_rule_nopw':
94+
path => '/etc/sudoers',
95+
line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
96+
}
97+
98+
In this example, Puppet will ensure both of the specified lines are
99+
contained in the file /etc/sudoers.
100+
101+
Match Example:
102+
103+
file_line { 'bashrc_proxy':
104+
ensure => present,
105+
path => '/etc/bashrc',
106+
line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
107+
match => '^export\ HTTP_PROXY\=',
108+
}
109+
110+
In this code example match will look for a line beginning with export
111+
followed by HTTP_PROXY and replace it with the value in line.
112+
113+
Match Example With `ensure => absent`:
114+
115+
file_line { 'bashrc_proxy':
116+
ensure => absent,
117+
path => '/etc/bashrc',
118+
line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
119+
match => '^export\ HTTP_PROXY\=',
120+
match_for_absence => true,
121+
}
122+
123+
In this code example match will look for a line beginning with export
124+
followed by HTTP_PROXY and delete it. If multiple lines match, an
125+
error will be raised unless the `multiple => true` parameter is set.
126+
127+
**Autorequires:** If Puppet is managing the file that will contain the line
128+
being managed, the file_line resource will autorequire that file.
91129

92130
##### Parameters
93131
All parameters are optional, unless otherwise noted.
94132

95133
* `after`: Specifies the line after which Puppet will add any new lines. (Existing lines are added in place.) Valid options: String. Default: Undefined.
96134
* `ensure`: Ensures whether the resource is present. Valid options: 'present', 'absent'. Default: 'present'.
97135
* `line`: **Required.** Sets the line to be added to the file located by the `path` parameter. Valid options: String. Default: Undefined.
98-
* `match`: Specifies a regular expression to run against existing lines in the file; if a match is found, it is replaced rather than adding a new line. Valid options: String containing a regex. Default: Undefined.
136+
* `match`: Specifies a regular expression to run against existing lines in the file; if a match is found, it is replaced rather than adding a new line. A regex comparison is performed against the line value and if it does not match an exception will be raised. Valid options: String containing a regex. Default: Undefined.
137+
* `match_for_absence`: An optional value to determine if match should be applied when `ensure => absent`. If set to true and match is set, the line that matches match will be deleted. If set to false (the default), match is ignored when `ensure => absent` and the value of `line` is used instead. Default: false.
99138
* `multiple`: Determines if `match` and/or `after` can change multiple lines. If set to false, an exception will be raised if more than one line matches. Valid options: 'true', 'false'. Default: Undefined.
100139
* `name`: Sets the name to use as the identity of the resource. This is necessary if you want the resource namevar to differ from the supplied `title` of the resource. Valid options: String. Default: Undefined.
101140
* `path`: **Required.** Defines the file in which Puppet will ensure the line specified by `line`. Must be an absolute path to the file.
102141
* `replace`: Defines whether the resource will overwrite an existing line that matches the `match` parameter. If set to false and a line is found matching the `match` param, the line will not be placed in the file. Valid options: true, false, yes, no. Default: true
103142

104-
105143
### Functions
106144

107145
#### `abs`
@@ -405,7 +443,7 @@ Returns an array an intersection of two. For example, `intersection(["a","b","c"
405443

406444
#### `is_a`
407445

408-
Boolean check to determine whether a variable is of a given data type. This is equivalent to the `=~` type checks. This function is only available in Puppet 4, or when using the "future" parser.
446+
Boolean check to determine whether a variable is of a given data type. This is equivalent to the `=~` type checks. This function is only available in Puppet 4, or when using the "future" parser.
409447

410448
~~~
411449
foo = 3

lib/puppet/type/file_line.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Ensures that a given line is contained within a file. The implementation
55
matches the full line, including whitespace at the beginning and end. If
66
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
7+
the end of the file to ensure the desired state. Multiple resources may
88
be declared to manage multiple lines in the same file.
99
1010
Example:
@@ -31,7 +31,7 @@
3131
match => '^export\ HTTP_PROXY\=',
3232
}
3333
34-
In this code example match will look for a line beginning with export
34+
In this code example match will look for a line beginning with export
3535
followed by HTTP_PROXY and replace it with the value in line.
3636
3737
Match Example With `ensure => absent`:
@@ -50,7 +50,6 @@
5050
5151
**Autorequires:** If Puppet is managing the file that will contain the line
5252
being managed, the file_line resource will autorequire that file.
53-
5453
EOT
5554

5655
ensurable do
@@ -63,10 +62,10 @@
6362
end
6463

6564
newparam(:match) do
66-
desc 'An optional ruby regular expression to run against existing lines in the file.' +
65+
desc 'An optional ruby regular expression to run against existing lines in the file.' +
6766
' If a match is found, we replace that line rather than adding a new line.' +
68-
' A regex comparisson is performed against the line value and if it does not' +
69-
' match an exception will be raised. '
67+
' A regex comparison is performed against the line value and if it does not' +
68+
' match an exception will be raised.'
7069
end
7170

7271
newparam(:match_for_absence) do

0 commit comments

Comments
 (0)