I'm trying to have my master send a script to a minion that backs up a database and some files. I then want my Master to rsync the files that have been created from the backup script so I fire an event that the backup is complete to the master. The master handles the event in a Reactor and starts a Runner that performs the rsync.
I want my minion to wait for the Runner to complete and return before it reports that the state 'backup-complete' was successful. Currently the minion simply reports that the state executed successfully without waiting for the response of the Runner.
My current setup works like this:
Run the backup script on the minion from the the master
salt 'minion' state.sls backup
The minion triggers an event that the backup is complete (and returns immedieately)
backup-complete:
module.run:
- name: 'event.fire_master'
- fun: fire_master
- tag: backup/complete
- data: {"status":"Backup complete"}
The master has a Reactor that catches the event and calls a Runner
backup_complete:
runner.sync-backup.sync:
- status: {{ data['data']['status'] }}
The Runner then executes an rsync command to sync the files and directories and returns the exit code
def sync(status):
command = "myrsyncscript.sh arg0 arg1"
result = os.system(command) >> 8
return result
I've been thinking about having the minion wait and listen for an 'rsync/complete' event triggered by the master but I can't find how to create eventlisteners on the minion nor how to make it wait. Another solution I've looked at is the 'salt.modules.cp.push' although the documentation warns agains using this for security reasons.
The solution seems overly complicated to me so perhaps I am approaching this the wrong way. All thoughts are welcome.
You can run a reactor on the minion, but I'm pretty sure it only listens on its own event bus. I don't believe there is a command to send a message from the Master to the Minion over the event bus.
I think your best bet is to have your runner on the Master execute a call on the Minion through Salt's normal execution modules.