2013-10-07 22:08:16 +02:00
|
|
|
#!/usr/bin/python
|
2013-05-31 21:04:49 +02:00
|
|
|
|
2013-10-07 22:08:16 +02:00
|
|
|
import sys
|
|
|
|
import subprocess
|
2013-11-01 00:00:30 +01:00
|
|
|
import ConfigParser
|
|
|
|
import re
|
2013-10-07 22:08:16 +02:00
|
|
|
|
|
|
|
force = False
|
|
|
|
extra_args = sys.argv[1:]
|
|
|
|
|
|
|
|
if len(extra_args) and extra_args[0] in ('-f', '--force'):
|
|
|
|
force = True
|
2013-11-05 19:37:55 +01:00
|
|
|
extra_args = extra_args[1:]
|
2013-10-07 22:08:16 +02:00
|
|
|
|
2013-11-01 00:00:30 +01:00
|
|
|
config = ConfigParser.RawConfigParser()
|
|
|
|
config.read("/etc/zulip/zulip.conf")
|
2013-10-07 22:08:16 +02:00
|
|
|
|
2013-11-01 00:00:30 +01:00
|
|
|
puppet_config = """
|
|
|
|
Exec { path => "/usr/sbin:/usr/bin:/sbin:/bin" }
|
2013-11-01 20:28:03 +01:00
|
|
|
include apt
|
2013-11-01 00:00:30 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
for pclass in re.split(r'\s*,\s*', config.get('machine', 'puppet_classes')):
|
2013-11-01 20:28:03 +01:00
|
|
|
puppet_config += "include %s\n" % (pclass,)
|
2013-11-01 00:00:30 +01:00
|
|
|
|
2015-09-27 06:26:50 +02:00
|
|
|
puppet_cmd = ["puppet", "apply", "--modulepath=/root/zulip/puppet", "-e", puppet_config]
|
2013-10-07 22:08:16 +02:00
|
|
|
puppet_cmd += extra_args
|
|
|
|
|
|
|
|
if force:
|
|
|
|
subprocess.check_call(puppet_cmd)
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
subprocess.check_call(puppet_cmd + ['--noop', '--show_diff'])
|
|
|
|
|
|
|
|
do_apply = None
|
|
|
|
while not (do_apply == 'y' or do_apply == 'n'):
|
|
|
|
sys.stdout.write("Apply changes? [y/N] ")
|
|
|
|
do_apply = sys.stdin.readline().strip().lower()
|
|
|
|
if do_apply == '':
|
|
|
|
do_apply = 'n'
|
|
|
|
|
|
|
|
if do_apply == 'y':
|
|
|
|
subprocess.check_call(puppet_cmd)
|