mirror of https://github.com/zulip/zulip.git
puppet: Pass zulip scripts path as a FACTER to puppet.
This makes it possible for the Puppet codebase to access the path to the relevant /home/zulip/deployments type directory that puppet was run from, which in turn makes it possible to safely call scripts from here. Based on work by Rein Zustand.
This commit is contained in:
parent
978b37379b
commit
b3a4b78c6d
|
@ -8,6 +8,7 @@ import re
|
|||
from lib.zulip_tools import parse_lsb_release, assert_running_as_root
|
||||
|
||||
assert_running_as_root()
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
force = False
|
||||
extra_args = sys.argv[1:]
|
||||
|
@ -34,12 +35,17 @@ for pclass in re.split(r'\s*,\s*', config.get('machine', 'puppet_classes')):
|
|||
puppet_config += "include %s\n" % (pclass,)
|
||||
|
||||
# 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(os.path.abspath(__file__))), "puppet")
|
||||
scripts_path = os.path.join(BASE_DIR, "scripts")
|
||||
puppet_module_path = os.path.join(BASE_DIR, "puppet")
|
||||
puppet_cmd = ["puppet", "apply", "--modulepath", puppet_module_path, "-e", puppet_config]
|
||||
puppet_cmd += extra_args
|
||||
|
||||
# Set the scripts path to be a factor so it can be used by puppet code
|
||||
puppet_env = os.environ.copy()
|
||||
puppet_env["FACTER_zulip_scripts_path"] = scripts_path
|
||||
|
||||
if not force:
|
||||
subprocess.check_call(puppet_cmd + ['--noop', '--show_diff'])
|
||||
subprocess.check_call(puppet_cmd + ['--noop', '--show_diff'], env=puppet_env)
|
||||
|
||||
do_apply = None
|
||||
while do_apply != 'y':
|
||||
|
@ -49,7 +55,7 @@ if not force:
|
|||
if do_apply == '' or do_apply == 'n':
|
||||
sys.exit(0)
|
||||
|
||||
ret = subprocess.call(puppet_cmd + ['--detailed-exitcodes'])
|
||||
ret = subprocess.call(puppet_cmd + ['--detailed-exitcodes'], env=puppet_env)
|
||||
# ret = 0 => no changes, no errors
|
||||
# ret = 2 => changes, no errors
|
||||
# ret = 4 => no changes, yes errors
|
||||
|
|
Loading…
Reference in New Issue