Ask Your Question
0

Requires for exec not working

asked 2015-06-12 18:08:10 -0500

mterrats gravatar image

Hello,

I have a simple class which will check if /etc/init.d/csf exists, and if it doesn't, it'll download the installer, run it and clean up the temp files. Here is the config.

class install_csf2 {

    exec { 'download_csf':
            command => 'wget

http://www.configserver.com/free/csf.tgz -O /tmp/csf.tgz', path => '/usr/bin', creates => '/tmp/csf.tgz', logoutput => true, onlyif => "/usr/bin/test ! -f /etc/init.d/csf", notify => Exec['unzip_csf'], }

    exec { 'unzip_csf':
            command => 'tar vxzf /tmp/csf.tgz -C /tmp',
            path    => '/bin/',
            creates => '/tmp/csf/',
            require => Exec['download_csf'],
            logoutput => true,
            refreshonly => true,
    }

    exec { 'install_csf':
            command => 'sh /tmp/csf/install.sh',
            cwd     => '/tmp/csf/',
            path    => '/bin/',
            require => Exec['unzip_csf'],
            creates => '/etc/init.d/csf',
            logoutput => true,
    }

    exec { 'cleanup_install_files':
            command => 'rm -rf /tmp/csf/ /tmp/csf.tgz',
            path    => '/bin/',
            require => Exec['unzip_csf'],
            logoutput => true,
    }

}

However, the problem I'm having is that it likes to do tasks even though they require other tasks. Here is my log:

Debug: Execdownloadcsf: Executing check '/usr/bin/test ! -f /etc/init.d/csf' Debug: Executing: '/usr/bin/test ! -f /etc/init.d/csf' Debug: Execcleanupinstallfiles: Executing 'rm -rf /tmp/csf/ /tmp/csf.tgz' Debug: Executing: 'rm -rf /tmp/csf/ /tmp/csf.tgz' Notice: /Stage[main]/Installcsf2/Exec[cleanupinstallfiles]/returns: executed successfully Debug: /Stage[main]/Installcsf2/Exec[cleanupinstallfiles]: The container Class[Installcsf2] will propagate my refresh event Debug: Class[Install_csf2]: The container Stage[main] will propagate my refresh event

So, it runs the first test if the file exists, realizes it exists, skips the unzip, install, and does the cleanup. It shouldn't do the cleanup unless unzip_csf runs, which it doesn't appear to.

What am I missing here?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-06-14 19:48:20 -0500

cbarbour gravatar image

updated 2015-06-14 19:49:07 -0500

require sets an order relationship, and prevents the resource from being evaluated if the dependency fails. You're probably looking for the refreshonly parameter for the exec resource.

With that said, I advise against using long chains of refreshonly resources to install things. Such strings of resources are not convergent; e.g. if a previous step fails, there's a chance that future steps will never be evaluated leaving the machine in an inconsistent state.

It's better to write a conditional for each step, and set an order. That way, if any individual step fails, you can be assured that future steps should succeed.

E.g.

  • The download step conditional should MD5sum the downloaded file, OR md5sum a file from the extracted archive.
  • The unzip conditional should MD5sum a file from the extracted archive
  • The install step should only run if it can't execute the --version or --help argument from the installed application.
  • The cleanup step should only run if the files that should be removed exist.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-06-12 18:08:10 -0500

Seen: 534 times

Last updated: Jun 14 '15