Skip to content

Instantly share code, notes, and snippets.

@peterfroehlich
Last active August 29, 2015 13:57
Show Gist options
  • Save peterfroehlich/9660897 to your computer and use it in GitHub Desktop.
Save peterfroehlich/9660897 to your computer and use it in GitHub Desktop.
Salt executor method to sync files to syndics
def sync_syndic():
'''
Sync defined folders and files from the salt master to the syndic fileserver
Looks for production specific top file to replace top.sls on syndics
'''
base_dir = "/srv/salt/"
dirs_to_sync = ["salt-cloud", "_modules", "_grains", "_runners", "scripts", "states"]
files_to_sync = []
production_top = "top-prod.sls"
file_counter = 0
dir_counter = 0
output = []
for dir in dirs_to_sync:
complete_path = base_dir #+ dir
dir_counter += 1
output += __salt__["cp.get_dir"]("salt://"+dir, complete_path)
for file_ in files_to_sync:
complete_path = base_dir + file_
file_counter += 1
output += [__salt__["cp.get_file"]("salt://"+file_, complete_path)]
# copy production top.sls
complete_path = base_dir + "top.sls"
file_counter += 1
output += [__salt__["cp.get_file"]("salt://" + production_top, complete_path)]
return "\n".join(output) + "\n\nCopied files %d, copied dirs %d" % (file_counter, dir_counter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment