Ask Your Question

Execute a list of resources only if path exist

asked 2017-04-26 03:14:45 -0600

I try to install jdk from source, simply decompress file in a location:

exec { "rm -f /tmp/${filename}":
  path    => [ "/bin" ],
  cwd     => "/tmp",
  command => "rm -f /tmp/${filename}",
  require => Exec["tar xzf /tmp/${filename} -C ${path}"],

exec { "tar xzf /tmp/${filename} -C ${path}":
  path    => [ "/bin/" ],
  cwd     => "/tmp",
  command => "tar xzf /tmp/${filename} -C ${path}",
  require => File["/tmp/${filename}"],

file { "/tmp/${filename}":
  source => "puppet:///software/java/${version}/${filename}",
  mode => '0755',
  require => File["${path}"],

file { "${path}":
  ensure => 'directory',
  owner  => 'root',
  group  => 'root',
  mode   => '0750',

but i can execute this only if not install previously. I want to do something like this:

if /opt/java/jdk1.8.0_20 directory don't exist {

executre resources


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-05-02 17:55:02 -0600

The only way I could find to do this was with a custom fact that used Ruby to query the local file system. In my case, I don't want to configure an apache vhost until Let's Encrypt has delivered me a certificate. However, the traditional method of using a requires means that the vhost startup fails, and then prevents all of apache starting up, meaning let's encrypt won't work.

Here's the custom fact code that I use. Modify it to match the conditions you require:

require "pathname"

cert_dir = "/etc/letsencrypt/live"

Facter.add(:webserver_certs_live) do
  live_certs_hash = {}

  if File.exists?(cert_dir)
    live_certs_hash =

  setcode do

Then in my module, I use this:

if $vhost_fqdn in $::webserver_certs_live {
  apache::vhost { ....
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


Asked: 2017-04-26 03:14:45 -0600

Seen: 51 times

Last updated: Apr 26 '17