Ask Your Question
0

Execute puppi::netinstall but ONLY if symlink/directory exists

asked 2016-03-10 17:18:40 -0500

greywindow gravatar image

Hello all,
We're using puppi::netinstall to download zip file, extract it and then we make a symlink to that directory (in short version). I'm trying to figure it out a way to invoke puppi::netinstall but ONLY if symlink doesn't exist and can't get that to work for some reason.

Basically: If symlink DOESN'T exist run puppi::netinstall.

Here's the code we have for now:

class logstash::install (
  $LogstashLinkVersionExist = '',
) {

    $retrieve_args = "${logstash::yum_proxy_host}" ? {
        /.+/    => "-e use_proxy=yes -e http_proxy=${logstash::yum_proxy_host}:${logstash::yum_proxy_port} -e https_proxy=${logstash::yum_proxy_host}:${logstash::yum_proxy_port}",
        default => '',
    }

    package { 'logstash':
        ensure => absent,
    }

    notify { 'SymlinkDoesNotExists':
      message => 'Symlink not there, creating.'
    }

    exec { 'LogstashLinkVersionExist':
      command => '/bin/false',
      onlyif  => "/usr/bin/test -L ${logstash::parent_dir}/logstash-${logstash::version}",
      path    => '/bin:/sbin:/usr/bin:/usr/sbin',
      notify  => Notify['SymlinkDoesNotExists'],
    }

      file { "${logstash::logstash_home}":
          ensure       => link,
          owner        => 'logstash',
          group        => 'logstash',
          target       => "${logstash::parent_dir}/logstash-${logstash::version}",
          require      => Puppi::Netinstall["logstash-${logstash::version}"],
      }

      puppi::netinstall { "logstash-${logstash::version}":
          url             => "https://download.elastic.co/logstash/logstash/logstash-${logstash::version}.zip",
          destination_dir => "${logstash::parent_dir}",
          retrieve_args   => "${logstash::retrieve_args}",
          owner           => 'logstash',
          group           => 'logstash',
          work_dir        => '/tmp',
          require         => [ Exec['LogstashLinkVersionExist'], Package['logstash'] ],
      }

}

but this invokes puppet::install and downloads zip file before Notify message.

Any help appreciated,

Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-03-10 19:35:00 -0500

lavaman gravatar image

You don't put resources in puppet code to attempt to determine the current state of the system. If you want your code to respond to the state of the system, you need a custom fact. However, if all you're trying to do is make sure the netinstall resource is applied whenever puppet has to create the symlink, you would simply have the netinstall resource subscribe to the file resource that creates the symlink.

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: 2016-03-10 17:18:40 -0500

Seen: 269 times

Last updated: Mar 10 '16