line.pp

 1 # line.pp - This file defines the "line" type that allows management of 
 2 #           distinct lines in configuration files
 3 #
 4 # Adapted shamelessly from: 
 5 #    http://www.reductivelabs.com/trac/puppet/wiki/SimpleTextRecipes
 6 # I will change/remove copyrights on request.
 7 #
 8 # Copyright 2007 Barak Korren
 9 #
10 #    This program is free software: you can redistribute it and/or modify
11 #    it under the terms of the GNU General Public License as published by
12 #    the Free Software Foundation, either version 3 of the License, or
13 #    (at your option) any later version.
14 #
15 #    This program is distributed in the hope that it will be useful,
16 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 #    GNU General Public License for more details.
19 #
20 #    You should have received a copy of the GNU General Public License
21 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 #
23 
24 define line($file, $line, $ensure = 'present') {
25    case $ensure {
26       default : { err ( "unknown ensure value ${ensure}" ) }
27       present: {
28          exec { "/bin/echo '${line}' >> '${file}'":
29             unless => "/bin/grep -qFx '${line}' '${file}'"
30          }
31       }
32       absent: {
33          exec { "/usr/bin/perl -ni -e 'print unless /^\\Q${line}\\E\$/' '${file}'":
34             onlyif => "/bin/grep -qFx '${line}' '${file}'"
35          }
36       }
37    }
38 }
39  
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s