Skip to content

Instantly share code, notes, and snippets.

@j1n6
Last active June 6, 2016 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j1n6/8e42dfefde5c933dfe77d772ec34f0bb to your computer and use it in GitHub Desktop.
Save j1n6/8e42dfefde5c933dfe77d772ec34f0bb to your computer and use it in GitHub Desktop.
Script and schema to manage Salt Fomulars dependencies from third party formula using git
# A yaml format file to pull dependencies into your own salt state
dependencies:
# local formular namespace will be called ntp
ntp:
# git repository
source: git@github.com:saltstack-formulas/ntp-formula.git
# copy sub directory as the root state
source_path: ntp
# version of the git repository
version: 4bc3bb91549db91e8cf9089899cc1139631a92c9
kubernetes:
source: git@github.com:kubernetes/kubernetes.git
# Copy github.com/kubernetes/kubernetes/cluster/saltbase/salt to -> {my state folder}/kubernetes
source_path: cluster/saltbase/salt
version: 6460b341282759d7cba7fe50b69082c6f0d9e942
# Pulls git into local file system
import yaml
import os
import shutil
import glob
from subprocess import call
working_dir = os.path.dirname(os.path.realpath(__file__))
custom_grains_dir = os.path.join(working_dir, '_grains')
def git_clone(repo, version, path, source_path):
# Old module clean up
call(["rm", "-rf", path])
# Update/Clone new modules into the temp directory
temp_folder = "tmp_" + path
call(["git", "clone", "-o", version, repo, temp_folder, "--depth=1"])
if source_path:
call(["mv", os.path.join(temp_folder, source_path), os.path.join(working_dir, path)])
for filename in glob.glob(os.path.join(temp_folder, '_grains' , '*.py')):
shutil.copy(filename, custom_grains_dir)
call(["rm", "-rf", temp_folder])
saltfile_byte = open("Saltfile", "r")
saltfile = yaml.load(saltfile_byte)
for key, value in saltfile['dependencies'].iteritems():
git_clone(value['source'], value['version'], key, value['source_path'])

Create Saltfile in state directory Specify dependencies Saltfile

Run the following command:

python Saltfile.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment