Hi,
I wanted to create a recipe for hashing a line in a file (I'd rather hash it than delete it), if the file is present and that particular line is present. I came up with a less than elegant solution and wondered whether
someone knows of a better way.
The file in question: /usr/share/X11/xorg.conf.d/glamor.conf
The line in question (which needs to be commented): Load "glamoregl"
exec { 'hash_glamor':
path => '/bin:/usr/sbin:/usr/bin',
command => 'sed -i \'s/\(^\s*Load\s*\"glamoregl\"$\)/\#\1/\' /usr/share/X11/xorg.conf.d/glamor.conf',
onlyif => 'grep -E "^\s*Load\s*\"glamoregl\"$" /usr/share/X11/xorg.conf.d/glamor.conf',
}
I tried using the 'file_line' module:
file_line { 'hash_glamor':
path => '/usr/share/X11/xorg.conf.d/glamor.conf',
line => '# Load "glamoregl"',
match => 'Load "glamoregl"',
}
but this returns an error if the file doesn't exist, and I couldn't find a way of adding a conditional that will check whether the file exists in the 'file_line' module before it executes.
Augeas could be a possibility, but I couldn't see a way of doing it in a simple way.
Any suggestions welcome.
Thanks,
Cam