2

I have a pp manifest like this:

vcsrepo { '/home/pi/pop_machine':
  ensure   => latest,
  provider => git,
  source   => 'https://github.com/kirkins/pop-machine-demo.git',
  revision => 'master',
}

exec { 'npm start':
  command => "/usr/bin/killall electron & /usr/bin/npm start",
  cwd     => "/home/pi/pop_machine/",
}

I want the exec resource to restart the device application only if the vcsrepo resource found an update on github and made changes.

Would this be possible with puppet alone, or should I write a bash script to check the last time the .git folder was updated?

Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67
Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225

2 Answers2

0

You can use the metaparameter subscribe and parameter refreshonly with your exec resource to accomplish this.

First, use the subscribe metaparmeter to establish an ordering relationship of the exec on the vcsrepo and to also check for a resource change: https://docs.puppet.com/puppet/latest/metaparameter.html#subscribe

Next, use refreshonly to instruct the exec resource to only apply a change if the vcsrepo repo effected a change (vis a vis non-idempotent): https://docs.puppet.com/puppet/latest/types/exec.html#exec-attribute-refreshonly

It would look like:

vcsrepo { '/home/pi/pop_machine':
  ensure   => latest,
  provider => git,
  source   => 'https://github.com/kirkins/pop-machine-demo.git',
  revision => 'master',
}

exec { 'npm start':
  command     => "/usr/bin/killall electron & /usr/bin/npm start",
  cwd         => "/home/pi/pop_machine/",
  subscribe   => Vcsrepo['/home/pi/pop_machine'],
  refreshonly => true,
}
Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67
0

Matt Schuchard's answer didn't work for me. I kept getting an error from puppet because of the "subscribe" in the "exec":

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Could not autoload puppet/type/vcsrepo: Attempt to redefine entity 'http://puppet.com/2016.1/runtime/type/vcsrepo'.

But this did work for me:

vcsrepo { '/home/pi/pop_machine':
  ensure   => latest,
  provider => git,
  source   => 'https://github.com/kirkins/pop-machine-demo.git',
  revision => 'master',
  notify   => Exec['npm start'],
}

exec { 'npm start':
  command     => "/usr/bin/killall electron & /usr/bin/npm start",
  cwd         => "/home/pi/pop_machine/",
  refreshonly => true,
}
Ken Roy
  • 915
  • 1
  • 10
  • 15