Last active
December 11, 2015 17:19
-
-
Save brk3/4633884 to your computer and use it in GitHub Desktop.
Quick tool to manage Chef knife configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import sys | |
chefdir = os.path.join(os.getenv('HOME'), '.chef') | |
if len(sys.argv) != 2: | |
print 'Usage: change_knife [-l|env]' | |
exit(1) | |
env = sys.argv[1] | |
if env == '-l': | |
for i in os.listdir(chefdir): | |
if i.endswith('.pem'): | |
print(i.split('.')[1]) | |
else: | |
try: | |
target = os.path.join(chefdir, 'knife.rb') | |
if os.path.isfile(target): | |
os.remove(target) | |
source = ''.join([target, '.', env]) | |
os.symlink(source, target) | |
except IOError as e: | |
print e | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment