Greetings, I am working on streamlining some older puppet code, that uses a lot of Exec resources to accomplish it's purposes. It's not terribly elegant and we're working on design to replace it with code that leverages puppet features. One of the pieces I'm struggling with is how to set complex environment variables that are available to use in onlyif/unless statements as well as the command itself. I'm wondering if this just isn't possible?
Here's an example with the aide. NOTE that we're not in a spot where I can make puppet manage the aide config file, and thus use an aide module and parameters instead of shell variables. All of these commands run successfully in a bash shell for the various conditions that would apply. I have other similar scenarios, but aide is one of the more complex ones. exec { 'init-aide-database': path => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', environment => [ 'DBDIR=$(egrep \'^@@define DBDIR \' /etc/aide.conf|awk \'{print $NF}\')', 'DBFILE=$(egrep \'^database=file\' /etc/aide.conf|awk -F/ \'{print $NF}\')', 'DBNEW=$(egrep \'^database_out=file\' /etc/aide.conf|awk -F/ \'{print $NF}\')', ], command => '/usr/sbin/aide --init >/dev/null 2>&1 && cp -p ${DBDIR}/${DBNEW} ${DBDIR}/${DBFILE}', unless => 'test -f ${DBDIR}/${DBNEW} && test -f ${DBDIR}/${DBFILE}' , require => Package['aide'], logoutput => true, timeout => 0, } When executing, puppet always runs the exec because the env var's are empty, so the unless case always fails. Then we get a scenario where we're running aide --init when it's not needed and the cp command throws an error due to empty variables. My thought at the moment is that I need to build two shell scripts as file resources. One to call in the unless test, and another to call in the command if the unless script fails. Perhaps that's more elegant, but we're hoping to avoid delivering script files to the nodes wherever possible. I'm hoping the gurus out here might point me in the best direction! Thank you kindly! -- 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/d4a7a101-cb24-46e3-98a6-4ad42b2345cc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.