Issue #7695 has been updated by Nick Fagerlund.

Hmm. OK, that seems to be a drop-in replacement, if your platform's grep has 
those switches. I'll add it to the wiki. Thanks!
----------------------------------------
Bug #7695: line "absent" example on wiki errors out on Ubuntu
https://projects.puppetlabs.com/issues/7695

Author: Peter Lieverdink
Status: Accepted
Priority: Normal
Assignee: Nick Fagerlund
Category: 
Target version: 
Keywords: 
Branch: 
Affected URL: 
http://projects.puppetlabs.com/projects/1/wiki/Simple_Text_Patterns


To manage ssh public keys in an ssh authorized_keys file I used the first code 
listing at http://projects.puppetlabs.com/projects/1/wiki/Simple_Text_Patterns

It happily adds lines if they're not present, but when I had to remove a key 
from the file it started erroring out. As per the syslog:

<blockquote>
May 26 06:30:08 drseuss puppet-agent[11312]: (/Whit[post]) Dependency 
Exec[/usr/bin/perl -ni -e 'print unless 
/^\Qcommand="/usr/local/bin/validate-backup-cmd",from="drseuss",no-port-forwarding,no-X11-forwarding,no-pty
 ssh-rsa AAAAB3NzaC..[snip]..K9qYOatVq1S6n rsnapshot ssh key\E$/' 
'/root/.ssh/authorized_keys'] has failures: true
</blockquote>

Running the perl command via the CLI I got:

<pre>
Bareword found where operator expected at -e line 1, near "/^command="/usr"
        (Missing operator before usr?)
String found where operator expected at -e line 1, near "cmd",from=""
Bareword found where operator expected at -e line 1, near "",from="drseuss"
        (Missing operator before drseuss?)
String found where operator expected at -e line 1, at end of line
        (Missing semicolon on previous line?)
syntax error at -e line 1, near "/^command="/usr"
Can't find string terminator '"' anywhere before EOF at -e line 1.
</pre>

I expect perl is unhappy about the use of quotes in the line it should be 
checking.

The solution I found that works is using grep -v and tee:

<pre>
define line($file, $line, $ensure = 'present') {
    case $ensure {
        default : { err ( "unknown ensure value ${ensure}" ) }
        present: {
            exec { "/bin/echo '${line}' >> '${file}'":
                unless => "/bin/grep -qFx '${line}' '${file}'"
            }
        }
        absent: {
            exec { "/bin/grep -vFx '${line}' '${file}' | /usr/bin/tee '${file}' 
> /dev/null 2>&1":
                onlyif => "/bin/grep -qFx '${line}' '${file}'"
            }
        }
    }
}
</pre>

It might be worth a note on the wiki page.


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to