Tuesday, February 14, 2012

editfiles cfengine v2

I had the task of disabling swap on a class of machines managed by cfengine2

The swap entry could have started with 'UUID=', or possibly '/dev/sda3'


One way of doing it:


editfiles:
    { /etc/fstab

            CommentLinesMatching ".*swap(\s+)swap(\s+).*"
     }

another, more complicated way:


editfiles:
    { /etc/fstab
        ReplaceAll "swap(\s+)swap(\s+)defaults(\s+)0(\s+)0$" With "swap                    swap    noauto,defaults        0 0"
}

Normally, with editfiles, you must match the whole line (hence the .* at the beginning and end of the first way using 'CommentLines'), but when matching a quoted regex (as with 'ReplaceAll'), you can just match (and replace) that part of the line


No comments: