Hello,

I cannot fully understand what you are trying to do, as I do not know what 
$copyPrivateCommand is, but I would advice against using an exec for copying a 
file, but just use a file resource instead:

file { "${letsencryptConfPath}/live/${letsencryptCommonName}/privkey.pem":
  ensure => file,
  source => 
"${appEtcConfPath}/ssl/private/${letsencryptCommonName}.letsencrypt.${letsencryptKeySize}.key",
  notify => Exec['/usr/local/bin/apache.sh -c restart'],
  # Or better: notify => Service['apache'],
}



This should only copy the private key if the source is different from the 
target and only in that case restart Apache.



N.B. Avoid exec resources as much as possible, as they often result in overly 
complex Puppet code that is hard to debug.



-----Original message-----
From: Helmut Schneider <jumpe...@gmx.de>
Sent: Friday 30th August 2019 11:41
To: puppet-users@googlegroups.com
Subject: [Puppet Users] change from 'notrun' to ['0'] failed


Hi,

I want to copy a file if a diff fails:

exec { "Private key
'${letsencryptConfPath}/live/${letsencryptCommonName}/privkey.pem'
changed, updating":
  path        => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin',
  command     => "$copyPrivateCommand",
  unless      => "diff -q
${letsencryptConfPath}/live/${letsencryptCommonName}/privkey.pem
$appEtcConfPath/ssl/private/${letsencryptCommonName}.letsencrypt.$letsen
cryptKeySize.key > /dev/null",
  notify      => Exec['/usr/local/bin/apache.sh -c restart'],
  logoutput   => true,
}

This results in:

Debug: Executing: 'diff -q
/usr/local/etc/letsencrypt/live/www./privkey.pem
/usr/local/etc/ssl/private/www.letsencrypt.4096.key > /dev/null'
Error: no implicit conversion of nil into String
Error: /Stage[main]/Letsencrypt/Exec[Private key
'/usr/local/etc/letsencrypt/live/www/privkey.pem' changed,
updating]/returns: change from 'notrun' to ['0'] failed: no implicit
conversion of nil into String (corrective)
Debug: /Stage[main]/Letsencrypt/Exec[Copy live public key for www (SAN:
www)]: 'cp -L /usr/local/etc/letsencrypt/live/www/fullchain.pem
/usr/local/etc/ssl/www.letsencrypt.4096.crt' won't be executed because
of failed check 'refreshonly'

The diff itself runs fine:

[helmut@BSDHelmut ˜]$ sudo diff -q
/usr/local/etc/letsencrypt/live/www/privkey.pem
/usr/local/etc/ssl/private/www.letsencrypt.4096.key > /dev/null; echo $?
1
[helmut@BSDHelmut ˜]$

Where is the issue?

[helmut@BSDHelmut ˜]$ puppet -V
5.5.16
[helmut@BSDHelmut ˜]$

Thank you!

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/xn0lyako587brxt001%40news.gmane.org.


-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/zarafa.5d6a9803.3d29.44815fd24bf22aba%40anjie.dontpanic.nl.

Reply via email to