#!/usr/bin/env python from __future__ import print_function import sys import subprocess import six.moves.configparser import re force = False extra_args = sys.argv[1:] if len(extra_args) and extra_args[0] in ('-f', '--force'): force = True extra_args = extra_args[1:] config = six.moves.configparser.RawConfigParser() config.read("/etc/zulip/zulip.conf") puppet_config = """ Exec { path => "/usr/sbin:/usr/bin:/sbin:/bin" } include apt """ for pclass in re.split(r'\s*,\s*', config.get('machine', 'puppet_classes')): puppet_config += "include %s\n" % (pclass,) puppet_cmd = ["puppet", "apply", "--modulepath=/root/zulip/puppet", "-e", puppet_config] puppet_cmd += extra_args 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)