Ask Your Question

How can I trigger a remote puppet run on a host every time a file changes or gets uploaded to the puppet master version 2015.2+

asked 2015-10-07 11:48:35 -0600

michaelokoluko gravatar image

updated 2015-10-07 16:24:04 -0600

So basically I’m looking to trigger a “puppet run” on a remote node every time an existing file ( in /modules/dowloadscript/files/ on the puppet master changes or gets uploaded with a new copy.

Can this be done by the following resource type; Cron, Augeas, Exec e.t.c. If it helps below is my current code that (it works – but needs further automation – don’t want to keep manually running the agent command on the remote box once this file is uploaded – I need a trigger on the master once a new file is uploaded) downloads file from the master, unzip it onto the windows directory /temp and execute the server build using PowerShell – I have hashed (#)out some attributes for now as they keep failing - either wrong parameter or invalid command – any pointers?

class downloadscript { file { 'C:\puppetfolder\downloadtest.ps1':

ensure  => 'present',
source  => 'puppet:///modules/downloadscript/downloadtest.ps1',
mode    => '0775',
owner   => 'Administrator',
group   => 'Administrator',

} -> file { 'C:\puppetfolder\downloadtest.bat':

ensure  => 'present',
source  => 'puppet:///modules/downloadscript/downloadtest.bat',
mode    => '0775',
owner   => 'Administrator',
group   => 'Administrator',

} -> file { 'C:\puppetfolder\7z.dll':

ensure   => 'present',
source   => 'puppet:///modules/downloadscript/7z.dll',
mode     => '0775',
owner    => 'Administrator',
group    => 'Administrator',
provider => 'windows',

} -> file { 'C:\puppetfolder\7z.exe':

ensure   => 'present',
source   => 'puppet:///modules/downloadscript/7z.exe',
mode     => '0775',
owner    => 'Administrator',
group    => 'Administrator',
provider => 'windows',

} -> file { 'C:\puppetfolder\':

ensure   => 'file',
source   => 'puppet:///modules/downloadscript/',
checksum => 'mtime',
#notify   => 'Exec["install_c:\\puppetfolder\downloadtest.ps1"]',
mode     => '0775',
owner    => 'Administrator',
group    => 'Administrator',

} -> exec {'unpacking_c:\puppetfolder\':

path         => 'c:\\puppetfolder\\7z.exe',
command      => 'C:\\puppetfolder\\7z.exe -y x C:\\puppetfolder\\ -oc:\\temp',
logoutput    =>  true,
provider     => 'windows',

} -> exec { 'install_c:\puppetfolder\downloadtest.ps1':

command     => 'C:\\puppetfolder\\downloadtest.bat',
#unless      => 'Test-Path path "puppet:///modules/downloadscript/" { exit 1 } else {exit 0}',
#subscribe   => 'File["puppet:///modules/downloadscript/"]',
logoutput   => true,
refreshonly => true,

} }

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-11-12 02:53:21 -0600

Cristian Falcas gravatar image

You could implement this with a script that watches on master for changes on the file and triggers a puppet run with mcollective.

Check this post on a way to implement the watcher: How to continuosly monitor the directory using dnotify /inotify command

Read on how to decide when the file has finished copying on inotify documentation.

edit flag offensive delete link more


Inotify is what I was thinking of also. It looks like Micheal is on Windows however and might need to find an an inotify like process. SO has some suggestions. This will work if you only have a few nodes.

scoffland gravatar imagescoffland ( 2015-11-13 08:21:29 -0600 )edit

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


Asked: 2015-10-07 11:48:35 -0600

Seen: 925 times

Last updated: Nov 12 '15