def _build_puppet_command(self):
"""
Refs:
https://github.com/mitchellh/vagrant/blob/9c299a2a357fcf87f356bb9d56e18a037a53d138/
plugins/provisioners/puppet/provisioner/puppet.rb#L173
"""
options = self.options.get('options', '')
options = list(map(shlex.quote, shlex.split(options)))
module_path = self.options.get('module_path')
if module_path is not None:
options += ['--modulepath',
'{}:{}'.format(self._guest_module_path,
self._guest_default_module_path)]
hiera_path = self.options.get('hiera_config_path')
if hiera_path is not None:
options += ['--hiera_config={}'.format(self._guest_hiera_file)]
# TODO: we are not detecting console color support now, but please contribute if you need!
options += ['--detailed-exitcodes']
environment_path = self.options.get('environment_path')
if environment_path is not None:
options += ['--environmentpath', str(self._guest_environment_path),
'--environment', self.options['environment']]
else:
options += ['--manifestdir', str(self._guest_manifests_path)]
manifest_file = self.options.get('manifest_file')
if manifest_file is not None:
options += [str(
PurePosixPath(self._guest_manifests_path) / manifest_file)]
# Build up the custom facts if we have any
facter = []
facter_dict = self.options.get('facter')
if facter_dict is not None:
for key, value in sorted(facter_dict.items()):
facter.append("FACTER_{}={}".format(key, shlex.quote(value)))
binary_path = self.options.get('binary_path')
if binary_path is not None:
puppet_bin = str(PurePosixPath(binary_path) / 'puppet')
else:
puppet_bin = 'puppet'
# TODO: working_directory for hiera. Please contribute!
env = []
env_variables = self.options.get('environment_variables')
if env_variables is not None:
for key, value in sorted(env_variables.items()):
env.append("{}={}".format(key, shlex.quote(value)))
command = env + facter + [puppet_bin, 'apply'] + options
return command
评论列表
文章目录