Skip to content

Instantly share code, notes, and snippets.

@brk3
Last active December 11, 2015 17:19
Show Gist options
  • Save brk3/4633884 to your computer and use it in GitHub Desktop.
Save brk3/4633884 to your computer and use it in GitHub Desktop.
Quick tool to manage Chef knife configuration
#!/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