Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a command using puppet only if it has not been executed earlier

Tags:

puppet

Suppose I want to make sure that my VM has devstack on it.

exec{ "openstack":
  command => "git clone https://git.openstack.org/openstack-dev/devstack",
}

This is the puppet code I write for it and it works fine for the first time. Now I want to put a check. I want to clone the repository only if it has not been done already. How to do that

like image 373
Atmesh Mishra Avatar asked Jan 27 '26 07:01

Atmesh Mishra


2 Answers

You say

exec { 'openstack':
  command => 'git clone https://git.openstack.org/openstack-dev/devstack',
  creates => '/path/to/somewhere/devstack',
  cwd     => '/path/to/somewhere',
  path    => '/usr/bin',
}

Now if the directory /path/to/somewhere/devstack exists the clone command won't run.

like image 126
Alex Harvey Avatar answered Jan 29 '26 00:01

Alex Harvey


exec { "openstack":
  command => 'git clone https://git.openstack.org/openstack-dev/devstack /path/to/devstack",
  unless => 'test -d /path/to/devstack'
}

its a really hacky way to handle this. you should look into the vcsrepo puppet module https://github.com/puppetlabs/puppetlabs-vcsrepo

like image 40
ptierno Avatar answered Jan 28 '26 22:01

ptierno



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!