Skip to content

Commit aa30e0b

Browse files
committed
Merge pull request #2 from robsweet/master
Adding --puppet-env-vars argument to be able to supply custom facts
2 parents fd13fa7 + 4a89d5d commit aa30e0b

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ Then you will need to make add an environment that uses the Puppet provisioner t
3232
## Accepted arguments
3333

3434
```
35-
--puppet_args - Extra arguments for Puppet. Can be used to include a Puppet class with -e.
35+
--puppet-env-vars - Extra arguments for Puppet. Can be used to include a Puppet class with -e.
3636
37-
--puppet_master - Hostname of Puppet Master
37+
--puppet-args - Extra arguments for Puppet. Can be used to include a Puppet class with -e.
3838
39-
--puppet_certs_dir - Used when generating/copying certs for use with Puppet Master
39+
--puppet-master - Hostname of Puppet Master
4040
41-
--puppet_private_keys_dir - Used when generating/copying certs for use with Puppet Master
41+
--puppet-certs-dir - Used when generating/copying certs for use with Puppet Master
42+
43+
--puppet-private-keys-dir - Used when generating/copying certs for use with Puppet Master
4244
```
4345

4446
## Usage with a Master
@@ -55,7 +57,7 @@ Puppet will use the default hostname 'puppet' to try to talk to the Puppet Maste
5557
### Master specified
5658

5759
```
58-
sudo aminate -B ami-35792c5c --puppet_master=puppet-master.domain.com some-host.domain.com
60+
sudo aminate -B ami-35792c5c --puppet-master=puppet-master.domain.com some-host.domain.com
5961
```
6062

6163
Puppet will use the specified hostname to try to talk to the Puppet Master server and generate certs with the name in the last argument.
@@ -82,6 +84,15 @@ sudo aminate -B ami-35792c5c /full/path/to/my_manifest_tarball.tgz
8284
Aminator will untar the manifests to /etc/puppet/modules (or /etc/puppet if the tarball contains a modules directory) and run Puppet apply.
8385

8486

87+
### Masterless passing custom facts
88+
89+
```
90+
sudo aminate -B ami-35792c5c --puppet-env-vars="FACTER_my_fact=some_value; FACTER_fact2=value2" /full/path/to/my_manifest_tarball.tgz
91+
```
92+
93+
Aminator will add the specified variables to the environment for Puppet runs. The most obvious use for this is to pass custom facts to Puppet that are used in the Puppet manifests. Pairs are delimited by semi-colon.
94+
95+
8596
### Masterless with modules and arguments for the apply
8697

8798
```

aminatorplugins/provisioner/puppet.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
================================
2424
"""
2525
import os
26+
import re
2627
import glob
2728
import shutil
2829
import time
@@ -61,6 +62,10 @@ def add_plugin_args(self):
6162
action=conf_action(self._config.plugins[self.full_name]),
6263
help='Extra arguments for Puppet. Can be used to include a Puppet class with -e.')
6364

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+
6469
puppet_config.add_argument('--puppet-master', dest='puppet_master',
6570
action=conf_action(self._config.plugins[self.full_name]),
6671
help='Hostname of Puppet Master')
@@ -100,12 +105,22 @@ def provision(self):
100105
self._decide_puppet_run_mode()
101106
self._pre_chroot_block()
102107

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+
103116
log.debug('Entering chroot at {0}'.format(self._distro._mountpoint))
104117
with Chroot(self._distro._mountpoint):
105118

106119
self._install_puppet()
107120

108-
escaped_args = self._escaped_puppet_args()
121+
escaped_args = self._escaped('puppet_args')
122+
123+
109124

110125
if self._puppet_run_mode is 'master':
111126
log.info('Running puppet agent')
@@ -206,9 +221,9 @@ def _list_files(self, startpath):
206221
log.debug((len(path) - start_len + 1) * '---' + '{0}'.format(file))
207222
log.debug("********************************************************")
208223

209-
def _escaped_puppet_args(self):
224+
def _escaped(self, config_name):
210225
import re
211-
return re.sub('\s','\ ', self._get_config_value('puppet_args', '' ))
226+
return re.sub('\s','\ ', self._get_config_value(config_name, '' ))
212227

213228
def _decide_puppet_run_mode(self):
214229
if os.access( self._config.context.package.arg, os.F_OK ):

0 commit comments

Comments
 (0)