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 { "/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, } #### 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bin/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 between 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/bin/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 where 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/bin/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f.q.d.n\E$/' '/root/user/b1.bak']/returns (notice): (Missing operator before BBBB?) 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bin/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 operator expected at -e line 1, at end of line 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bin/perl -ni -e 'print unless /^\Qssh-rsa AAAA/BBBB/knMQ== user@host.f.q.d.n\E$/' '/root/user/b1.bak']/returns (notice): (Missing operator before ?) 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bin/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 where 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/bin/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 where operator expected at -e line 1, near "n\" 2019-11-27 21:49:14 +0000 /Stage[main]/Main/Line[ssh_key]/Exec[/usr/bin/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/bin/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 aborted due to compilation errors. 2019-11-27 21:49:14 +0000 Puppet (err): /usr/bin/perl -ni -e 'print unless /^\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/bin/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/knMQ== user@host.f.q.d.n\E$/' '/root/user/b1.bak' returned 255 instead of one of [0]