|
23 | 23 | ================================
|
24 | 24 | """
|
25 | 25 | import os
|
| 26 | +import re |
26 | 27 | import glob
|
27 | 28 | import shutil
|
28 | 29 | import time
|
@@ -61,6 +62,10 @@ def add_plugin_args(self):
|
61 | 62 | action=conf_action(self._config.plugins[self.full_name]),
|
62 | 63 | help='Extra arguments for Puppet. Can be used to include a Puppet class with -e.')
|
63 | 64 |
|
| 65 | + puppet_config.add_argument('--puppet-env-vars', dest='puppet_env_vars', |
| 66 | + action=conf_action(self._config.plugins[self.full_name]), |
| 67 | + help='Environment arguments for Puppet, delimited by a semi-colon. Can be used to do things like pass custom Facter facts.') |
| 68 | + |
64 | 69 | puppet_config.add_argument('--puppet-master', dest='puppet_master',
|
65 | 70 | action=conf_action(self._config.plugins[self.full_name]),
|
66 | 71 | help='Hostname of Puppet Master')
|
@@ -100,12 +105,22 @@ def provision(self):
|
100 | 105 | self._decide_puppet_run_mode()
|
101 | 106 | self._pre_chroot_block()
|
102 | 107 |
|
| 108 | + if re.compile('\S=\S').search(self._get_config_value('puppet_env_vars')): |
| 109 | + parsed_env_vars = dict([x.split('=') for x in re.compile("\s?;\s?").split(self._get_config_value('puppet_env_vars'))]) |
| 110 | + log.info("\tAdding to Puppet apply environment:") |
| 111 | + for key, value in parsed_env_vars.iteritems(): |
| 112 | + log.info("\t{0}={1}".format(key,value)) |
| 113 | + log.info('=========================================================================================================') |
| 114 | + os.environ.update( parsed_env_vars ) |
| 115 | + |
103 | 116 | log.debug('Entering chroot at {0}'.format(self._distro._mountpoint))
|
104 | 117 | with Chroot(self._distro._mountpoint):
|
105 | 118 |
|
106 | 119 | self._install_puppet()
|
107 | 120 |
|
108 |
| - escaped_args = self._escaped_puppet_args() |
| 121 | + escaped_args = self._escaped('puppet_args') |
| 122 | + |
| 123 | + |
109 | 124 |
|
110 | 125 | if self._puppet_run_mode is 'master':
|
111 | 126 | log.info('Running puppet agent')
|
@@ -206,9 +221,9 @@ def _list_files(self, startpath):
|
206 | 221 | log.debug((len(path) - start_len + 1) * '---' + '{0}'.format(file))
|
207 | 222 | log.debug("********************************************************")
|
208 | 223 |
|
209 |
| - def _escaped_puppet_args(self): |
| 224 | + def _escaped(self, config_name): |
210 | 225 | import re
|
211 |
| - return re.sub('\s','\ ', self._get_config_value('puppet_args', '' )) |
| 226 | + return re.sub('\s','\ ', self._get_config_value(config_name, '' )) |
212 | 227 |
|
213 | 228 | def _decide_puppet_run_mode(self):
|
214 | 229 | if os.access( self._config.context.package.arg, os.F_OK ):
|
|
0 commit comments