summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorAlex Harvey <Alex_Harvey@amp.com.au>2017-09-29 16:14:37 +1000
committerAlex Harvey <Alex_Harvey@amp.com.au>2017-09-29 16:25:47 +1000
commitad5d92461596d8d0b1c001d49061d70b36761d59 (patch)
tree4b601143c1d4e665e8a715596bfb5fbd87f17801 /README.md
parent2b2b3870ec1737dc78ec402c2dccbb7b65a2ef8f (diff)
(maint) Clarify docs and add new tests
Based on a Stack Overflow question, it was noted that the documentation for `file_line` isn't complete and the underlying behaviour somewhat confusing. https://stackoverflow.com/questions/46468922/how-to-change-the-contents-of-a-file-by-using-puppet/46473458 In this patch I add additional unit tests and better examples and complete documentation.
Diffstat (limited to 'README.md')
-rw-r--r--README.md46
1 files changed, 36 insertions, 10 deletions
diff --git a/README.md b/README.md
index ac4f997..2b6a64b 100644
--- a/README.md
+++ b/README.md
@@ -117,29 +117,55 @@ In the example above, `match` looks for a line beginning with 'export' followed
Match Example:
- file_line { 'bashrc_proxy':
- ensure => present,
- path => '/etc/bashrc',
- line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
- match => '^export\ HTTP_PROXY\=',
- append_on_no_match => false,
- }
+```puppet
+file_line { 'bashrc_proxy':
+ ensure => present,
+ path => '/etc/bashrc',
+ line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
+ match => '^export\ HTTP_PROXY\=',
+ append_on_no_match => false,
+}
+```
In this code example, `match` looks for a line beginning with export followed by HTTP_PROXY and replaces it with the value in line. If a match is not found, then no changes are made to the file.
-Match Example with `ensure => absent`:
+Examples With `ensure => absent`:
+
+This type has two behaviors when `ensure => absent` is set.
+
+One possibility is to set `match => ...` and `match_for_absence => true`,
+as in the following example:
```puppet
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 the example above, `match` looks for a line beginning with 'export' followed by 'HTTP_PROXY' and deletes it. If multiple lines match, an error is raised, unless the `multiple => true` parameter is set.
+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.
+
+Note that the `line => ...` parameter would be accepted *but ignored* in
+the above example.
+
+The second way of using `ensure => absent` is to specify a `line => ...`,
+and no match:
+
+```puppet
+file_line { 'bashrc_proxy':
+ ensure => absent,
+ path => '/etc/bashrc',
+ line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128',
+}
+```
+
+Note that when ensuring lines are absent this way, the default behavior
+this time is to always remove all lines matching, and this behavior
+can't be disabled.
Encoding example: