2016-04-07 15:03:22 +02:00
|
|
|
#!/usr/bin/env python
|
2013-05-31 21:04:49 +02:00
|
|
|
|
2016-07-01 19:15:46 +02:00
|
|
|
from __future__ import print_function
|
2016-07-31 03:01:37 +02:00
|
|
|
import os
|
2013-10-07 22:08:16 +02:00
|
|
|
import sys
|
|
|
|
import subprocess
|
2016-07-23 20:33:58 +02:00
|
|
|
import six.moves.configparser as configparser
|
2013-11-01 00:00:30 +01:00
|
|
|
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
|
|
|
|
2016-07-23 20:33:58 +02:00
|
|
|
config = configparser.RawConfigParser()
|
2013-11-01 00:00:30 +01:00
|
|
|
config.read("/etc/zulip/zulip.conf")
|
2013-10-07 22:08:16 +02:00
|
|
|
|
2016-07-31 03:01:37 +02:00
|
|
|
if not os.path.exists("/etc/puppet/hiera.yaml"):
|
|
|
|
# Suppress warnings about hiera.yaml not existing.
|
|
|
|
subprocess.check_call(["touch", "/etc/puppet/hiera.yaml"])
|
|
|
|
|
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
|
|
|
|
2017-02-08 20:05:20 +01:00
|
|
|
# We use the puppet configuration from the same Zulip checkout as this script
|
|
|
|
puppet_module_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "puppet")
|
|
|
|
puppet_cmd = ["puppet", "apply", "--modulepath", puppet_module_path, "-e", puppet_config]
|
2013-10-07 22:08:16 +02:00
|
|
|
puppet_cmd += extra_args
|
|
|
|
|
2016-07-01 19:15:46 +02:00
|
|
|
if not force:
|
|
|
|
subprocess.check_call(puppet_cmd + ['--noop', '--show_diff'])
|
|
|
|
|
|
|
|
do_apply = None
|
|
|
|
while do_apply != 'y':
|
|
|
|
sys.stdout.write("Apply changes? [y/N] ")
|
|
|
|
do_apply = sys.stdin.readline().strip().lower()
|
|
|
|
if do_apply == '' or do_apply == 'n':
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
ret = subprocess.call(puppet_cmd + ['--detailed-exitcodes'])
|
|
|
|
# ret = 0 => no changes, no errors
|
|
|
|
# ret = 2 => changes, no errors
|
|
|
|
# ret = 4 => no changes, yes errors
|
|
|
|
# ret = 6 => changes, yes errors
|
|
|
|
if ret != 0 and ret != 2:
|
|
|
|
sys.exit(1)
|