Hi Guys,
So we have ~ 2k machines configured via Puppet. These have some ssh keys set that are now redundant and need removing I inherited the following (minimized) codebut it seems it can't cope with special chars like '/'/ & '@'; test run showsdefine 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 { "/usr/bin/perl -ni -e 'print unless /^\ +\Q${line}\\E\$/' '${file}'": onlyif => "/bin/grep -qFx -- '${line}' + '${file}'" } } } } line { 'ssh_key' : file => '/root/user/b1.bak', line => 'ssh-rsa AAAA/BBBB/knMQ== user@host.f.q.d.n', ensure => absent, }
I have tried various ways of quoting/escaping etc, but none seem to work. I would definitely appreciate a working solution Cheers Chris2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bi +n/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f. +q.d.n\E$/' '/root/user/b1.bak']/returns (notice): Having no space bet +ween pattern and following word is deprecated at -e line 1. 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bi +n/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f. +q.d.n\E$/' '/root/user/b1.bak']/returns (notice): Bareword found wher +e operator expected at -e line 1, near "/^\Qssh-rsa AAAA/BBBB" 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bi +n/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f. +q.d.n\E$/' '/root/user/b1.bak']/returns (notice): (Missing operat +or before BBBB?) 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bi +n/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f. +q.d.n\E$/' '/root/user/b1.bak']/returns (notice): Array found where o +perator expected at -e line 1, at end of line 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bi +n/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f. +q.d.n\E$/' '/root/user/b1.bak']/returns (notice): (Missing operat +or before ?) 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bi +n/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f. +q.d.n\E$/' '/root/user/b1.bak']/returns (notice): Bareword found wher +e operator expected at -e line 1, near "q.d.n" 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bi +n/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f. +q.d.n\E$/' '/root/user/b1.bak']/returns (notice): Backslash found whe +re operator expected at -e line 1, near "n\" 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bi +n/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f. +q.d.n\E$/' '/root/user/b1.bak']/returns (notice): syntax error at -e +line 1, near "/^\Qssh-rsa AAAA/BBBB" 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bi +n/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f. +q.d.n\E$/' '/root/user/b1.bak']/returns (notice): Execution of -e abo +rted due to compilation errors. 2019-11-27 21:49:14 +0000 Puppet (err): /usr/bin/perl -ni -e 'print un +less /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f.q.d.n\E$/' '/root/user/ +b1.bak' returned 255 instead of one of [0] 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bi +n/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f. +q.d.n\E$/' '/root/user/b1.bak']/returns (err): change from notrun to +0 failed: /usr/bin/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/kn +MQ== user@host.f.q.d.n\E$/' '/root/user/b1.bak' returned 255 instead +of one of [0]
In reply to One liner: remove ssh keys with quotemeta by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |